imanghafoori/php-imports-analyzer
CLI tool to scan Composer-based PHP projects for unnecessary or incorrect use/import statements. Helps clean up imports and enforce coding standards across apps and open-source packages. Install as dev dependency or globally; run check_imports from your project root.
Install the package as a dev dependency with composer require imanghafoori/php-imports-analyzer --dev, then run ./vendor/bin/check_imports from your Laravel project root. The CLI scans app/, src/, config/, database/, and routes/ by default and instantly reports unused or incorrect use statements (e.g., imported classes never used, or used classes not imported). Start with a small module—like app/Services—to validate accuracy before broad adoption.
check_imports --no-ansi --format=json to .git/hooks/pre-commit or use simple-phpunit to fail early if imports are dirty../vendor/bin/check_imports --no-ansi --format=json > imports-report.json && test -z "$(cat imports-report.json | jq '.summary.errors')".--path=app/Models to focus on high-traffic areas or --exclude=database/migrations to avoid vendor-generated noise.check_imports output and strips use lines via regex.check_imports on save and display warnings based on exit code (1 = issues found).use Illuminate\Support\Facades\Cache;) as unused—even if used via Cache::get()—because it performs static string analysis without resolving Facade aliases. Mitigation: temporarily add // @phpstan-ignore-line or verify false positives manually; consider reporting them as issues.class_exists($name), eval(), or new ($class)() will always be flagged as unused. Use @noinspection PHPUnusedUseInspection above the import to silence warnings.use App\Models\*; is not recognized—convert to explicit imports or accept the false positive.src/Domain/*), override with --path=src or create php-imports-config.php to define custom scan roots.--format=json to feed reports into internal tooling (e.g., Laravel Telemetry or custom Slack bots)."^1.0") and test upgrades carefully—API or behavior may change without semver guarantees.How can I help you explore Laravel packages today?