标签: phpcs

关联数组对齐 => 与 PHP-CS-Fixer

关联数组 => 应该与 PHP-CS-Fixer 对齐吗?

$array = [
    1    => 'a',
    '1'  => 'b',
    1.5  => 'c',
    true => 'd',
];
Run Code Online (Sandbox Code Playgroud)

或者

$array = [
    1 => 'a',
    '1' => 'b',
    1.5 => 'c',
    true => 'd',
];
Run Code Online (Sandbox Code Playgroud)

我没有在https://github.com/FriendsOfPHP/PHP-CS-Fixer 中找到过滤器

php phpcs

5
推荐指数
2
解决办法
3401
查看次数

git filter-branch 只获取已更改的文件?

我们想要运行git filter-branch一个大型代码库来重新格式化 PHP 文件。由于我们有超过 21k 次提交,phpcbf因此希望每次提交filter-branch. 是否可以只获取每次提交更改的文件并对其进行专门格式化?就像是...

git filter-branch --tree-filter \
 'FILES=$(<something> | grep .php) php /usr/local/bin/phpcbf.phar $FILES || true'
Run Code Online (Sandbox Code Playgroud)

git phpcs

5
推荐指数
1
解决办法
1347
查看次数

从命令行运行时忽略单个 PHPCS 规则

设想

有时,我想运行 PHPCS,但让它忽略一个规则,在本例中是 Camel Case Method Name 规则。

我知道我可以创建一个新的规则集,它从另一个规则集继承所有规则集,并排除一个规则集,但如果可能的话,我想从命令行执行此操作。

运行时phpcs --standard=PSR2 --extentions=php src/,有没有办法从这次运行的标准中排除单个规则?

phpcs

5
推荐指数
1
解决办法
406
查看次数

phpcbf 抱怨缺少 CodeSniffer

问题

phpcbf 抱怨缺少 CodeSniffer,但它似乎在自己的 phar 中丢失了。

我的设置

Ubuntu 14.04 使用 ondrej ppa for PHP 5.6

