Download the PHP package shipmonk/modulint without Composer
On this page you can find all versions of the php package shipmonk/modulint. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download shipmonk/modulint
More information about shipmonk/modulint
Files in shipmonk/modulint
Package modulint
Short Description Enforce architecture by defining modules with allowed dependencies. Detects forbidden, uncovered, missing and unused module dependencies in PHP projects.
License MIT
Informations about the package modulint
Modulint - module dependency enforcer for PHP
- ð§ą Module-aware: define modules over your codebase and declare which other modules each one may depend on
- ðĶ Strict: detects forbidden, uncovered, missing and unused module dependencies
- ðŠķ Lightweight: single static analysis pass over your sources
- âïļ Configurable: pure PHP config, modules identified by your own enum
- âĻ Compatible: PHP 8.1+
Why?
Once a codebase grows, hand-written rules like "the Logging module must not depend on Doctrine" tend to drift. shipmonk/modulint lets you declare those rules as data and enforce them in CI.
A module is a named bag of paths (files and/or directories). For each module you declare which other modules it is allowed to depend on. Modulint walks every PHP file in each module, parses it, resolves used class-like symbols (classes, interfaces, traits, enums) via Composer's autoloader, looks up which module they belong to, and reports:
- Forbidden dependency â module
Xuses a class belonging to moduleY, andYis not inX's allowed dependencies. - Uncovered dependency â module
Xuses a class that is not part of any declared module. - Missing module â a file inside a "fully-modulized" directory is not covered by any module.
- Unused dependency â module
Xdeclares a dependency on moduleYbut never actually uses anything from it.
Installation
Usage
Create modulint.php in your project root:
Then run:
Exit code is 0 when everything is clean and 1 otherwise.
Example output
When something is wrong, modulint groups the violations by type and points at the exact file-to-file edge that broke the rule:
When everything checks out:
Concepts
Module identifier
ModuleIdentifier is an empty marker interface extending UnitEnum. You implement it by writing your own enum. Using an enum gives you autocompletion and refactoring support, and the IDE will tell you immediately if you reference a module that does not exist.
Allowed dependencies
The dependencies constructor argument controls what a module can use:
[]â module can only use symbols defined inside itself.[OtherModule::X, OtherModule::Y]â module can additionally use symbols from those modules.nullâ module can depend on anything. Use this for vendor-bag modules so that whoever depends on them never produces a forbidden-dependency error, and modulint will not report unused dependencies for them.
A dependency on a parent module implicitly allows dependencies on its nested modules: [...] children.
Fully-modulized directories
addFullyModulizedDirectory('src') makes modulint complain about any .php file under src/ that no module claims. This is how you keep the configuration honest as code is added.
Vendor modules
A common pattern is to declare one module per relevant vendor package, pointing at vendor/<package> as its paths, with dependencies: null. That lets you assert which parts of your code may use which vendor library â typically the most useful kind of architectural rule.
Disable colored output
Set NO_COLOR to disable ANSI colors:
Contributing
- Check your code with
composer check - Autofix coding-style with
composer fix:cs - All functionality must be tested
Supported PHP versions
- Runtime requires PHP 8.1+