phpmyadmin/coding-standard
phpMyAdmin Coding Standard provides PHP_CodeSniffer rules based on the Doctrine Coding Standard. Install via Composer and run phpcs with the PhpMyAdmin standard to enforce consistent PHP style across your project.
Installation Add the package via Composer in your Laravel project:
composer require --dev phpmyadmin/coding-standard
Register the standard in your project’s phpcs.xml or phpcs.xml.dist:
<config name="standard" value="PhpMyAdmin"/>
First Use Case Run CodeSniffer on a Laravel controller or model:
vendor/bin/phpcs app/Http/Controllers/ --standard=PhpMyAdmin
Focus on files where you suspect violations (e.g., new or modified files).
Where to Look First
vendor/phpmyadmin/coding-standard/PhpMyAdmin.ruleset.xml for custom rules.phpcs.xml (e.g., relax PSR12 conflicts).Integrate into CI/CD
Add to composer.json scripts:
"scripts": {
"test": [
"phpcs --standard=PhpMyAdmin --report=full app/"
]
}
Trigger via GitHub Actions or GitLab CI:
- name: Run PHP CodeSniffer
run: composer test
Laravel-Specific Workflows
database/migrations/ to enforce consistency:
phpcs database/migrations/ --standard=PhpMyAdmin --warning-severity=3
Pair with PHPStan/Laravel-Pint Combine with static analysis tools for broader coverage:
composer require --dev phpstan/phpstan laravel/pint
vendor/bin/phpstan analyse --level=5
vendor/bin/pint --test
vendor/bin/phpcs app/
phpcbf:
vendor/bin/phpcbf app/Http/Controllers/UserController.php
phpcs-local.ruleset.xml) and reference it:
<config name="standard" value="PhpMyAdmin,phpcs-local"/>
CONTRIBUTING.md with examples of compliant/non-compliant code.Rule Conflicts with PSR12
phpcs.xml:
<rule ref="PhpMyAdmin">
<exclude name="PSR12.Classes.ClassDeclaration.MissingDocblock"/>
<arg name="lineLength" value="120"/>
</rule>
False Positives in Legacy Code
mysql_* functions, old Laravel versions).<exclude-pattern> in phpcs.xml:
<file>app/OldLegacyCode/</file>
Performance on Large Codebases
app/ can be slow.--ignore:
phpcs app/Http app/Models --ignore=app/Jobs/*
--report=full to debug rule violations:
phpcs app/ --standard=PhpMyAdmin --report=full --verbose
vendor/bin/phpcs --help for generic tips).Custom Sniffs
Add project-specific sniffs to phpcs.xml:
<rule ref="PhpMyAdmin">
<config name="customSniffs" value="app/CodeSniffer/"/>
</rule>
Example: Create app/CodeSniffer/LaravelSniff.php to enforce Laravel-specific patterns.
Severity Adjustments Lower severity for non-critical rules (e.g., docblocks):
<rule ref="PhpMyAdmin">
<severity name="PSR12.Classes.ClassDeclaration.MissingDocblock" value="2"/>
</rule>
Autofix Limitations
--fix. Test phpcbf on a backup first:
cp -r app/ app.bak && vendor/bin/phpcbf app/
How can I help you explore Laravel packages today?