maglnet/composer-require-checker
CLI tool that scans your PHP sources and composer.json to ensure every used class/function comes from declared dependencies. Detects “soft” transitive deps and missing required PHP extensions, helping prevent breakage after dependency updates.
Dependency Hygiene & Risk Mitigation:
Build vs. Buy:
Roadmap Priorities:
composer outdated) to auto-fix issues.Use Cases:
guzzlehttp/guzzle via thatvendor/api-lib).composer validate or phpstan instead).| Tool | Focus | PHP-Specific? | CI-Friendly? |
|---|---|---|---|
phpstan |
Static analysis (types) | Yes | Yes |
psalm |
Static analysis (advanced) | Yes | Yes |
composer validate |
composer.json syntax |
Yes | Yes |
| Custom Script | Ad-hoc dependency checks | Yes | Maybe |
*"This tool is like a dependency X-ray for our PHP projects. Right now, we might unknowingly rely on libraries that aren’t explicitly listed in our codebase—like using a tool from your car because it’s already in the garage, but not paying for it. If the garage owner (Composer) changes the tool’s location or version, our code breaks unexpectedly.
ComposerRequireChecker scans our code to flag these ‘hidden’ dependencies, forcing us to explicitly declare what we use. This:
- Reduces risk from undocumented library updates (e.g., API failures after a Composer upgrade).
- Saves time by catching issues early (e.g., during PR reviews or CI checks).
- Improves security by eliminating ‘accidental’ exposure to vulnerable transitive deps.
Cost: Free (MIT license), runs in CI (~1–5 mins), and pays for itself by preventing post-release fires. Ask: Should we pilot this in [High-Risk Project X] to audit dependencies before the next major release?"*
*"Problem: Transitive dependencies (e.g.,
guzzlehttp/guzzlepulled in bythatvendor/api-lib) are a ticking time bomb. When upstream packages update, your code may break silently—only discovered in QA or production.Solution: ComposerRequireChecker is a CLI tool that:
- Static analyzes your PHP code to detect symbols (classes/functions) used from non-explicit dependencies.
- Flags ‘soft’ dependencies (e.g.,
use GuzzleHttp\Psr7\Stream;whenguzzlehttp/psr7isn’t inrequire).- Checks PHP extensions (e.g.,
opensslfunctions withoutext-opensslinrequire).Why Now?
- Prevents ‘works on my machine’ issues from transitive updates.
- Integrates with CI (e.g., GitHub Actions) to block bad PRs early.
- Lightweight: No runtime overhead; runs in ~1–5 mins for large codebases.
Implementation:
- Add to CI (e.g.,
php composer-require-checker.phar check composer.json).- Configure whitelists for false positives (e.g.,
vendor/bin/scripts).- Treat warnings as blocking until resolved.
Trade-offs:
- False positives: Rare, but configurable (see
config.dist.json).- No runtime checks: Pairs well with
composer validateandphpstan.Next Steps:
- Run against [Project Y] to validate ROI.
- Propose adding to pre-commit hooks for developer feedback.
- Explore auto-fixing via
composer require(future work)."*
How can I help you explore Laravel packages today?