pronamic / wp-coding-standards
Pronamic WordPress WordPress 编码规范 for PHP_CodeSniffer。
Requires
- php: >=8.0
- automattic/vipwpcs: ^3.0
- dealerdirect/phpcodesniffer-composer-installer: ^1.0
- phpcompatibility/phpcompatibility-wp: ^2.1
- sirbrillig/phpcs-variable-analysis: ^2.11
- squizlabs/php_codesniffer: ^3.9
- wp-coding-standards/wpcs: ^3.1
README
Pronamic WordPress 编码规范 for PHP_CodeSniffer。
版本
我们努力在我们的项目中为最新的3个主要版本的PHP和WordPress提供支持。
PHP
8.3
8.2
8.1
https://php.ac.cn/supported-versions.php
WordPress
6.5
6.4
6.3
https://codex.wordpress.org/WordPress_Versions
其他
- https://make.wordpress.org/core/handbook/best-practices/browser-support/
- https://make.wordpress.org/core/handbook/references/php-compatibility-and-wordpress-versions/
PHP_CodeSniffer
https://github.com/PHPCSStandards/PHP_CodeSniffer
参数
https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Usage
colors
默认情况下,在输出中使用颜色。
<arg name="colors" />
extensions
默认情况下,仅检查具有 php
扩展名的文件
<arg name="extensions" value="php" />
parallel
默认情况下,使用 8
个并行进程。
<arg name="parallel" value="8" />
squizlabs/PHP_CodeSniffer#1732
sp
默认情况下,在所有报告中显示嗅探代码。默认情况下显示运行进度。
<arg value="sp" />
规则
PHPCompatibilityWP
https://github.com/PHPCompatibility/PHPCompatibilityWP
默认情况下,此包通过以下设置测试PHP 8.1
及更高版本
<config name="testVersion" value="8.1-"/>
PHPCompatibility
https://github.com/PHPCompatibility/PHPCompatibility
通过 PHPCompatibilityWP
需要。
WordPress
https://github.com/WordPress/WordPress-Coding-Standards
默认情况下,要检查的最小WordPress版本设置为 6.3
,如下设置
<config name="minimum_supported_wp_version" value="6.3" />
WordPressVIPMinimum
https://github.com/Automattic/VIP-Coding-Standards
WordPress-VIP-Go
https://github.com/Automattic/VIP-Coding-Standards
VariableAnalysis
https://github.com/sirbrillig/phpcs-variable-analysis
排除
WordPress.Files.FileName.InvalidClassFileName
根据WordPress PHP编码规范
类文件名应根据类名命名,并在类名前加上
class-
,并将类名中的下划线替换为连字符,例如WP_Error
变为class-wp-error.php
来源: https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#naming-conventions
此嗅探器将检查此命名约定
Class file names should be based on the class name with "class-" prepended. Expected class-test.php, but found Test.php.
我们经常使用 PSR-4 自动加载机制,因此偏离了它。
WordPress.Files.FileName.NotHyphenatedLowercase
根据WordPress PHP编码规范
文件应使用小写字母描述性地命名。使用连字符分隔单词。
my-plugin-name.php
来源: https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#naming-conventions
Filenames should be all lowercase with hyphens as word separators. Expected test.php, but found Test.php.
我们经常使用 PSR-4 自动加载机制,因此偏离了它。
Universal.Arrays.DisallowShortArraySyntax
根据WordPress PHP编码规范
使用长数组语法(
array( 1, 2, 3 )
)声明数组通常比短数组语法([ 1, 2, 3 ]
)更易于阅读,尤其是对于视力有困难的人。此外,它对于初学者来说描述性更强。数组必须使用长数组语法声明。
来源: https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#declaring-arrays