aik099/coding-standard
A reusable PHP_CodeSniffer coding standard used across aik099 projects. Compatible with PHPCS 3.x+, includes a PHPCS-compliant standard and test suite, and can be run via phpcs --standard=... against your source and tests or integrated into IDEs.
Installation:
composer require --dev aik099/coding-standard
Ensure PHP_CodeSniffer (v3.x+) is installed globally or via Composer:
composer global require squizlabs/php_codesniffer
First Run: Run PHPCS with the custom standard on your Laravel project:
vendor/bin/phpcs --standard=vendor/aik099/coding-standard src app config routes tests
IDE Integration:
Settings > Languages & Frameworks > PHP > Code Sniffer:
vendor/aik099/coding-standard/CodingStandardUse this standard to standardize code reviews and onboarding by:
husky or pre-commit) to auto-check staged files:
vendor/bin/phpcs --standard=vendor/aik099/coding-standard --report=json $(git diff --cached --name-only --diff-filter=ACM | grep '\.php$')
Team Onboarding:
CONTRIBUTING.md with a sample PHPCS command.--diff to show new violations in PRs:
vendor/bin/phpcs --standard=vendor/aik099/coding-standard --diff src/app/Http/Controllers/
CI Integration:
- name: Run PHPCS
run: |
vendor/bin/phpcs --standard=vendor/aik099/coding-standard --warning-severity=3 -n || exit 1
Fixing Violations:
--fix to auto-correct simple issues (e.g., indentation, spacing):
vendor/bin/phpcs --standard=vendor/aik099/coding-standard --fix src/
phpcs.xml (create if missing):
<config name="exclude" value="vendor,node_modules,storage"/>
app/, routes/, and tests/ in CI to reduce noise.phpcs.xml in your project root:
<ruleset>
<config name="standard" value="vendor/aik099/coding-standard/CodingStandard"/>
<file>app/</file>
<arg name="extensions" value="php"/>
<arg name="tab-width" value="4"/>
</ruleset>
Outdated PHPCS:
phpunit/phpunit) may use an older version. Pin PHPCS explicitly in composer.json:
"require-dev": {
"squizlabs/php_codesniffer": "^3.7"
}
False Positives:
$request->input()) may trigger Squizlabs.PHP.Commenting.DocComment.MissingShort or PSR12.Methods.CamelCapsMethodName. Suppress these in phpcs.xml:
<rule ref="Squizlabs.PHP.Commenting.DocComment.MissingShort">
<properties>
<property name="ignore" value="^app\/Http\/Controllers\/.*"/>
</properties>
</rule>
Performance:
--parallel (PHPCS 3.6+) or cache results:
vendor/bin/phpcs --standard=vendor/aik099/coding-standard --cache=~/.phpcs_cache src/
--verbose to diagnose rule application:
vendor/bin/phpcs --standard=vendor/aik099/coding-standard --verbose app/Http/Controllers/
vendor/bin/phpcs --standard=vendor/aik099/coding-standard --help
Custom Rules:
Add project-specific rules by extending the standard in phpcs.xml:
<rule ref="vendor/aik099/coding-standard/CodingStandard">
<exclude name="PSR12.Methods.CamelCapsMethodName"/>
</rule>
<rule ref="CustomRule">
<file>app/</file>
</rule>
Sniff Development:
Extend the standard by creating a custom sniff (e.g., app/CodeSniffer/CustomSniff.php) and reference it in phpcs.xml:
<rule ref="app/CodeSniffer/CustomSniff"/>
Integration with Laravel Tools:
valet.php hook to run PHPCS on project open:
<?php
return [
'commands' => [
'phpcs' => 'vendor/bin/phpcs --standard=vendor/aik099/coding-standard --report=summary',
],
];
How can I help you explore Laravel packages today?