Show unused packages by scanning your code
Working in a big repository with multiple people, sometimes you might lose track of you required composer packages. You have so many packages you can't be sure if they are used or not.
You can use composer why package/A
but that only gives you information about why this package is installed
in dependency to another package.
What if you need to find out if the provided namespaces of the package are used in your code?
composer unused
to the rescue!
Run
$ composer global require icanhazstring/composer-unused
Run
$ composer unused
Sometimes you don't want to scan a certain dir or ignore a composer package while scanning.
For this you can provide the --excludeDir|-xd
or the --excludePackage|-xp
parameter.
$ composer unused --excludeDir=config --excludePackage=symfony/console
Make sure the package is named exactly as in your
composer.json
You can provide multiple folders and package by repeating the argument.
If you encounter some errors, try running
$ composer unused -vvv
This will enable debug mode and create an error report beside your composer.json
.
composer-unused-dump-YmdHis
vagrant@ubuntu-bionic:/vagrant/doctrine/orm$ composer unused
Loading packages
----------------
Loading 15 requirements
15/15 [-----------------------------] 100%
! [NOTE] Skipped 2 requirements. No package found or invalid constraint.
* php
* ext-ctype
! [NOTE] Found 13 packages to be checked.
Scanning files...
-----------------
1174/1174 [-----------------------------] 100%
Found 13 used and 0 unused packages
Results
-------
Used packages
* doctrine/annotations ✓
* doctrine/cache ✓
* doctrine/collections ✓
* doctrine/dbal ✓
* doctrine/event-manager ✓
* doctrine/inflector ✓
* doctrine/instantiator ✓
* doctrine/persistence ✓
* doctrine/reflection ✓
* ocramius/package-versions ✓
* ocramius/proxy-manager ✓
* symfony/console ✓
* symfony/var-dumper ✓
Unused packages
Please have a look at CHANGELOG.md
.
Please have a look at CONTRIBUTING.md
.
Please have a look at CODE_OF_CONDUCT.md
.
This package is licensed using the MIT License.