Download the PHP package dbublik/unused-class-hunter without Composer
On this page you can find all versions of the php package dbublik/unused-class-hunter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dbublik/unused-class-hunter
More information about dbublik/unused-class-hunter
Files in dbublik/unused-class-hunter
Package unused-class-hunter
Short Description Detects unused classes in your codebase
License MIT
Informations about the package unused-class-hunter
Unused class hunter
Detects unused classes in your PHP codebase.
Installation
Usage
After installation, you can run the following command to start hunting:
And that’s it! The Hunter will scan your entire codebase and find all unused classes. If you want to delete them immediately, just run the command:
Customization
Config:
Most likely, after the first run, the Hunter will find classes that are actually used.
In this case you can help it by creating a configuration file .unused-class-hunter.php in the root of the project:
If your config file has another path, you can specify this via the "config" option:
Ignoring classes:
If you want to ignore certain classes, you have three options. The first two are to specify the classes or the attributes of these classes in the config:
The third option is to use one of our "filter".
In the engine of this project we use two filters - ClassFilter and AttributeFilter.
But there are other filters - for example ApiTagFilter (which filters classes with the tag @api).
See all filters in directory /src/Filter.
Or you can create your own custom filter:
Unignoring classes:
If classes are used as false positives, you can use our pre-filter or create your own. It helps indicate to the Hunter that the classes should be marked as unused.
For more details, see directory /src/PreFilter.
Sets for some libraries:
The Hunter contains several predefined sets for different libraries, which can be enabled with this config:
Custom cache directory:
By default, the Hunter stores its cache files in sys_get_temp_dir() . '/unused-class-hunter' (usually
/tmp/unused-class-hunter).
You can override this by setting the setCacheDir method:
Custom bootstrap files:
If you need to initialize something in PHP runtime before the Hunter runs (like your own autoloader), you can provide your own bootstrap files:
Strict mode
If you want the strictest rules, you can enable this:
List of them:
- Classes that are only listed in phpdoc are not considered to be used;
Output format
The Hunter supports text (by default), gitlab and github formats.
Supported PHP versions
PHP 8.2 and later.
All versions of unused-class-hunter with dependencies
nikic/php-parser Version ^5.4
symfony/console Version ^6.4 || ^7.0
symfony/finder Version ^6.4 || ^7.0