Installation:
composer require --dev sweetchuck/robo-phpcs
Ensure robo/robo is also installed (required dependency).
Basic RoboFile Integration:
Add the task to your RoboFile.php:
use Sweetchuck\RoboPhpcs\RoboPhpcs;
$tasks = new RoboPhpcs($this);
First Use Case:
Run PHPCS on a directory (e.g., src/):
robo phpcs:run --dir=src/
Defaults to app/ if no directory is specified.
Pre-Commit Hook:
$this->taskExec('git')->hook('pre-commit')
->exec('robo phpcs:run --dir=src/ --standard=PSR12 --report=json');
CI Integration: Fail the build on errors:
$this->taskPhpcsRun()
->dir('src/')
->standard('PSR12')
->failOnError()
->run();
Custom Standards:
Load a custom .phpcs.xml file:
$this->taskPhpcsRun()
->config('tests/phpcs.xml')
->run();
Chain PHPCS with other tasks (e.g., tests):
$tasks = $this->taskPhpcsRun()->dir('src/');
$tasks->then($this->taskExec('phpunit'));
Generate reports for CI tools:
robo phpcs:run --dir=src/ --report=json --report-file=phpcs-report.json
Robo Version:
Requires Robo 1.0.0-RC1+ (check composer.json for conflicts).
PHPCS Configuration:
If no --standard is set, defaults to PSR2 (not PSR12). Explicitly specify:
robo phpcs:run --standard=PSR12
Path Resolution:
Relative paths (e.g., --dir=src/) are resolved from the project root. Use absolute paths if needed:
robo phpcs:run --dir=/full/path/to/src
robo phpcs:run --debug
robo phpcs:run --dry-run
Custom Rules:
Extend PHPCS rules via phpcs.xml and reference them in tasks:
$this->taskPhpcsRun()->config('custom-rules.xml')->run();
Parallel Execution: Use Robo’s parallel tasks for large codebases:
$this->taskPhpcsRun()->parallel()->run();
Event Listeners: Hook into PHPCS events (e.g., file processing) via Robo’s event system:
$this->taskPhpcsRun()->on('task.phpcs.run', function ($task) {
// Custom logic
});
How can I help you explore Laravel packages today?