Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Imports Analyzer Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

  • Pre-commit hook: Add check_imports --no-ansi --format=json to .git/hooks/pre-commit or use simple-phpunit to fail early if imports are dirty.
  • CI gate: In GitHub Actions, include a step: ./vendor/bin/check_imports --no-ansi --format=json > imports-report.json && test -z "$(cat imports-report.json | jq '.summary.errors')".
  • Targeted scans: Use --path=app/Models to focus on high-traffic areas or --exclude=database/migrations to avoid vendor-generated noise.
  • Fix automation: Parse JSON output to auto-delete unused imports (the tool only reports—no auto-fix). Example: write a Laravel-zero command that reads check_imports output and strips use lines via regex.
  • IDE integration: Configure PhpStorm or VS Code tasks to run check_imports on save and display warnings based on exit code (1 = issues found).

Gotchas and Tips

  • Laravel facades: The tool may misflag facade imports (e.g., 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.
  • Dynamic usage: Imports used in class_exists($name), eval(), or new ($class)() will always be flagged as unused. Use @noinspection PHPUnusedUseInspection above the import to silence warnings.
  • Wildcard imports unsupported: use App\Models\*; is not recognized—convert to explicit imports or accept the false positive.
  • Configurable paths: If your structure deviates (e.g., src/Domain/*), override with --path=src or create php-imports-config.php to define custom scan roots.
  • JSON output for dashboards: Use --format=json to feed reports into internal tooling (e.g., Laravel Telemetry or custom Slack bots).
  • Stability caution: With only 21 stars and no dependents, pin the version (e.g., "^1.0") and test upgrades carefully—API or behavior may change without semver guarantees.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport