← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Composer Scripts & Hooks

php PHP 5.3+ Intermediate
debt(d7/e3/b3/t5)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The detection_hints indicate automated detection is 'no' — there's no linter or SAST tool that flags missing Composer scripts. The code_pattern describes symptoms (long CI commands, different developer invocations) that only surface through code review or observing CI drift. Composer itself doesn't warn about missing scripts.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix shows defining scripts in composer.json is straightforward — adding a scripts section with test, lint, analyse entries. However, it's not quite a one-line patch (e1) since you need to define multiple scripts and potentially update CI pipelines to use them, touching a few files.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). Missing Composer scripts creates a localised tax where each developer and CI pipeline may invoke tools differently, but this doesn't fundamentally shape the architecture. The applies_to shows web/cli contexts, meaning moderate reach, but the burden stays contained to build/dev tooling rather than runtime code. Once scripts are defined, the tax is paid and the system benefits.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap' (t5). The misconception field explicitly states developers think Composer scripts are 'only useful for running tests' when they can automate code generation, asset compilation, migrations, and any shell command. This is a documented gotcha that most PHP devs eventually learn, but the narrow mental model leads teams to miss the full task-runner capability built into every project.

About DEBT scoring →

Also Known As

Composer scripts composer.json scripts Composer hooks

TL;DR

Composer's scripts section automates tasks triggered on lifecycle events (install, update) or run manually — cache clearing, migrations, asset builds.

Explanation

Composer scripts are shell commands or PHP callables in the scripts key of composer.json, executed automatically on lifecycle events (post-install-cmd, post-update-cmd, post-autoload-dump) or manually with composer run. Common uses: clearing caches, running migrations, generating IDE helper files, and compiling assets. Security concern: scripts from third-party packages run with the same privileges as the Composer process — always audit composer.json of new dependencies before running composer install in CI. Use --no-scripts to disable all scripts when trust is uncertain, such as when first evaluating a package.

Watch Out

Malicious packages can execute arbitrary commands via Composer scripts on install. Review composer.json of all new dependencies and audit changes to existing ones.

Common Misconception

Composer scripts are only useful for running tests. Composer scripts can automate code generation, asset compilation, cache clearing, database migrations, and any shell command — they form a lightweight task runner built into every PHP project.

Why It Matters

Composer scripts automate common tasks (tests, linting, code generation) as project-level commands — they ensure every developer and CI pipeline runs tasks identically without separate documentation.

Common Mistakes

  • Not defining scripts for common tasks — developers run different commands and the team drifts.
  • Scripts that run dev-only tools (phpstan, phpcs) without guarding against --no-dev production installs.
  • Forgetting to chain scripts with @script syntax — duplicating command lists in multiple script entries.
  • Not documenting custom scripts — composer run without arguments lists available scripts, but descriptions help.

Code Examples

✗ Vulnerable
// No scripts defined — every dev runs slightly different commands:
{
  "require": {"php": ">=8.1"},
  "require-dev": {"phpunit/phpunit": "^10"}
  // Missing: scripts.test, scripts.lint, scripts.analyse
}
✓ Fixed
// composer.json scripts — automate common tasks
{
  "scripts": {
    "test":     "phpunit --colors=always",
    "lint":     "phpcs --standard=PSR12 src/ tests/",
    "lint:fix": "phpcbf --standard=PSR12 src/ tests/",
    "analyse":  "phpstan analyse src/ --level=6",
    "audit":    "composer audit",
    "ci":       ["@lint", "@analyse", "@test", "@audit"]
  },
  "scripts-descriptions": {
    "test": "Run PHPUnit test suite",
    "ci":   "Run full CI pipeline locally"
  }
}

// Run:
// $ composer test
// $ composer ci
// $ composer lint:fix

Added 15 Mar 2026
Edited 22 Mar 2026
Views 20
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 1 ping M 0 pings T 0 pings W 1 ping T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 1 ping F 1 ping S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S
No pings yet today
No pings yesterday
Amazonbot 6 Google 4 Perplexity 3 Unknown AI 3 Ahrefs 1 SEMrush 1
crawler 14 crawler_json 3 pre-tracking 1
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Low
⚡ Quick Fix
Define scripts in composer.json for common tasks: test, lint, analyse, check — then CI runs composer test instead of knowing the exact PHPUnit invocation
📦 Applies To
PHP 5.3+ web cli
🔗 Prerequisites
🔍 Detection Hints
Long CI commands hardcoding tool paths; no scripts section in composer.json; different developers using different tool invocations
Auto-detectable: ✗ No composer makefile
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: Medium ✗ Manual fix Fix: Low Context: File

✓ schema.org compliant