2017 © Pedro Peláez
 

library composer-require-checker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

image

maglnet/composer-require-checker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  • Wednesday, July 11, 2018
  • by maglnet
  • Repository
  • 8 Watchers
  • 134 Stars
  • 21,125 Installations
  • PHP
  • 113 Dependents
  • 1 Suggesters
  • 15 Forks
  • 20 Open issues
  • 26 Versions
  • 54 % Grown

The README.md

ComposerRequireChecker

A CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package. This will prevent you from using "soft" dependencies that are not defined within your composer.json require section., (*1)

PHP ^7.4 current version Build Status, (*2)

What's it about?

"Soft" (or transitive) dependencies are code that you did not explicitly define to be there, but use it nonetheless. The opposite is a "hard" (or direct) dependency., (*3)

Your code most certainly uses external dependencies. Imagine that you found a library to access a remote API. You require thatvendor/api-lib for your software and use it in your code. This library is a hard dependency., (*4)

Then you see that another remote API is available, but no library exists. The use case is simple, so you look around and find that guzzlehttp/guzzle (or any other HTTP client library) is already installed, and you use it right away to fetch some info. Guzzle just became a soft dependency., (*5)

Then some day, when you update your dependencies, your access to the second API breaks. Why? Turns out that the reason guzzlehttp/guzzle was installed is that it is a dependency of thatvendor/api-lib you included, and their developers decided to update from an earlier major version to the latest and greatest, simply stating in their changelog: "Version 3.1.0 uses the lates major version of Guzzle - no breaking changes expected.", (*6)

And you think: What about my broken code?, (*7)

Composer-require-checker parses your code and your composer.json-file to see whether your code uses symbols that are not declared as a required library, i.e. that are soft dependencies. If you rely on components that are already installed, but you didn't explicitly request them, this tool will complain about them, and you should require them explicitly, making them hard dependencies. This will prevent unexpected updates., (*8)

In the situation above you wouldn't get the latest update of thatvendor/api-lib, but your code would continue to work if you also required guzzlehttp/guzzle before the update., (*9)

The tool will also check for usage of PHP functions that are only available if an extension is installed, and will complain if that extension isn't explicitly required., (*10)

Installation / Usage

Composer require checker is not supposed to be installed as part of your project dependencies., (*11)

PHAR file [preferred]

Please check the releases for available phar files. Download the latest release and and run it like this:, (*12)

php composer-require-checker.phar check /path/to/your/project/composer.json

PHIVE

If you already use PHIVE to install and manage your project’s tooling, then you should be able to simply install ComposerRequireChecker like this:, (*13)

phive install composer-require-checker

Composer - global command

This package can be easily globally installed by using Composer:, (*14)

composer global require maglnet/composer-require-checker

If you haven't already setup you composer installation to support global requirements, please refer to the Composer cli - global If this is already done, run it like this:, (*15)

composer-require-checker check /path/to/your/project/composer.json

Configuration

Composer require checker is configured to whitelist some symbols per default. Have a look at the config file example to see which configuration options are available., (*16)

You can now adjust this file, as needed, and tell composer-require-checker to use it for it's configuration., (*17)

Note that you'll have to copy it's contents if you want to add something on top. This tool intentionally only reads one configuration file. If you pass only your new settings, you'll get error reports about the PHP core extensions and internal symbols like true or false being undefined., (*18)

bin/composer-require-checker check --config-file=path/to/config.json /path/to/your/project/composer.json

Scan Additional Files

To scan files, that are not part of your autoload definition you may add glob patterns to the config file's scan-files section. Copy the default file and add to your copy., (*19)

The following example would also scan the file bin/console and all files with .php extension within your bin/ folder:, (*20)

"scan-files" : ["bin/console", "bin/*.php"]

If you don't like copying the tool's default settings, consider adding these paths to the Composer autoloading section of your project instead., (*21)

Usage

Composer require checker runs on an existing directory structure. It does not change your code, and does not even install your composer dependencies. That is a task that is entirely up to you, allowing you to change/improve things after a scan to see if it fixes the issue., (*22)

So the usual workflow would be, (*23)

  1. Clone your repo
  2. composer install your dependencies
  3. composer-require-checker check your code

Dealing with custom installer plugins

Composer require checker only fetches it's knowledge of where files are from your project's composer.json. It does not use Composer itself to understand custom directory structures., (*24)

If your project requires to use any install plugins to put files in directories that are not vendor/ or defined via the vendor-dir config setting in composer.json, composer require checker will fail to detect the required code correctly., (*25)

As a workaround, you can install your dependencies without plugins just for the scan:, (*26)

  1. Clone your repo
  2. composer install --no-plugins will put all code into the vendor folder
  3. composer-require-checker check your code
  4. composer install dependencies once again in the correct location

License

This package is made available under the MIT LICENSE., (*27)

Credits

This package was initially designed by Marco Pivetta and Matthias Glaub.
And of course all Contributors., (*28)

The Versions

11/07 2018

dev-feature/add-additional-scan-files

dev-feature/add-additional-scan-files https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

11/07 2018

dev-master

9999999-dev https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

11/07 2018

1.0.0

1.0.0.0 https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

20/03 2018

0.2.1

0.2.1.0 https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

10/03 2018

dev-bugfix/record-definition-of-define

dev-bugfix/record-definition-of-define https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

20/01 2018

dev-feature/chnage-preferred-install

dev-feature/chnage-preferred-install https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

20/01 2018

0.2.0

0.2.0.0 https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

20/01 2018

dev-bugfix/dont-fail-on-parse-errors

dev-bugfix/dont-fail-on-parse-errors https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

20/01 2018

dev-feature/exclude-from-classmap

dev-feature/exclude-from-classmap https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

15/11 2017

dev-bugfix/44-error-on-trait-adaptation

dev-bugfix/44-error-on-trait-adaptation https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

04/11 2017

dev-feature/psr-code-style

dev-feature/psr-code-style https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

31/10 2017

dev-feature/perform-basic-check-command-test

dev-feature/perform-basic-check-command-test https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

11/10 2017

dev-feature/remove-example-code

dev-feature/remove-example-code https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

11/10 2017

dev-feature/add-scruitinizer-fails

dev-feature/add-scruitinizer-fails https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

24/09 2017

0.1.6

0.1.6.0 https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

24/09 2017

dev-feature/add-shebang-to-phar

dev-feature/add-shebang-to-phar https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

23/07 2017

0.1.5

0.1.5.0 https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

15/07 2017

dev-bugfix/phar-bultin

dev-bugfix/phar-bultin https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

13/05 2017

0.1.4

0.1.4.0 https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

13/05 2017

0.1.3

0.1.3.0 https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

25/03 2017

dev-feature/add-scrutinizer

dev-feature/add-scrutinizer https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

25/03 2017

dev-feature/phpunit-6

dev-feature/phpunit-6 https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

17/05 2016

0.1.2

0.1.2.0 https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

16/12 2015

dev-feature/suggest-dependencies-from-php-src

dev-feature/suggest-dependencies-from-php-src https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

02/12 2015

0.1.1

0.1.1.0 https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports

02/12 2015

0.1.0

0.1.0.0 https://github.com/Ocramius/ComposerRequireChecker

CLI tool to analyze composer dependencies and verify that no unknown symbols are used in the sources of a package

  Sources   Download

MIT

The Requires

 

The Development Requires

composer cli analysis dependency require requirements imports