tomasvotruba/class-leak
Finds class leaks in PHP apps: detects classes unintentionally pulled into your runtime via autoloading, service container or tests. Helps trim dependencies, speed up CI, and keep boundaries clean by reporting unexpected class usage with clear, actionable output.
Find leaking classes that you never use... and get rid of them.
composer require tomasvotruba/class-leak --dev
Pass directories you want to check:
vendor/bin/class-leak check src
Make sure to exclude /tests directories, to keep reporting classes that are used in tests, but never used in the code-base.
Many types are excluded by default, as they're collected by framework magic, e.g. console command classes.
Do you want to skip classes of certain type?
vendor/bin/class-leak check src --skip-type="App\\Contract\\SomeInterface"
What if your classes do no implement any type?
vendor/bin/class-leak check src --skip-suffix="Controller"
Do you want to skip classes using a specific attribute?
vendor/bin/class-leak check src --skip-attribute="App\\Attribute\\AsController"
Happy coding!
How can I help you explore Laravel packages today?