sweetchuck/robo-phpstan
Robo tasks for running PHPStan in your PHP projects. Provides configurable commands and integration helpers to execute static analysis as part of Robo workflows and CI pipelines, with options for paths, config files, and reporting.
Installation:
composer require --dev sweetchuck/robo-phpstan
Ensure robo/robo is also installed (required dependency).
First Use Case:
Add a phpstan.neon config file in your project root (or extend an existing one).
Run a basic analysis:
vendor/bin/robo phpstan:analyse
This executes PHPStan with default parameters (level 5, autoload from composer.json).
Where to Look First:
robo.php for predefined tasks (if any).src/Robo/Tasks/PHPStanTasks.php for available commands (e.g., analyse, bootstrap, check).phpstan.neon (or phpstan.dist.neon for templates).Integrate into CI/CD:
Add to .github/workflows/phpstan.yml or similar:
- name: Run PHPStan
run: vendor/bin/robo phpstan:analyse --level=7
Use --no-progress for cleaner CI output.
Customize Analysis:
Extend phpstan.neon to include:
includes:
- vendor/autoload.php
- config/phpstan.php
parameters:
level: 8
paths:
- src
- tests
Task Chaining:
Combine with other Robo tasks (e.g., phpstan:bootstrap before analysis):
$this->taskPHPStanBootstrap()
->run();
$this->taskPHPStanAnalyse()
->run();
Parallel Execution:
Use --parallel flag for multi-core analysis:
vendor/bin/robo phpstan:analyse --parallel
phpstan.neon:
paths:
- app
- bootstrap
- config
- database/seeds
- routes
excludeFiles in phpstan.neon to skip tests or generated files:
excludeFiles:
- '*/Tests/*'
- '*/Migrations/*'
phpstan.dist.neon as a template for new projects.Missing Autoload:
If PHPStan fails to load classes, ensure includes in phpstan.neon points to vendor/autoload.php or use:
vendor/bin/robo phpstan:bootstrap
Level Mismatch:
Default level is 5. For stricter checks, explicitly set --level=8 or higher in phpstan.neon.
Configuration Overrides:
Command-line flags (e.g., --level) override phpstan.neon settings. Use --no-cache to bypass cached results if configs change.
Robo Task Not Found:
Ensure robo/robo is installed. Run composer require robo/robo if missing.
--verbose for detailed logs:
vendor/bin/robo phpstan:analyse --verbose
3.x for PHPStan 1.x).PHPStanTasks in your robo.php:
$this->taskPHPStanAnalyse()
->arg('level')->default('8')
->run();
before()/after() to run tasks before/after PHPStan:
$this->taskPHPStanAnalyse()
->before(function () {
$this->taskExec('composer dump-autoload')->run();
});
phpstan.neon dynamically based on environment (e.g., phpstan.prod.neon):
$configPath = env('PHPSTAN_CONFIG') ?: 'phpstan.neon';
$this->taskPHPStanAnalyse()->arg('config')->default($configPath)->run();
--no-cache or manually delete .phpstan.cache.vendor/bin/robo phpstan:analyse --paths=src --no-progress
How can I help you explore Laravel packages today?