Weave 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

Class Leak Laravel Package

tomasvotruba/class-leak

Class Leak is a PHP dev tool that finds classes you never use, helping you remove dead code. Scan directories and skip types, suffixes, or attributes; exclude tests so classes used only there are still reported.

View on GitHub
Deep Wiki
Context7

Detect leaking classes

Frequently asked questions about Class Leak
How do I install Class Leak in a Laravel project?
Install it as a Composer dev dependency with composer require tomasvotruba/class-leak --dev. Then run vendor/bin/class-leak check src against the directories you want to scan. It runs as a static analysis tool and has no runtime coupling with your Laravel application.
How does Class Leak detect unused classes?
Class Leak uses reference-graph-based static analysis: you point it at a directory, and it reports classes that are never referenced elsewhere in the scanned code. It is designed for Laravel and PHP projects where framework magic often collects classes automatically. Many framework-collected types, such as console commands, are skipped by default.
Will Class Leak find classes resolved by Laravel's service container, facades, or config?
Class Leak relies on static reference analysis, so it has blind spots for Laravel's dynamic class loading patterns. Classes resolved only through app()->make(), config-driven instantiation, facade calls, route definitions, or variable class names may be reported as unused. Treat findings as candidates and review or skip classes that are resolved indirectly.
How do I skip classes that implement a specific interface?
Use the --skip-type flag with the fully qualified interface name. For example, run vendor/bin/class-leak check src --skip-type="App\\Contract\\SomeInterface". This is useful for contracts or types that your framework collects without direct static references.
Can I exclude controllers or other classes by naming convention?
Yes. Use --skip-suffix to exclude classes by suffix, such as vendor/bin/class-leak check src --skip-suffix="Controller". This helps when classes do not implement a shared interface but are still collected by framework conventions.
How do I skip classes that use a specific attribute?
Use the --skip-attribute flag with the attribute class name. For example, run vendor/bin/class-leak check src --skip-attribute="App\\Attribute\\AsController". This lets you ignore classes marked for framework discovery by attributes rather than interfaces or suffixes.
Should I exclude tests when running Class Leak?
Yes, the README advises excluding /tests directories so classes used only in tests are still reported. That keeps test usage from masking classes that are unused in your actual codebase. Pass only the production source directories you want to analyze.
Does Class Leak scan artisan and custom bin scripts?
Release 2.3.5 adds shebang scanning (#106), which is relevant to Laravel because artisan and many custom bin wrappers are extensionless PHP files with a shebang. Previously such files could be silently excluded from the scan root, hiding console bootstrapping paths and causing false positives. The provided context does not state whether it follows require/include chains out of artisan or only parses the entry file, so verify that behavior for your setup.
How should I upgrade from 2.3.4 to 2.3.5 and regenerate my baseline?
Upgrade the dependency to ^2.3.5 first, then regenerate the baseline, because the new shebang scanning and default skips change the result set. Diff the old and new baseline and confirm every change is explained by #104, #105, or #106. Keep the job advisory until the baseline is stable, then add it as a blocking CI gate if desired.
Does Class Leak ship a Laravel-specific default skip list, and can I override default skips?
The 2.3.5 release adds default skips for Symfony contracts such as EnvVarProcessorInterface and Messenger TransportFactoryInterface, but the provided context does not document an equivalent Illuminate\Contracts default set. It also does not state whether those default skips are user-overridable. For Laravel projects, expect to add your own --skip-type, --skip-suffix, or --skip-attribute rules for container-resolved classes and review upstream release notes when defaults change.
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.
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect
youbar/easy-crud
c-point-labs/laravel-hostyourai
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo