oscar-team/per-coding-standard
最新稳定版本:1.0.1
Composer 安装命令:
composer require oscar-team/per-coding-standard
包简介
Oscar coding standard built on PER Coding Style 3.0.
README 文档
README
Coding standard for the Oscar technical team that layers project-specific sniffs on top of the PER Coding Style 3.0 specification. The standard is distributed as a PHP_CodeSniffer custom standard located at Oscar/ruleset.xml.
Custom PER Sniffs
- Namespaces.UseGrouping – rejects grouped
usestatements that append more than one namespace separator inside the group. (PER §3) - Attributes.AttributePlacement – validates attribute spacing, line placement, and parameter formatting, including adjacency to docblocks. (PER §12)
- Closures.ShortClosure – enforces arrow function spacing, indentation and semicolon placement rules. (PER §7.1)
- Functions.EmptyBody – requires empty methods/functions to collapse to
{}inline bodies with a preceding space. (PER §4.4) - Formatting.TrailingComma – ensures multi-line lists end with a comma and single-line lists do not. (PER §2.6)
All other PER/PSR-12 expectations are inherited by referencing the upstream PSR12 standard.
Installation
- Install PHP_CodeSniffer (globally or per-project), for example:
composer global require squizlabs/php_codesniffer
- Install Oscar standard (globally or per-project), for example:
composer global require oscar-team/per-coding-standard
- Register the Oscar standard so PHPCS can discover it:
phpcs --config-set installed_paths path/to/oscar-team/per-coding-standard
Example for global:phpcs --config-set installed_paths ~/.composer/vendor/oscar-team/per-coding-standardExample for project:phpcs --config-set installed_paths ~/Projects/my-project/vendor/oscar-team/per-coding-standardAlternatively, provide the ruleset path directly when runningphpcs. - Run
phpcs -ito confirm thatOscarappears in the installed standards list.
Usage
- Analyse code:
phpcs --standard=Oscar path/to/your/php/files
- Auto-fix fixable violations (where safe):
phpcbf --standard=Oscar path/to/your/php/files
Testing
- Install dependencies with
composer install. - Run the automated fixtures with
./tests/run-phpcs.sh.
Development Notes
- Baseline PSR-12 is referenced, with
Squiz.WhiteSpace.ScopeClosingBrace.ContentBeforeexcluded to avoid conflicts with inline empty bodies. - Sniffs live under
Oscar/Sniffs. - Error codes on each sniff reference the matching PER section to aid suppression and maintenance.
- Extend the ruleset by adding new
<rule>entries underOscar/ruleset.xml; PHPCS will autoload them via the configured installed path.
统计信息
- 总下载量: 55
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2025-11-08