devstrict / phpcs
Custom PHP_CodeSniffer ruleset for strict development standards
Installs: 160
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 2
Type:phpcodesniffer-standard
pkg:composer/devstrict/phpcs
Requires
- php: ^8.3
- dealerdirect/phpcodesniffer-composer-installer: ^1.2.0
- squizlabs/php_codesniffer: ^4.0.0
Requires (Dev)
- captainhook/captainhook: ^5.25.11
- friendsofphp/php-cs-fixer: ^3.89.0
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan: ^2.1.0
- phpstan/phpstan-strict-rules: ^2.0.7
- phpunit/phpunit: ^12.4.3
- slevomat/coding-standard: ^8.24
This package is auto-updated.
Last update: 2025-12-22 22:23:04 UTC
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.