Composer dependency checker
Published: , Updated:
Topics: quality assurance, typo3
Introduction ¶
This post will provide a small introduction into composer package "maglnet/composer-require-checker".
Some hints regarding usage for TYPO3 extensions is given, while there is not to much to know.
The composer package allows to check missing dependencies within composer.json. Its purpose is to run locally or in a CI to verify that all necessary dependencies are added to the composer.json file.
The blog posts expects a working composer environment. It will not explain how to migrate or setup a project using composer.
The blog post will follow a concrete example of an TYPO3 extension that is delivered to the public. The steps can be adapted to other PHP and TYPO3 projects.
Installation ¶
The package can be installed in different ways. Those are all mentioned in projects readme at https://packagist.org/packages/maglnet/composer-require-checker as well as on https://github.com/maglnet/ComposerRequireChecker. I'll add the package as development dependency to the extension:
composer req --dev maglnet/composer-require-checker
Depending on existing dependencies an older version might be necessary. E.g. "maglnet/composer-require-checker:2.0.*"
which supports older versions of symfony/console
. In order to ensure the package detects well known PHP native extensions and function, add PHP as dependency:
composer req "php:*"
Adjust the statement in case only specific PHP versions are supported.
Adding configuration file ¶
This step is optional, but suggested for TYPO3 extensions.
The package by default will check all files configured via composer autoloading. As TYPO3 extensions provide further files, e.g. configuration files, those need to be configured. This can happen with a custom JSON configuration file. No specific location is defined, it can be located in a subfolder or the projects root.
In the following example the file will be located in the extensions root folder and named dependency-checker.json
. The contents of the file differ from project to project but might look like the following:
{
"scan-files" : [
"*.php",
"Configuration/TCA/*.php",
"Configuration/TCA/Overrides/*.php"
]
}
An example can be found inside the projects repository: https://github.com/maglnet/ComposerRequireChecker/blob/2.1.0/data/config.dist.json. The above example will configure the tool to scan further files. All PHP files in project root, as well as some PHP files configuring TCA.
Executing ¶
Once everything is setup, one can execute the tool, this is done via:
./vendor/bin/composer-require-checker
As a configuration file should be read, the full execution looks like:
./vendor/bin/composer-require-checker check --config-file dependency-checker.json
Last hint ¶
The project aims to find missing dependencies in production code. It will not be extended or support require-dev
, suggest
or autoload-dev
.
Further reading ¶
The package can be found at:
- Packagist: https://packagist.org/packages/maglnet/composer-require-checker
- GitHub: https://github.com/maglnet/ComposerRequireChecker
The following TYPO3 Extension uses the package and can be used as an example:
- Example TYPO3 Extension: https://github.com/DanielSiepmann/tracking