phpcq/plugin-api
phpcq/plugin-api provides the plugin interfaces used by the phpcq tool runner, enabling PHP code quality checks to be integrated and automated in CI pipelines. It defines the contracts plugins implement to extend phpcq’s analysis and reporting.
phpcq/plugin-api provides a plugin-driven architecture for PHP code quality, aligning with Laravel’s modular design (e.g., service providers, commands). This enables custom rule engines without monolithic tooling, ideal for Laravel-specific checks (e.g., Blade template validation, Eloquent query optimization).php artisan phpcq:check).file.updated or repository.pushed.PluginInterface to Laravel’s DI system for dependency injection.PluginInterface, RuleInterface) decouple logic from Laravel, enabling reuse.phpcq/plugin-api → phpcq/phpcq (core runner).Process facade or Artisan.PluginInterface: Define plugin entry points (e.g., run()).RuleInterface: Implement custom checks (e.g., isViolation()).ConfigurationInterface: Merge Laravel config with phpcq settings.| Risk | Severity | Mitigation |
|---|---|---|
| Plugin Isolation | Medium | Use Laravel’s Process facade to sandbox phpcq execution. |
| Config Merge Conflicts | Medium | Override phpcq defaults via config/phpcq.php with Laravel’s config system. |
| Performance Overhead | Low | Run phpcq in CI/CD (not runtime) to avoid HTTP request delays. |
| Laravel-Specific Gaps | High | Build adapters (e.g., convert phpcq violations to Laravel notifications). |
| Ecosystem Immaturity | High | Pilot with 1–2 plugins before full adoption; monitor phpcq activity. |
pint, phpstan) or complement them?config/ with phpcq’s .phpcq.php without conflicts?php artisan phpcq:plugin)?php artisan phpcq:check).phpcq interfaces to Laravel’s DI system.file.updated or repository.pushed.Phase 1: Standalone Integration (1–2 days)
phpcq/plugin-api and phpcq/phpcq as dev dependencies.// app/Console/Commands/RunPhpcq.php
public function handle() {
$process = new Process(['phpcq', 'run']);
$process->run();
$this->output->write($process->getOutput());
}
app/Console/Kernel.php.Phase 2: Configuration Layer (3–5 days)
config/phpcq.php:
php artisan vendor:publish --provider="Phpcq\ServiceProvider"
// config/phpcq.php
return [
'rules' => [
'laravel_magic_methods' => ['enabled' => true],
],
];
Phase 3: Plugin Development (1–2 weeks)
php artisan make:phpcq-plugin LaravelMagicMethodsCheck
RuleInterface and bind to Laravel’s container.Phase 4: Advanced Integration (Ongoing)
| Component | Compatibility Notes |
|---|---|
| PHP Version | phpcq supports PHP 8.0+. Laravel 9+ uses PHP 8.1+, so no conflicts. |
| Composer | No version constraints between phpcq and Laravel core packages. |
| Laravel Features | - Events: Use Events\FileUpdated to trigger phpcq. |
- Notifications: Convert phpcq violations to Notification objects. |
|
- Testing: Mock PluginInterface in PHPUnit tests. |
|
| CI/CD | Works with Laravel’s phpunit.xml or custom GitHub Actions workflows. |
composer.json to avoid surprises:
"require-dev": {
"phpcq/plugin-api": "^1.0",
"phpcq/phpcq": "^2.0"
}
phpcq for breaking changes (low risk due to interface stability).config:clear to reset phpcq settings.README.md.package:discover system.storage/logs/phpcq.log.telescope to track plugin execution times.ProcessFailedException in Artisan commands.phpcq/plugin-api.phpcq --parallel.config('phpcq.cache_ttl', 3600) seconds.Queue system to process violations asynchronously:
Violation::dispatch($violation)->onQueue('phpcq-violations');
php artisan phpcq:docs (custom command to generate docs).phpcq:status command to check compliance.| Failure Mode | Impact | Mitigation |
|---|---|---|
| Plugin Crash | CI/CD pipeline failure | Graceful error handling in Artisan commands; retry logic. |
| Config Merge Errors |
How can I help you explore Laravel packages today?