Composer Scripts
Composer Scripts
Composer scripts let you define shortcut commands in your composer.json file. They are useful for reducing repetitive commands and for chaining multiple tools together into a single quality-check step.
Defining Scripts
Add a scripts section to your composer.json:
{
"scripts": {
"lint": "vendor/bin/pint",
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/pest",
"check": ["@lint", "@analyse", "@test"]
}
}
The @ prefix tells Composer to run another script by name. This means composer check will run lint, static analysis, and tests in sequence, stopping if any step fails.
Usage
composer lint # Run the code style checker
composer analyse # Run static analysis
composer test # Run the test suite
composer check # Run all three in order
Tips
- Order matters. Place the fastest checks first (lint) and the slowest last (tests) so that failures are caught early.
- Use named scripts everywhere. If you find yourself typing a long
vendor/bin/...command regularly, wrap it in a script. - Document your scripts. Anyone joining the project should be able to discover available checks by reading
composer.jsonor a short README entry.