picklewagon / picklewagon-coding-standards
在PHP项目中强制执行PHP编码标准。
0.1.7
2022-10-15 08:26 UTC
Requires
- php: ~7.0|~8.0
This package is auto-updated.
Last update: 2024-09-15 12:35:09 UTC
README
将此软件包包含到您的项目中,以强制执行Picklewagon项目使用的编码标准。
安装
添加到composer.json中。由于它是一个私有软件包,您还必须添加一些依赖项。
"require-dev": {
...
"picklewagon/picklewagon-coding-standards": "1.0.0"
},
"repositories": [
{
"type": "vcs",
"url": "git@bitbucket.org:picklewagon/picklewgon-coding-standards.git"
}
],
从命令行运行
$ composer require squizlabs/php_codesniffer $ composer require wimg/php-compatibility $ composer update picklewagon/picklewagon-coding-standards $ ./vendor/bin/phpcs --config-set installed_paths vendor/picklewagon/php-coding-standards-pkg/,vendor/wimg/php-compatibility/
通过运行以下命令验证软件包安装
$ ./vendor/bin/phpcs -i
您应该会看到Picklewagon编码标准已经安装。
用法
创建一个文件,您的特定仓库将使用它来定义编码标准。
详细信息可以在PHP_CodeSniffer wiki中找到。
基本上,您需要在项目根目录中创建一个phpcs.xml文件。
以下是此文件可能包含的内容示例
<?xml version="1.0"?> <ruleset name="PrinterInstaller"> <description>The coding standard for the user microservice.</description> <!-- Include these folders --> <file>app</file> <file>bootstrap</file> <file>config</file> <file>database</file> <file>resources</file> <file>routes</file> <file>tests</file> <!-- Don't validate these files --> <exclude-pattern>*.blade.php</exclude-pattern> <exclude-pattern>bootstrap/autoload.php</exclude-pattern> <exclude-pattern>bootstrap/cache/services.php</exclude-pattern> <!-- Configuration --> <!-- Check for cross-version support for PHP 7.1 and higher. --> <config name="testVersion" value="7.1-" /> <!-- Arguments --> <arg value="sp" /> <arg name="extensions" value="php" /> <arg name="report-json" value="build/reports/php/phpcs-code.json" /> <!-- Include the Picklewagon coding standard. --> <rule ref="Picklewagon" /> </ruleset>
您需要根据安装它的仓库进行自定义。
运行以下命令
$ ./vendor/bin/phpcs