All Projects → maglnet → Composerrequirechecker

maglnet / Composerrequirechecker

Licence: mit
A CLI tool to check whether a specific composer package uses imported symbols that aren't part of its direct composer dependencies

Projects that are alternatives of or similar to Composerrequirechecker

Taylor
Measure Swift code metrics and get reports in Xcode, Jenkins and other CI platforms.
Stars: ✭ 300 (-46.14%)
Mutual labels:  code-quality
Solhint
Solhint is an open source project created by https://protofire.io. Its goal is to provide a linting utility for Solidity code.
Stars: ✭ 363 (-34.83%)
Mutual labels:  code-quality
Sonar Dotnet
Code analyzer for C# and VB.NET projects https://redirect.sonarsource.com/plugins/vbnet.html
Stars: ✭ 466 (-16.34%)
Mutual labels:  code-quality
Eslint Plugin Import
ESLint plugin with rules that help validate proper imports.
Stars: ✭ 3,722 (+568.22%)
Mutual labels:  code-quality
Git Cop
DEPRECATED: Use Git Lint (https://www.alchemists.io/projects/git-lint) instead.
Stars: ✭ 352 (-36.8%)
Mutual labels:  code-quality
Gradle Static Analysis Plugin
Easy setup of static analysis tools for Android and Java projects.
Stars: ✭ 398 (-28.55%)
Mutual labels:  code-quality
Gradle Code Quality Tools Plugin
Gradle plugin that generates ErrorProne, Findbugs, Checkstyle, PMD, CPD, Lint, Detekt & Ktlint Tasks for every subproject.
Stars: ✭ 282 (-49.37%)
Mutual labels:  code-quality
Flake8 Bugbear
A plugin for Flake8 finding likely bugs and design problems in your program. Contains warnings that don't belong in pyflakes and pycodestyle.
Stars: ✭ 518 (-7%)
Mutual labels:  code-quality
Detekt
Static code analysis for Kotlin
Stars: ✭ 4,169 (+648.47%)
Mutual labels:  code-quality
Simplecov
Code coverage for Ruby with a powerful configuration library and automatic merging of coverage across test suites
Stars: ✭ 4,362 (+683.12%)
Mutual labels:  code-quality
Pylint
It's not just a linter that annoys you!
Stars: ✭ 3,733 (+570.2%)
Mutual labels:  code-quality
Grumphp
Submitting bugs and feature requests
Stars: ✭ 3,679 (+560.5%)
Mutual labels:  code-quality
Sonar Kotlin
SonarQube plugin for Kotlin
Stars: ✭ 412 (-26.03%)
Mutual labels:  code-quality
Reviewdog
🐶 Automated code review tool integrated with any code analysis tools regardless of programming language
Stars: ✭ 4,541 (+715.26%)
Mutual labels:  code-quality
Awesome Guidelines
A curated list of high quality coding style conventions and standards.
Stars: ✭ 6,379 (+1045.24%)
Mutual labels:  code-quality
Sonar Php
🐘 SonarPHP: PHP static analyzer for SonarQube & SonarLint
Stars: ✭ 288 (-48.29%)
Mutual labels:  code-quality
Sourcery
Refactor Python using AI. ⭐ this repo and Sourcery Starbot will send you a PR
Stars: ✭ 372 (-33.21%)
Mutual labels:  code-quality
Pep8speaks
A GitHub app to automatically review Python code style over Pull Requests
Stars: ✭ 546 (-1.97%)
Mutual labels:  code-quality
Phpdependencyanalysis
Static code analysis to find violations in a dependency graph
Stars: ✭ 505 (-9.34%)
Mutual labels:  code-quality
Log Process Errors
Show some ❤️ to Node.js process errors
Stars: ✭ 424 (-23.88%)
Mutual labels:  code-quality

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.

PHP ^7.4 current version Build Status

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.

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.

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.

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."

And you think: What about my broken code?

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.

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.

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.

Installation / Usage

Composer require checker is not supposed to be installed as part of your project dependencies.

PHAR file [preferred]

Please check the releases for available phar files. Download the latest release and and run it like this:

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:

phive install composer-require-checker

Composer - global command

This package can be easily globally installed by using Composer:

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:

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.

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

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.

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.

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

"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.

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.

So the usual workflow would be

  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.

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.

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

  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.

Credits

This package was initially designed by Marco Pivetta and Matthias Glaub.
And of course all Contributors.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].