SyntaxStudy
Sign Up
PHP Beginner 3 min read

Composer Scripts

Composer Scripts

Composer scripts run shell commands or PHP callbacks as build automation steps — similar to npm scripts.

Example
"scripts": {
  "test":  "phpunit --colors=always",
  "lint":  "php-cs-fixer fix",
  "analyse": "phpstan analyse src --level=8",
  "build": ["@lint", "@analyse", "@test"],
  "post-install-cmd": ["php artisan optimize"],
  "post-update-cmd":  ["php artisan optimize:clear"]
}
// Run with: composer test   or   composer run build
Pro Tip

Chain scripts with arrays — composer build runs lint, analyse, then test in sequence.