fnayou/standards

PHP 代码规范配置器。

安装数量: 3,802

依赖: 3

建议者: 0

安全: 0

星标: 5

关注者: 2

分支: 0

开放问题: 0

语言:Shell

1.2 2017-01-12 15:48 UTC

This package is auto-updated.

Last update: 2024-09-12 04:06:14 UTC


README

清晰易用的 PHP 代码规范 配置器。

symfonylaravelyii 以及任何基于 PHP 的项目兼容。

安装

通过 composer 安装,用于开发

$ composer require --dev fnayou/standards

默认情况下,您可以从 vendor/bin/standards 运行命令,但您可以添加

"config": {
    "bin-dir": "bin"
}

然后您可以从 bin/standards 运行命令。

注意,您可以全局安装

$ composer global require fnayou/standards

使用方法

使用 .standards 配置文件

您需要创建一个名为 .standards 的点文件,其中将包含所有参数

# .standards file content

# can be phpcs or phpcbf (optional - default: phpcs)
command=phpcs

# path used to load standards (optional)
#standard-path=path/to/phpcs/standards/

# standard used by PHP CodeSniffer (required)
standard=PSR2

# verbose/debug mode (optional - default: false)
#verbose=true

# allowed files and directories (optional)
src/

# ignored files and directories (optional)
!tests

现在,您只需运行命令 bin\standards

注意

  • 所有 忽略的文件或目录 应以 ! 开头,例如 !test/!test.php
  • 所有 忽略和允许 的文件/目录应逐行编写,如下
# allowed files/directories
src/
file.php

# ignored files/directories
!tests/
!test.php

带有参数的命令执行

您可以使用 phpcs 参数 运行命令

$ bin/standards src  --standard=PSR2 --ignore=tests

注意,如果使用,此用法将覆盖使用 .standards 文件进行的配置

与 Symfony 一起使用

您必须通过 composer 安装

$ composer require --dev fnayou/standards
$ composer require --dev escapestudios/symfony2-coding-standard

然后,创建您的 .standards 文件

standard=vendor/escapestudios/symfony2-coding-standard/Symfony2

# white list of files and directories
src/

# black list of files and directories
!tests

现在,您只需运行命令 bin\standards

与 Laravel 一起使用

您必须通过 composer 安装

$ composer require --dev fnayou/standards
$ composer require --dev pragmarx/laravelcs

然后,创建您的 .standards 文件

standard=vendor/pragmarx/laravelcs/Standards/Laravel

# white list of files and directories
src/

# black list of files and directories
!tests

现在,您只需运行命令 bin\standards

与 Yii 一起使用

您必须通过 composer 安装

$ composer require --dev fnayou/standards
$ composer require --dev yiisoft/yii2-coding-standards

然后,创建您的 .standards 文件

standard=vendor/yiisoft/yii2-coding-standards/Yii2

# white list of files and directories
src/

# black list of files and directories
!tests

现在,您只需运行命令 bin\standards

Composer 脚本

您还可以添加一个 composer 脚本 以运行命令

"scripts": {
    "stdr": "bin/standards"
},

然后,您只需运行脚本(在 capistrano 或/和 jenkins 中非常有用)

composer stdr

致谢

注意

我创建了优秀的 M6Web Coke 分支,因为我在工作的公司发现 cokesniff 不是那么传统 :),他们拒绝使用它。说实话,我不喜欢输出中的蓝色 :P

待办事项

  • 生成 .standards 文件
  • 处理命令的不同路径(全局安装的 phpcs

许可协议

License: MIT 请参阅 许可文件 了解更多信息。