shiftonelabs/codesniffer-standard
Opinionated PHP_CodeSniffer ruleset by ShiftOneLabs. Provides a shared coding standard for consistent style, formatting, and best practices across PHP/Laravel projects. Easy to install and run with phpcs in CI or local development.
Install via Composer
composer require --dev shiftonelabs/codesniffer-standard
Add the standard to your phpcs.xml or phpcs.xml.dist:
<config name="standard" value="Shiftonelabs"/>
First Use Case Run CodeSniffer on a file or directory:
./vendor/bin/phpcs app/
Verify the new rules (e.g., Shiftonelabs.Arrays, Shiftonelabs.Namespaces) are applied.
Where to Look First
vendor/shiftonelabs/codesniffer-standard/ruleset.xml for available rules.phpcs.xml from the package’s tests/ directory if available.CI/CD Pipeline Add to your CI (e.g., GitHub Actions) to enforce standards pre-merge:
- name: Run PHP_CodeSniffer
run: ./vendor/bin/phpcs --standard=Shiftonelabs --warning-severity=0 app/
Pre-Commit Hook
Use phpcs via a tool like Husky or Laravel Pint to catch issues early:
composer require --dev laravel/pint
./vendor/bin/pint --test
Custom Rules Extension
Extend existing rules by copying the package’s Shiftonelabs namespace to your project’s Custom namespace (e.g., app/Rules/Custom/Arrays.php) and override logic.
Shiftonelabs.Arrays.ArrayKeyQuotes).Shiftonelabs.Namespaces).@throws for exceptions).phpcs with Shiftonelabs rules:
php artisan make:command CheckCodeStandards
public function handle() {
$this->call('phpcs', [
'--standard' => 'Shiftonelabs',
'--extensions' => 'php',
'app/',
]);
}
Rule Conflicts
PSR12 + Shiftonelabs), conflicts may arise. Prioritize rules in phpcs.xml:
<arg name="report" value="full" />
<arg name="report-width" value="120" />
<config name="categories" value="1"/>
--report=summary to identify overlapping rules.Performance
vendor/, storage/) to speed up runs:
<exclude-pattern>.*/vendor/.*</exclude-pattern>
False Positives
<rule ref="Shiftonelabs.Arrays.ArrayKeyQuotes">
<severity>1</severity> <!-- Warning instead of error -->
</rule>
--verbose to debug rule application:
./vendor/bin/phpcs --standard=Shiftonelabs --verbose app/
./vendor/bin/phpcs --help or check the package’s README for rule descriptions.Add Custom Rules
app/Rules/Custom/ extending PHP_CodeSniffer_Standards_AbstractStandard.phpcs.xml:
<rule ref="Custom">
<file>.</file>
</rule>
Override Default Rules
Shiftonelabs rules to your project’s Custom namespace and modify as needed.Integrate with IDE
Settings > Editor > Inspections > PHP > CodeSniffer, add the standard path.phpcs.xml paths are case-sensitive (especially on Linux).composer clear-cache
How can I help you explore Laravel packages today?