phpcq/all-tasks
phpcq/all-tasks bundles the full set of PHPCQ tasks into one convenient package, so you can install and run multiple code quality tools with a single dependency. Ideal for setting up consistent linting, testing, and analysis in your PHP projects.
Installation Add the package via Composer:
composer require phpcq/all-tasks --dev
Ensure it’s listed under require-dev in composer.json.
First Use Case Run the predefined PHP Code Quality (PHP-CQ) tasks via Artisan:
php artisan php-cq:run
This executes all default tasks (e.g., static analysis, coding standards, tests).
Configuration
Check config/php-cq.php (auto-generated if missing) for task overrides or custom rules. Example:
'tasks' => [
'phpstan' => [
'level' => 'level:5',
],
'psalm' => [
'enabled' => true,
],
],
CI/CD Pipeline Trigger tasks in GitHub Actions/GitLab CI:
# Example GitHub Actions
- name: Run PHP-CQ
run: php artisan php-cq:run --ansi
Use --ansi for colored output in CI logs.
Pre-Commit Hooks
Integrate with laravel-pint or husky:
composer require laravel-pint --dev
php artisan php-cq:run --tasks=pint
Custom Task Groups
Define reusable task sets in php-cq.php:
'groups' => [
'core' => ['phpstan', 'psalm', 'phpunit'],
'pre-release' => ['phpstan', 'phpunit', 'pest'],
],
Run via:
php artisan php-cq:run --group=core
| Command | Purpose |
|---|---|
php artisan php-cq:run |
Execute all tasks. |
php artisan php-cq:task |
Run a specific task (e.g., phpstan). |
php artisan php-cq:config |
Dump current config to php-cq.php. |
// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->bind(\PHPStan\Rules\Rule::class, function () {
return new CustomRule();
});
}
phpunit.xml) to include:
<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="sqlite"/>
Task Dependencies
phpstan/extension-installer and phpunit/phpunit are installed if using those tasks.composer require --dev phpcq/all-tasks again or manually add missing packages.Configuration Overrides
php-cq.php may conflict with package defaults. Use php artisan php-cq:config to reset.return [
'tasks' => array_merge(
require __DIR__.'/php-cq.php',
['phpstan' => ['level' => 'level:7']]
),
];
Performance
--parallel (if supported):
php artisan php-cq:run --parallel --tasks=phpstan,psalm
Debugging
php artisan php-cq:run --verbose
storage/logs/php-cq.log.Custom Tasks Extend the package by creating a service provider:
// app/Providers/PHPcqServiceProvider.php
public function boot()
{
\PHPcq\AllTasks::extend(function ($manager) {
$manager->addTask(new CustomTask());
});
}
Hooks
Listen to task events (e.g., phpcq.task.started):
// app/Listeners/LogTaskEvents.php
public function handle()
{
Log::info('Task started: '.$event->task);
}
Environment-Specific Configs Use Laravel’s environment configs:
// config/php-cq.php
'tasks' => env('PHP_CQ_TASKS', ['phpstan', 'phpunit']),
--cache to skip unchanged files:
php artisan php-cq:run --cache
- uses: actions/cache@v3
with:
path: ~/.cache/php-cq
key: ${{ runner.os }}-php-cq-${{ hashFiles('**/composer.lock') }}
How can I help you explore Laravel packages today?