PHPCS

使用 PHP-CS-Fixer 自动规范化你的 PHP 代码

随声附和 提交于 2020-03-14 20:32:42
良好的代码规范可以提高代码可读性,团队沟通维护成本。最推荐大家遵守的是 php-fig (PHP Framework Interop Group) 组织定义的 PSR-1 、 PSR-2 两个。不了解的同学可以先通过连接点击过去阅读下。 PHP-CS-Fixer 项目地址: https://github.com/FriendsOfPHP/PHP-CS-Fixer 用来自动格式化你的代码。 通过安装 Composer 安装 composer.phar global require fabpot/php-cs-fixer 请确保 ~/.composer/vendor/bin 目录在你的系统PATH中。 export PATH="$PATH:$HOME/.composer/vendor/bin" 更多请查看 installation 使用fix命令 使用 fix 指令修复文件夹或文件的代码风格 php php-cs-fixer.phar fix /path/to/dir php php-cs-fixer.phar fix /path/to/file 使用 --level 选项设置修复至的「规范」。 php php-cs-fixer.phar fix /path/to/project --level=psr0 php php-cs-fixer.phar fix /path/to

Resolve this error for Laravel migration file: Each class must be in a namespace of at least one level

北慕城南 提交于 2020-01-02 05:44:08
问题 How to resolve this phpcs error? It shows up for the class Keyword in all Laravel migrations files. The error message is: Each class must be in a namespace of at least one level (a top-level vendor name) phpcs 回答1: You can do it in many ways and First you can put this at the top of your file: // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace Second you can use // @codingStandardsIgnoreLine Just before your class declaration. Hope any one of these will work for you. If problem

phpcs: How can I modify PSR2 to check that the brace is on the same line as the method?

安稳与你 提交于 2019-12-18 11:49:26
问题 I've spent now over 2h on trying to figure out how to require the { in the same line as the method declaration instead of the default requirement being the next line. How can I get this done? I've copied the PSR2 standard to a new folder named PSR2 to be ably to modify it to my liking. So the base I'm working on is basically the PSR2 standard which I would like to modify. I've tried the ruleset.xml and I've tried to modify it in the code directly without success. <rule ref="PEAR.Classes

Resolve this error for Laravel migration file: Each class must be in a namespace of at least one level

百般思念 提交于 2019-12-05 14:19:41
How to resolve this phpcs error? It shows up for the class Keyword in all Laravel migrations files. The error message is: Each class must be in a namespace of at least one level (a top-level vendor name) phpcs You can do it in many ways and First you can put this at the top of your file: // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace Second you can use // @codingStandardsIgnoreLine Just before your class declaration. Hope any one of these will work for you. If problem still persists please let me know about this. 来源: https://stackoverflow.com/questions/53919231/resolve-this

How can I suppress PHPCS warnings using comments?

£可爱£侵袭症+ 提交于 2019-12-03 05:26:22
问题 My TestMyClass.php has two class definitions in the same file (unit testing class), and PHP Code Sniffer complains about each class must be in a file by itself . How can I suppress this warning? class MyClassImpl implements MyInterface { // ... } class MyClassTest extends \PHPUnit_Framework_TestCase { // ... } 回答1: You can get PHP_CodeSniffer to ignore specific files or lines in a file using comments: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-files-and-folders

Sublime Text 3配置php语法错误提示插件PHPCS (windows7环境)

爱⌒轻易说出口 提交于 2019-11-30 19:26:49
第一步:下载 php code sniffer插件安装包 地址 https://github.com/benmatselby/sublime-phpcs ; 解压安装包得到sublime-phpcs-master,把sublime-phpcs-master文件夹放到sublime安装目录下的Data/Packages/目录下;重启sublime, 打开 Sublime Text 3->Preferences-> Package Settings -> Php Code Sniffer 证明插件安装成功; 第二步:下载 php-cs-fixer.phar 地址 http://cs.sensiolabs.org/get/php-cs-fixer.phar ; 第三步:把 php-cs-fixer.phar 放到 你的 php.exe 安装目录 (例如 (mine is C:/WAMP/php/php.exe) ); 第四步: 下载 http://download.pear.php.net/package/PHP_CodeSniffer-1.5.0RC4.tgz ,解压,然后找到scripts目录下的 phpcs.bat,放到 php.exe 安装目录; 第五步:解压打开 第一步下载的 php code sniffer安装包,在子文件example-settings下有个文件