icanhazstring / composer-unused
Show unused packages by scanning your code
Fund package maintenance!
Other
icanhazstring
Installs: 4 285 169
Dependents: 140
Suggesters: 2
Security: 0
Stars: 1 528
Watchers: 8
Forks: 55
Open Issues: 28
Requires
- php: ^7.4 || ^8.0
- ext-json: *
- composer-unused/contracts: ^0.3
- composer-unused/symbol-parser: ^0.2.1
- nikic/php-parser: ^4.15
- ondram/ci-detector: ^4.1
- phpstan/phpdoc-parser: ^1.12
- psr/container: ^1.0 || ^2.0
- psr/log: ^1.1 || ^2 || ^3
- symfony/config: ^4.4 || ^5.4 || ^6.0 || ^7.0
- symfony/console: ^4.4 || ^5.4 || ^6.0 || ^7.0
- symfony/dependency-injection: ^4.4.8 || ^5.4 || ^6.0 || ^7.0
- symfony/property-access: ^4.4 || ^5.4 || ^6.0 || ^7.0
- symfony/serializer: ^4.4 || ^5.4 || ^6.0 || ^7.0
- symfony/validator: ^4.4 || ^5.4 || ^6.0 || ^7.0
- webmozart/assert: ^1.10
- webmozart/glob: ^4.4
Requires (Dev)
- ext-ds: *
- ext-zend-opcache: *
- bamarni/composer-bin-plugin: ^1.8
- codeception/verify: ^3.0
- dg/bypass-finals: ^1.5
- ergebnis/composer-normalize: ^2.28
- jangregor/phpstan-prophecy: ^1.0
- php-ds/php-ds: ^1.4
- phpspec/prophecy-phpunit: ^2.0.2
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^1.10
- phpstan/phpstan-phpunit: ^1.3
- phpunit/phpunit: ^9.6.13
- roave/security-advisories: dev-master
- squizlabs/php_codesniffer: ^3.7
- dev-main
- 0.8.11
- 0.8.10
- 0.8.9
- 0.8.8
- 0.8.7
- 0.8.6
- 0.8.5
- 0.8.4
- 0.8.3
- 0.8.2
- 0.8.1
- 0.8.0
- 0.8.0-RC1
- 0.7.12
- 0.7.11
- 0.7.10
- 0.7.9
- 0.7.8
- 0.7.7
- 0.7.6
- 0.7.5
- 0.7.4
- 0.7.3
- 0.7.2
- 0.7.1
- 0.7.0
- 0.6.2
- 0.6.1
- 0.6.0
- 0.5.6
- 0.5.5
- 0.5.4
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.0
- 0.3.1
- 0.3.0
- 0.2.0
- 0.1.1
- 0.1.0
- dev-dependabot/github_actions/dependencies-7ae20179eb
- dev-dependabot/composer/dependencies-3405cdb127
- dev-build/box-4
- dev-composer-unused-340
- dev-fix/composer-plugin
This package is auto-updated.
Last update: 2024-10-24 03:36:49 UTC
README
composer-unused
A Composer tool to show unused Composer dependencies by scanning your code.
Created by Andreas Frömer and contributors, logo by Caneco.
⚠️ If you want to use this tool as composer-plugin head over to composer-unused-plugin.
Motivation
When working in a big repository, you sometimes lose track of your required Composer packages. There may be so many packages you can't be sure if they are actually used or not.
Unfortunately, the composer why
command only gives you the information about why
a package is installed in dependency to another package.
How do we check whether the provided symbols of a package are used in our code?
composer unused
to the rescue!
Installation
⚠️ This tool heavily depends on certain versions of its dependencies. A local installation of this tool is not recommended as it might not work as intended or can't be installed correctly. We do recommened you download the .phar
archive or use PHIVE to install it locally.
PHAR (PHP Archive) (recommended)
Install via phive
or grab the latest composer-unused.phar
from the latest release:
phive install composer-unused
curl -OL https://github.com/composer-unused/composer-unused/releases/latest/download/composer-unused.phar
Local
You can also install composer-unused
as a local development dependency:
composer require --dev icanhazstring/composer-unused
Usage
Depending on the kind of your installation the command might differ.
Note: Packages must be installed via composer install
or composer update
prior to running composer-unused
.
PHAR
The phar
archive can be run directly in you project:
php composer-unused.phar
Local
Having composer-unused
as a local dependency you can run it using the shipped binary:
vendor/bin/composer-unused
Exclude folders and packages
Sometimes you don't want to scan a certain directory or ignore a Composer package while scanning.
In these cases, you can provide the --excludeDir
or the --excludePackage
option.
These options accept multiple values as shown next:
php composer-unused.phar --excludeDir=config --excludePackage=symfony/console
php composer-unused.phar \
--excludeDir=bin \
--excludeDir=config \
--excludePackage=symfony/assets \
--excludePackage=symfony/console
Make sure the package is named exactly as in your
composer.json
Configuration
You can configure composer-unused by placing a composer-unused.php
beside the projects composer.json
This configuration can look something like this: composer-unused.php
Ignore dependencies by name
To ignore dependencies by their name, add the following line to your configuration:
$config->addNamedFilter(NamedFilter::fromString('dependency/name'));
Ignore dependencies by pattern
To ignore dependencies by pattern, add the following line to your configuration
$config->addPatternFilter(PatternFilter::fromString('/dependency\/name/'));
You can ignore multiple dependencies by a single organization using
PatternFilter
e.g./symfony\/.*/
Additional files to be parsed
Per default, composer-unused
is using the composer.json
autoload directive to determine where to look for files to parse.
Sometimes dependencies don't have their composer.json correctly set up, or files get loaded in another way.
Using this, you can define additional files on a per-dependency basis.
$config->setAdditionalFilesFor('dependency/name', [<list-of-file-paths>]);
Changelog
Please have a look at CHANGELOG.md
.
Contributing
Please have a look at CONTRIBUTING.md
.
Code of Conduct
Please have a look at CODE_OF_CONDUCT.md
.
License
This package is licensed under the MIT License.