这是我尝试安装的内容和验证安装的输出

  • sudo pear install PHP_CodeSniffer

    pear list=> PHP_CodeSniffer 2.6.0 稳定版

  • curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar

    php phpcbf.phar --version=> Squiz 的 PHP_CodeSniffer 版本 2.6.0(稳定)(http://www.squiz.net

我如何运行 phpcbf

php phpcbf.phar --standard=PSR2 ./MyDir/MyClass.php

PHP Warning: chdir(): No such file or directory (errno 2) in phar:///home/myuser/projects/myproject/src/phpcbf.phar/CodeSniffer.php on line 861

更新:尽管有警告,但它似乎工作正常。

php phar phpcs

5
推荐指数
1
解决办法
1706
查看次数

PHP CodeSniffer 在方法中忽略/排除下划线规则

运行 phpcs 时,出现Protected member variable "myMethod" must contain a leading underscore. 我如何排除/忽略这个错误ruleset.xml

<?xml version="1.0"?>
<ruleset name="PSR2">
 <description>The PSR-2 coding standard.</description>
 <arg name="tab-width" value="4"/>
 <!-- 2. General -->
 <!-- 2.1 Basic Coding Standard -->
 <!-- Include the whole PSR-1 standard -->
 <rule ref="PSR1"/>
 <!-- 2.2 Files -->
 <!-- All PHP files MUST use the Unix LF (linefeed) line ending. -->
 <rule ref="Generic.Files.LineEndings">
  <properties>
   <property name="eolChar" value="\r\n"/>
  </properties>
 </rule>
 <!-- All PHP files MUST end with a single …
Run Code Online (Sandbox Code Playgroud)

php zend-framework codesniffer phpcodesniffer phpcs

5
推荐指数
1
解决办法
3524
查看次数

PHPCS 不同目录的不同规则集

我目前正在清理现有的代码库,其中一个方面涉及使用 PHPCS。这是我目前的phpcs.xml文件:

<?xml version='1.0'?>
<ruleset name='MyApplication'>
    <arg name='encoding' value='utf-8'/>
    <arg name='extensions' value='php'/>
    <arg name='warning-severity' value='0'/>
    <arg name='colors'/>
    <arg value='p'/>

    <exclude-pattern>vendor/*</exclude-pattern>
    <exclude-pattern>node_modules/*</exclude-pattern>

    <rule ref='PSR1'></rule>
</ruleset>
Run Code Online (Sandbox Code Playgroud)

我想修改它,以便将 PSR-2 应用于某些目录(例如foo/bar/),而其余目录则根据 PSR-1 进行检查。

<exclude-pattern>在手册中找到了可以作为元素的子元素放置的选项,<rule>但我需要相反的选项。

php phpcs

5
推荐指数
1
解决办法
770
查看次数

如何修复 Visual Studio Code 中的以下 phpcs 错误?

我是 VS 代码的新手。我正在尝试使用 PHP,但我不断收到此通知。

phpcs:请求工作区/配置失败并显示消息:无法找到 phpcs。请将 phpcs 添加到您的全局路径或使用 composer 依赖管理器将其安装在您的本地项目中。

Intellisense 也不适用于 PHP。我使用的是 Windows 系统。我尝试下载并安装 Composer,但仍然出现屏幕截图所示的问题。

[截屏] 1

我安装了一些在屏幕截图中可见的扩展,但问题仍然存在。

php visual-studio-code phpcs

5
推荐指数
1
解决办法
1万
查看次数

PHPcs xml 配置禁用一些规则

我了解如何使用 xml 配置 phpcs,但找不到如何禁用某些嗅探。这是我当前的配置(甚至不知道这是否正确):

\n\n
<?xml version="1.0" encoding="UTF-8"?>\n<ruleset name="custom" \n  xmlns="http://pmd.sf.net/ruleset/1.0.0" \n  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">\n  <rule ref="rulesets/codesize.xml"/>\n  <rule ref="rulesets/controversial.xml/Superglobals"/>\n  <rule ref="rulesets/controversial.xml/CamelCaseParameterName"/>\n  <rule ref="rulesets/controversial.xml/CamelCaseVariableName"/>\n  <rule ref="rulesets/design.xml"/>\n  <rule ref="rulesets/naming.xml/ShortMethodName"/>\n  <rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass"/>\n  <rule ref="rulesets/naming.xml/ConstantNamingConventions"/>\n  <rule ref="rulesets/naming.xml/BooleanGetMethodName">\n    <properties>\n      <property name="checkParameterizedMethods" value="true"/>\n    </properties>\n  </rule>\n  <rule ref="rulesets/unusedcode.xml"/>\n\n  <arg name="tab-width" value="2"/>\n  <rule ref="Generic.WhiteSpace.ScopeIndent">\n    <properties>\n      <property name="indent" value="2"/>\n    </properties>\n  </rule>\n\n  <rule ref="Generic.Files.LineLength">\n    <properties>\n      <property name="lineLimit" value="140"/>\n      <property name="absoluteLineLimit" value="0"/>\n    </properties>\n  </rule>\n</ruleset>\n
Run Code Online (Sandbox Code Playgroud)\n\n

我想禁用这些:

\n\n
    \n
  • [phpcs] @copyright tag must contain a year and the name of the …

php phpcodesniffer phpcs

5
推荐指数
3
解决办法
1万
查看次数

运行phpcs时,错误:引用的嗅探“ PHPCompatibility”不存在

我想运行phpcs工具,但是此错误即将到来,

ERROR: Referenced sniff "PHPCompatibility" does not exist 我运行了phpcs -i。那给了我,

The installed coding standards are PEAR, PSR1, Zend, Squiz, PSR12, PSR2, MySource and PHPCompatibility.

但是总是会出现此错误,错误:引用的嗅探“ PHPCompatibility”不存在。有什么原因吗?

php psr-2 phpcs php-7.1

5
推荐指数
1
解决办法
755
查看次数

Visual Studio Code - PHPCS 错误(发生未知错误。请验证是否返回有效的 json 对象)

我正在尝试设置 PHPCS 插件,但到目前为止我只收到此错误:

phpcs:发生未知错误。请验证 /home/[user]/Documents/offprojects/vet_direct/vetsdirectapp/vendor/bin/phpcs --report=json -q --encoding=UTF-8 --error-severity=5 --warning-severity= 5 --stdin-path=/home/[user]/Documents/offprojects/vet_direct/vetsdirectapp/app/Http/Controllers/JobController.php - 返回有效的 json 对象。

我按照插件页面的安装指南在全局和项目中安装了 PHPCS。此外,终端中的命令显示此错误:

zsh: command not found: phpcs
Run Code Online (Sandbox Code Playgroud)

知道这里出了什么问题吗?

visual-studio-code phpcs

5
推荐指数
1
解决办法
4565
查看次数