tomasvotruba/unused-public
PHPStan extension that finds unused public methods, properties, and constants by scanning calls across your codebase. Helps clean up dead APIs or spot members that should be private/protected. Supports gradual adoption via allowed % thresholds and excluding template-used methods.
Install the package via Composer with composer require tomasvotruba/unused-public --dev. It integrates with PHPStan, so no additional setup is needed if you’re using the phpstan/extension-installer. Enable detection by adding a simple config to phpstan.neon:
parameters:
unused_public:
methods: true
properties: true
constants: true
Run it via vendor/bin/unused-public (or ./vendor/bin/unused-public on Windows). Start with a minimal scope—e.g., scan just app/Http/Controllers—to build confidence in results before expanding coverage.
unused-public as a step in GitHub Actions/GitLab CI to fail builds when unused public elements exceed thresholds (e.g., methods: 2.5).methods: 2.5) to prevent overwhelming teams—fix regressions before tackling historical debt.template_paths for Blade (resources/views) or Twig to avoid false positives for methods used in views (e.g., {{ $book->getTitle() }}).@api annotations to public methods intended for external consumption (e.g., packages, SDKs) to exclude them from reports.local_methods: true to flag public methods only used within the class—ideal for identifying candidates to downgrade to private/protected.@phpstan-ignore-line or exclusions in config (e.g., exclude_paths: ['app/Console/Commands']).__get, __call, or Symfony OptionsResolver may be incorrectly flagged—annotate with @api or exclude explicitly.--debug to see why an element is marked unused/used—this reveals missing usages (e.g., in string-based method calls like call_user_func([$obj, 'getTitle'])).methods: true) with targeted thresholds (methods: 5.0) per namespace via custom PHPStan configs for incremental adoption.How can I help you explore Laravel packages today?