contributte/qa
Contributte QA is a dev-only Composer package that bundles and streamlines PHP quality assurance tooling for your project. Install via composer require --dev contributte/qa and follow the included docs to integrate checks into your workflow/CI.
## Getting Started
### Minimal Setup
1. **Install the package** in your Laravel project:
```bash
composer require --dev contributte/qa
phpcs.xml) in your project root:
<?xml version="1.0"?>
<ruleset name="Project Standards">
<rule ref="./vendor/contributte/qa/ruleset.xml"/>
<!-- Optionally override specific rules -->
<rule ref="rules/Squiz.WhiteSpace.DisallowTabCharacter">
<severity>warning</severity>
</rule>
</ruleset>
vendor/bin/phpcs --standard=phpcs.xml app/
vendor/bin/phpcbf --standard=phpcs.xml app/
Add a GitHub Actions workflow (.github/workflows/qa.yml) to enforce standards on every push:
name: QA Checks
on: [push, pull_request]
jobs:
phpcs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- run: composer install
- run: vendor/bin/phpcs --standard=phpcs.xml --report=checkstyle | tee results.xml
- uses: jwgmeligmeyling/checkstyle-github-action@v1
with:
path: results.xml
Local Checks:
phpcs on-demand during development:
alias phpcs="vendor/bin/phpcs --standard=phpcs.xml --colors"
phpcbf for quick fixes:
vendor/bin/phpcbf --standard=phpcs.xml --diff app/
IDE Integration:
phpcs.xml as the Code Sniffer profile:
Settings > Languages & Frameworks > PHP > Code SnifferConfiguration file to phpcs.xmlRun inspection on saveTeam Onboarding:
CONTRIBUTING.md snippet:
## Code Standards
This project enforces [Contributte QA](https://github.com/contributte/qa) standards.
Run `composer cs-check` to validate your changes before submitting a PR.
Service Provider Integration:
Create a QACheckServiceProvider to register commands:
// app/Providers/QACheckServiceProvider.php
public function register()
{
$this->commands([
Commands\QACheckCommand::class,
]);
}
Command implementation:
// app/Console/Commands/QACheckCommand.php
public function handle()
{
$exitCode = Artisan::call('phpcs', [
'--standard=phpcs.xml',
'--report=full',
'--colors',
app_path('..'),
]);
if ($exitCode !== 0) {
$this->error('Code standards violations found!');
exit(1);
}
}
Custom Rules for Laravel Idioms: Extend the ruleset to handle Laravel-specific patterns:
<!-- phpcs.xml -->
<rule ref="./vendor/contributte/qa/ruleset.xml"/>
<rule ref="Custom/Laravel/DisallowFacadeDirectCalls">
<severity>warning</severity>
</rule>
Create a custom sniff (e.g., app/Rules/Custom/Laravel/DisallowFacadeDirectCallsSniff.php):
class DisallowFacadeDirectCallsSniff implements Sniff
{
public function register()
{
return [
T_STRING => $this,
];
}
public function process(Tokens $tokens, $position)
{
$content = $tokens[$position][1];
if (in_array($content, ['Auth', 'Cache', 'Route'])) {
return new FixableError(
'Direct facade calls are discouraged. Use dependency injection instead.',
$position,
$position + 1
);
}
return null;
}
}
Partial Integration: Use the package selectively for specific directories:
vendor/bin/phpcs --standard=phpcs.xml --ignore=tests,config app/
PHP Version Mismatch:
Your PHP version (8.1) does not meet the minimum requirement (8.2).
contributte/qa:0.3.x).Deprecated Rules:
Squiz.WhiteSpace.LanguageConstructSpacing is deprecated since PHP_CodeSniffer v3.3.0.<rule ref="Squiz.WhiteSpace.LanguageConstructSpacing">
<severity>warning</severity>
<properties>
<property name="deprecated" value="true"/>
</properties>
</rule>
Strict Typing Enforcement:
declare(strict_types=1) at the top of files.<rule ref="SlevomatCodingStandard.TypeHints.Declaration">
<properties>
<property name="strict_types_declaration" value="false"/>
</properties>
</rule>
CI Pipeline Failures:
--report=checkstyle for better integration:
vendor/bin/phpcs --standard=phpcs.xml --report=checkstyle | tee results.xml
cs2pr for GitHub PR previews:
vendor/bin/phpcs --standard=phpcs.xml | cs2pr
Performance with Large Codebases:
phpcs on large projects (e.g., 10K+ files) can be slow.parallel:
vendor/bin/phpcs --standard=phpcs.xml --parallel=4 app/
Isolate Rule Violations:
vendor/bin/phpcs --standard=SlevomatCodingStandard rules/TypeHints/Declaration.php
Inspect Ruleset:
vendor/bin/phpcs --standard=phpcs.xml --list-rules
Snapshot Testing:
php bin/snapshots --sniffs
Custom Rulesets:
<!-- ruleset-8.5.xml -->
<ruleset>
<config name="php_version" value="8.5"/>
<rule ref="./ruleset.xml"/>
<rule ref="Custom/RulesForPHP85"/>
</ruleset>
Dynamic Rule Configuration:
// Generate ruleset.php
$ruleset = new \PHP_CodeSniffer\Config();
$ruleset->addRule('SlevomatCodingStandard.TypeHints.Declaration');
$ruleset->save('phpcs.xml');
Integrate with Laravel Events:
eloquent.saved or job.processed:
Event::listen('eloquent.saved', function ($model) {
$exitCode = Artisan::call('phpcs', [
'--standard=phpcs.xml',
'--ignore=*/migrations/*',
$model->getTable(),
]);
if ($exitCode !== 0) {
Log::error("Code standards violated in {$model->getTable()}");
}
});
Exclude Files:
.phpcsignore to exclude files/directories:
# .phpcsignore
vendor/
node_modules/
storage/logs/*.log
Custom Error Messages:
<rule ref="Squiz.WhiteSpace.SpaceAfterCast">
<properties>
<property name="message" value="Missing space after
How can I help you explore Laravel packages today?