Download the PHP package kajstrom/dependency-constraints without Composer
On this page you can find all versions of the php package kajstrom/dependency-constraints. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kajstrom/dependency-constraints
More information about kajstrom/dependency-constraints
Files in kajstrom/dependency-constraints
Package dependency-constraints
Short Description Create constraints in your test suite to prevent unwanted dependencies.
License BSD-3-Clause
Informations about the package dependency-constraints
DependencyConstraints
DependencyConstraints is a static code analysis tool for creating constraints for dependencies between modules in your project. It is intended to be used within a testing library such as PHPUnit or Codeception.
The core idea of DependencyConstraints is to shorten the feedback loop for finding changes that degrade the architecture of your application. Instead of finding out 6 months later that you or someone else on the team added undesirable coupling into your application, you can create tests that act as a safeguard against such changes.
DependencyConstraints is inspired by JDepend and Fitness Functions introduced in the book Building Evolutionary Architectures.
Getting started
To get started require DependencyConstraints with Composer.
After DependencyConstraints has been installed you can start creating tests with it. It is recommended to create only a single instance of DependencyConstraints as it will go through all PHP files in your in the target directory.
In addition, you should use DependencyConstraints on your own src/classes directory. It is not necessary for DependencyConstraints to parse vendor directory etc. to be able to look for usages of external classes.
Using PHPUnit the test would look like this.
What is considered to be a dependency
DependencyConstraints assumes the following to be dependencies:
- Using a class, interface, trait or instances of a class from another module (namespace).
- Using a function from another module.
- Using a constant from another module.
Currently globally scoped classes, functions and constants are not considered to be dependencies.
Using something from a submodule is not considered to be a dependency.
For example:
Using "MyProject\ModuleA\SomeClass" in "MyProject\ModuleB" is a dependency.
Using "MyProject\ModuleA\SubModule\SomeClass" in "MyProject\ModuleA" is not a dependency.
Potential use cases
In a layered architecture you might want to prevent other layers of your software from becoming coupled to the presentation layer.
Perhaps you have a modular monolith and want to ensure that a certain module will not get coupled to another module.
Or maybe you want to keep certain external libraries out of the Application layer in a Hexagonal Architecture.
You can also check for dependencies on a certain class. Maybe you are refactoring it out but it keeps popping up in new places all the time!
Limitations
As a static code analysis tool DependencyConstraints can't catch absolutely everything. Let's say someone wants to be clever and do something like this:
This would not be found as a dependency when analyzing the source.
Why not use Pdepend?
Pdepend offers very useful metrics on the quality of the codebase, but it does not allow testing dependencies between modules.
All versions of dependency-constraints with dependencies
ext-tokenizer Version ^7.1.0