devstrict/phpcs
最新稳定版本:v0.2.4
Composer 安装命令:
composer require --dev devstrict/phpcs
包简介
Custom PHP_CodeSniffer ruleset for strict development standards
README 文档
README
A comprehensive set of strict PHP_CodeSniffer rules for general PHP, Laravel, and Yii2 projects to maintain high code quality standards in your projects.
Installation
Requirements
- PHP 8.3 or higher
- Composer
Install via Composer
composer require --dev devstrict/phpcs
Usage
Basic Configuration
Create a phpcs.xml file in your project root:
<?xml version="1.0"?> <ruleset name="MyProject"> <description>My project coding standard</description> <!-- Paths to check --> <file>src</file> <file>tests</file> <!-- Use DevStrict rules --> <rule ref="DevStrict"/> </ruleset>
Rulesets
DevStrict
The main ruleset includes all available rules. See RULES.md for detailed documentation of each rule.
Core Rules:
DevStrict.Attributes.ForbiddenAttributes- Disallow specific attributes (e.g.#[ArrayShape])DevStrict.ControlStructures.DisallowCountInLoop- Preventcount()in loop conditions for performanceDevStrict.ControlStructures.DisallowGotoStatement- Disallowgotostatements as anti-patternDevStrict.ControlStructures.DisallowThrowInTernary- No exceptions in ternary operatorsDevStrict.ControlStructures.UseInArray- Suggestin_array()for multiple OR comparisonsDevStrict.Formatting.MethodChainingIndentation- Enforce four-space indentation for multi-line method chainsDevStrict.Formatting.MethodChainingPerLine- Require one chained call per line once the chain is brokenDevStrict.Formatting.ConsistentStatementIndentation- Keep statements at the same nesting level aligned with identical indentationDevStrict.Formatting.DisallowConsecutivePhpTags- Warn when?>...<?phpswitches appear repeatedly in view filesDevStrict.Functions.DisallowCastFunctions- Use type casts instead ofstrval(),intval(),floatval(),boolval()DevStrict.Functions.PreferModernStringFunctions- Suggest modern string functions (str_contains(),str_starts_with(),str_ends_with()) instead ofstrpos()DevStrict.Functions.PreferJsonValidate- Suggestjson_validate()instead ofjson_decode()for validation-only use casesDevStrict.Objects.DisallowVariableStaticProperty- Forbid$object::$propertystatic property access
Yii2 Framework Rules:
DevStrict.Yii2.DisallowResponseFormatAssignment- Use controller methods likeasJson()instead of direct assignmentDevStrict.Yii2.PreferActiveRecordShortcuts- SuggestfindOne()/findAll()overfind()->where()->one()/all()DevStrict.Yii2.PreferExistsOverCount- Useexists()instead ofcount() > 0for better performanceDevStrict.Yii2.PreferIsGuestOverUserIdCheck- UseYii::$app->user->isGuestinstead of checkingiddirectly
Development
Guidelines
- All new sniffs must have tests
- Follow the existing code style
- Update documentation when necessary
- Ensure all checks pass (
composer check)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Additional Resources
统计信息
- 总下载量: 160
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-15