Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
f2466bf
Require php-parser 5.3 so property hooks are analysed
ChrisAbner Nov 8, 2026
2056b32
Resolve modules and load the baseline once, and stop naming artisan i…
ChrisAbner Nov 8, 2026
9177a8a
Fail on unknown config keys, modules and dependencies
ChrisAbner Nov 8, 2026
644ad4e
Add error, warn and off severities per rule
ChrisAbner Nov 8, 2026
a8d9de3
Tell listener edges apart: they no longer close dependency cycles by …
ChrisAbner Nov 8, 2026
18c080d
Add --fail-on-stale
ChrisAbner Nov 8, 2026
45bc13d
Version the JSON report and publish its schema
ChrisAbner Nov 8, 2026
4cd6dd1
Mark the public API with @api and everything else @internal
ChrisAbner Nov 8, 2026
5840e79
Document 0.4
ChrisAbner Nov 8, 2026
93e083b
Keep warnings with --module and in the baseline, check the config in …
ChrisAbner Nov 8, 2026
b97778d
Guard the php-parser minimum in CI
ChrisAbner Nov 8, 2026
766c7de
Share the PHPStan setup between rules
ChrisAbner Nov 8, 2026
7133802
Find the module of a file analysed in editor mode
ChrisAbner Nov 8, 2026
0a795b1
Report undeclared dependencies in PHPStan
ChrisAbner Nov 8, 2026
04e6be3
Skip the editor mode tests on PHPStan versions without it
ChrisAbner Nov 8, 2026
4a2e48f
Report dependency cycles in PHPStan with collectors
ChrisAbner Nov 8, 2026
f4a26d5
Limit the report to some paths, for pre-commit hooks
ChrisAbner Nov 8, 2026
b55a944
Link each rule to its documentation and document local use
ChrisAbner Nov 8, 2026
b586ce6
Use PHPStan's own path in editor mode, and fix the docs about cycles
ChrisAbner Nov 8, 2026
97c40ba
Open the JSON schema to new optional fields and link each violation t…
ChrisAbner Nov 8, 2026
9ce2275
Warn about depends_on entries a module does not use
ChrisAbner Nov 8, 2026
0741162
Add GitLab Code Quality, JUnit and Checkstyle reports
ChrisAbner Nov 8, 2026
53aad81
Add explain, why and impact commands
ChrisAbner Nov 8, 2026
ffdf285
Export the module graph as Mermaid, DOT or JSON
ChrisAbner Nov 8, 2026
5edf96a
Point cross-module Eloquent relations to the recipe
ChrisAbner Nov 8, 2026
3602c82
Group each module's components by Laravel role in the generated docs
ChrisAbner Nov 8, 2026
da04a78
Fix the findings of the reports and CLI review
ChrisAbner Nov 8, 2026
0754f76
Check the code outside modules as a host (#25)
ChrisAbner Nov 8, 2026
2cfe98a
Allow ignoring a violation in place, with a reason
ChrisAbner Nov 8, 2026
74da9e1
Add layers as a shorthand for module dependencies
ChrisAbner Nov 8, 2026
4ccd373
Keep strict modules out of the baseline
ChrisAbner Nov 8, 2026
dc80db0
Warn when a public class exposes an internal one
ChrisAbner Nov 8, 2026
2e5d567
Fix the minor issues of the first review
ChrisAbner Nov 9, 2026
da9c2d4
Fix the findings of the rules and model review
ChrisAbner Nov 9, 2026
53d2866
Test the extractor against a matrix of positions, name forms and cont…
ChrisAbner Nov 9, 2026
ad1c89c
Calibrate the matrix with known bugs reintroduced
ChrisAbner Nov 9, 2026
15a100e
Read listener events and visibility attributes in any letter case
ChrisAbner Nov 9, 2026
7515e01
Add metamorphic tests over the real fixtures
ChrisAbner Nov 9, 2026
5091fad
Compare the extractor with reflection and the PHPStan rules
ChrisAbner Nov 9, 2026
c850643
Make every output independent of the file order
ChrisAbner Nov 9, 2026
59215b4
Measure coverage and mutation score of the analysis core
ChrisAbner Nov 9, 2026
e822e2f
Add a one-line Pest preset for module boundaries
ChrisAbner Nov 9, 2026
f39a53f
Fix the findings of the oracles and quality review
ChrisAbner Nov 9, 2026
c989f5b
Kill surviving mutants in IgnoreDirectives
ChrisAbner Nov 11, 2026
989e5c2
Kill surviving mutants in ReferenceCollector
ChrisAbner Nov 11, 2026
2febd61
Kill surviving mutants in ModuleFilter
ChrisAbner Nov 11, 2026
dd3bd5b
Kill surviving mutants in IgnoreChecker
ChrisAbner Nov 11, 2026
a7bbfd4
Kill surviving mutants in ListenerSignature
ChrisAbner Nov 11, 2026
78cf780
Kill surviving mutants in PublicApiPolicy
ChrisAbner Nov 11, 2026
b55e08f
Kill surviving mutants in CycleFinder
ChrisAbner Nov 11, 2026
57a5759
Kill surviving mutants in RuleSet
ChrisAbner Nov 11, 2026
28b946b
Kill surviving mutants in PublicApiLeakRule
ChrisAbner Nov 11, 2026
889c170
Kill surviving mutants in LayerRule
ChrisAbner Nov 11, 2026
10e184a
Kill surviving mutants in HostAccessRule
ChrisAbner Nov 11, 2026
797fcb4
Kill surviving mutants in InternalAccessRule
ChrisAbner Nov 11, 2026
5d0947a
Kill surviving mutants in UndeclaredDependencyRule
ChrisAbner Nov 11, 2026
64afa6d
Report layer violations per class
ChrisAbner Nov 11, 2026
ed0d148
List every rule in the rules tables
ChrisAbner Nov 11, 2026
2163a76
Record the 0.4 decisions as ADRs
ChrisAbner Nov 11, 2026
ad1d321
Prepare the 0.4.0 changelog and upgrade guide
ChrisAbner Nov 11, 2026
b5c9bdb
Bring the docs in line with 0.4
ChrisAbner Nov 11, 2026
940a9a5
Prepare 0.4.0
ChrisAbner Nov 11, 2026
e9d1fdc
Give the coverage job its own name, so the workflow is valid
ChrisAbner Nov 11, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
* text=auto eol=lf

/.github export-ignore
/docker export-ignore
/docs export-ignore
/tests export-ignore
/.gitattributes export-ignore
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ body:
id: versions
attributes:
label: Versions
placeholder: Cordon Modulith 0.3.1, PHP 8.4, Laravel 13, nwidart/laravel-modules 13
placeholder: Cordon Modulith 0.4.0, PHP 8.4, Laravel 13, nwidart/laravel-modules 13
validations:
required: true
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/false_positive.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ body:
id: versions
attributes:
label: Versions
placeholder: Cordon Modulith 0.3.1, PHP 8.4, Laravel 13
placeholder: Cordon Modulith 0.4.0, PHP 8.4, Laravel 13
validations:
required: true
76 changes: 74 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
matrix:
php: ['8.2', '8.3', '8.4', '8.5']
laravel: ['12.*', '13.*']
dependencies: ['highest']
exclude:
# Laravel 13 requires PHP 8.3.
- php: '8.2'
Expand All @@ -22,8 +23,13 @@ jobs:
testbench: '10.*'
- laravel: '13.*'
testbench: '11.*'
# The lowest version of every dependency, so the minimums in composer.json stay honest.
- php: '8.2'
laravel: '12.*'
testbench: '10.*'
dependencies: 'lowest'

name: PHP ${{ matrix.php }} / Laravel ${{ matrix.laravel }}
name: PHP ${{ matrix.php }} / Laravel ${{ matrix.laravel }} (${{ matrix.dependencies }})

steps:
- uses: actions/checkout@v7
Expand All @@ -36,7 +42,7 @@ jobs:
- name: Install dependencies
run: |
composer require "illuminate/support:${{ matrix.laravel }}" "illuminate/console:${{ matrix.laravel }}" "illuminate/contracts:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --prefer-dist --no-interaction
composer update --prefer-dist --no-interaction ${{ matrix.dependencies == 'lowest' && '--prefer-lowest' || '' }}

- name: Tests
run: vendor/bin/pest
Expand Down Expand Up @@ -73,3 +79,69 @@ jobs:

- name: 1,000 files in less than 10 seconds
run: composer bench

# The suite cannot test the lowest nikic/php-parser composer.json allows: its dev
# dependencies require a newer one. This installs Cordon alone, at its minimums.
parser-floor:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7

- uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
coverage: none

- name: Install the lowest dependencies, without require-dev
run: |
php -r '$j = json_decode(file_get_contents("composer.json"), true); unset($j["require-dev"], $j["autoload-dev"]); file_put_contents("composer.json", json_encode($j, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));'
composer update --prefer-dist --prefer-lowest --no-interaction

- name: The lowest php-parser analyses modern PHP
run: php tests/parser-floor.php

- name: The position matrix passes on the lowest php-parser
run: php tests/Oracle/check-matrix.php

# Runs the declaration cells of the position matrix in PHP and compares
# what reflection sees with what the matrix expects Cordon to find.
reflection-oracle:
name: Reflection oracle / PHP ${{ matrix.php }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.2', '8.3', '8.4', '8.5']
steps:
- uses: actions/checkout@v7

- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- run: php tests/Oracle/reflection.php

# Coverage of the whole package, and mutation testing of the classes whose
# tests declare mutates(). Thresholds are the measured values, rounded down.
coverage:
name: Coverage and mutation testing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7

- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: pcov

- run: composer update --prefer-dist --no-interaction

- name: Oracles (calibration and reflection)
run: composer oracle

- name: Coverage (at least 95%)
run: composer coverage

- name: Mutation testing (at least 88%)
run: composer mutate
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This file is for AI agents (and agent swarms) working on the Cordon Modulith cod

## Project in one paragraph

Cordon Modulith is a Laravel dev-dependency that verifies boundaries between modules. It statically parses PHP files (nikic/php-parser, never loading code), maps class references to modules, and runs rules (`internal_access`, `undeclared_dependency`, `cycles`). Entry points: `php artisan cordon:verify` (and `cordon:docs`), `vendor/bin/cordon` (the same commands without booting Laravel, `StandaloneApplication`), the Pest expectation `toRespectBoundaries()` and the PHPStan rule. Pipeline: `ModuleResolver` → `FileCollector` → `DependencyExtractor` → `Analyzer` (cross-module edges) → `Rule`s → `Baseline` → `Reporter`.
Cordon Modulith is a Laravel dev-dependency that verifies boundaries between modules. It statically parses PHP files (nikic/php-parser, never loading code), maps class references to modules, and runs rules (`internal_access`, `undeclared_dependency`, `cycles`, `unused_dependency`, `host_access`, `layers`, `public_api_leak`, each `error`, `warn` or `off`). Entry points: `php artisan cordon:verify` (and `cordon:docs`), `vendor/bin/cordon` (the same commands without booting Laravel, `StandaloneApplication`), the Pest expectation `toRespectBoundaries()` and the PHPStan rule. Pipeline: `ModuleResolver` → `FileCollector` → `DependencyExtractor` → `Analyzer` (cross-module edges) → `Rule`s → `Baseline` → `Reporter`.

## Hard rules

Expand Down
50 changes: 49 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,55 @@

All notable changes to Cordon Modulith are documented here. The project follows [Semantic Versioning](https://semver.org) from 1.0.0; before that, minor versions may contain breaking changes.

## [Unreleased]
## [0.4.0] - 2026-11-11

This release settles the model that 1.0 will freeze: rule severities, listener edges, a strict config, a versioned JSON report and the code outside the modules. Read [UPGRADE.md](UPGRADE.md) first: a broken config now stops `cordon:verify`, and some reports change. The decisions are recorded in [ADR 0015](docs/adr/0015-rule-severities.md) (severities, warnings and the baseline), [0016](docs/adr/0016-listener-edges.md) (listener edges), [0017](docs/adr/0017-host-module.md) (the `host`), [0018](docs/adr/0018-json-report-version.md) (the JSON report), [0019](docs/adr/0019-strict-configuration.md) (the strict config) and [0020](docs/adr/0020-rules-options-and-commands.md) (the other additions).

### Breaking
- `config/cordon.php` is validated before anything is analysed: unknown keys, unknown modules or dependencies, settings of the wrong type (`'Shared' => null`, a rule set to `null` or `1`), unknown rule ids and two custom rules with the same id stop `cordon:verify` with exit code `2`, with a suggestion for the closest valid name. They used to be ignored or only warned about, so a typo such as `depend_on` could leave a module open with CI green. `toRespectBoundaries()` and `Cordon::assertBoundaries()` fail on them too ([ADR 0019](docs/adr/0019-strict-configuration.md)).
- A listener's reference to another module's event no longer closes a dependency cycle. Two modules that call each other through a contract one way and an event the other are not reported as a cycle any more, and their `cycles` entries in the baseline become stale. Set `listeners.cycles` to `true` to count listeners again ([ADR 0016](docs/adr/0016-listener-edges.md)).
- The code outside the modules (`host.paths`: `app`, `routes` and `database` by default) is analysed for `host_access` (#25). `summary.files` in JSON and the file count of the text report include its files, a file there that does not parse is listed as skipped (and turns off `--fail-on-stale`), and a module named `host` is a configuration error. Set `host.paths` to `[]` to keep the 0.3 counts ([ADR 0017](docs/adr/0017-host-module.md)).
- Files outside the project root, such as the packages of a monorepo, are written relative to it with `../` (they used to be absolute paths, different on every machine). Baseline entries for those files become stale: run `cordon:verify --generate-baseline` once.
- If you use the PHPStan extension, PHPStan now also reports `cordon.undeclaredDependency` and `cordon.cycle`, which can fail a run that passed, and `cordon.incompleteGraph` when its `paths` leave a module out. Add the module directories to `paths`, or ignore `cordon.incompleteGraph` if you analyse parts of the project on purpose (see the PHPStan guide).
- `nikic/php-parser` 5.3 or later is required. Older 5.x versions skipped files with PHP 8.4 property hooks as parse errors (5.0, 5.1) or lost the types of hook parameters (5.2).
- `ModuleMap::configurationWarnings()` is removed: use `Cordon\Support\ConfigValidator::errors()`, which reports the same problems as errors.

### Added
- Severities per rule: `error`, `warn` or `off` (`true` and `false` keep working). Violations of a rule in `warn` are reported, never fail, and are neither written to the baseline nor hidden by it. The JSON report lists them under `warnings`, the GitHub format as `::warning`. Custom rules take a severity when their class is the key ([ADR 0015](docs/adr/0015-rule-severities.md)).
- `listeners` config (`cycles: false`, `depends_on: true` by default), and listener references in the analysis: the type of the first parameter of `handle()` or `__invoke()` under an `Events` namespace (and that event elsewhere in the listener, such as `failed()`), the keys of an `EventServiceProvider`'s `$listen` map, and the event of `Event::listen()`, with a class name or a closure.
- `--fail-on-stale`: a baseline entry that no longer matches the code fails `cordon:verify`, and each one is listed with the occurrences it records and the ones found. The check is skipped when a file does not parse.
- The JSON report starts with `"version": 1`, is described by `resources/schemas/report-v1.schema.json` and gives each violation a `severity` and the `docs_url` of its rule. A new optional field keeps version 1; removing or renaming one does not ([ADR 0018](docs/adr/0018-json-report-version.md)).
- `--format=gitlab`, `junit` and `checkstyle` reports, for GitLab Code Quality and the CI tools that read JUnit or Checkstyle.
- `host_access` (a warning by default): the code outside the modules may only use the public API of the modules. Filament resources, controllers and routes that reach into a module's internals are reported (#25). `AnalysisContext::$hostEdges` has its references.
- `unused_dependency` (a warning by default): a `depends_on` entry the module never uses. It says nothing about a module with a file that does not parse.
- `public_api_leak` (a warning by default): a public class whose public methods, properties or constants name an internal class of its own module. `Reference` has a new `signature` field, and `AnalysisContext::$signatures` lists those references.
- `layers`: layers of modules from the top down, as a shorthand for `depends_on`; a module that depends on a layer above its own is a violation (`layers` rule), reported once per file and class (the message names it, [ADR 0014](docs/adr/0014-layer-violations-per-class.md)) so the baseline tracks classes. It checks nothing until `layers` is configured.
- `strict` per module: the baseline never suppresses a strict module's violations (nor the cycles it takes part in), and `--generate-baseline` leaves them out. The PHPStan rules follow it.
- `// @cordon-ignore <rule>[, <rule>] (<reason>)` accepts a violation where it is, as a decision rather than baseline debt. The reason is required; a comment without one, or with an unknown rule, exits with code `2`; a comment that no longer matches is a warning. The JSON summary counts them in `ignored`, and the PHPStan rules honour them.
- PHPStan reports all three of its rules: `undeclared_dependency` (`cordon.undeclaredDependency`) per file, and `cycles` (`cordon.cycle`) with collectors on a full analysis, at the first reference of each dependency. Each error links to the rule's documentation.
- `cordon:verify <paths>`: report only the violations of some files or directories, plus the cycles their modules take part in, for pre-commit hooks (see the new recipe).
- `cordon:explain <class>` (its module, whether it is public and why, who uses it), `cordon:why <from> <to>` (the references behind a dependency, and whether `depends_on` allows it) and `cordon:impact <module>` (the modules that depend on it, directly or not). Also `explain`, `why`, `impact` and `graph` in `vendor/bin/cordon`.
- `cordon:graph`: the module graph as Mermaid, DOT (Graphviz) or JSON, with the dependencies that have violations marked; `--module` keeps one module and its neighbours.
- `cordon:docs` groups each module's components by Laravel role (models, controllers, jobs, listeners, events...) and shows the module's `metadata` description and owner. `ClassDeclaration` has the parent class and interfaces; `Module` has the metadata.
- An `internal_access` on the model of an Eloquent relation (`$this->belongsTo(Model::class)` and its siblings) links to the recipe for cross-module relations. `Reference` has a new `relation` flag.
- `Cordon::assertBoundaries()` and `php artisan vendor:publish --tag=cordon-tests`: one Pest test that fails with every module crossing its boundaries, and on a broken config or no modules.
- A per-module `metadata` key (free-form) and the reserved `Module::Interface` syntax in `depends_on`, for named interfaces later.
- Every class in `src/` is marked `@api` or `@internal`; see [compatibility](https://chrisabner.github.io/Cordon-Modulith/guide/compatibility).
- `AnalysisContext` has the files that could not be parsed (`parseErrors`), for custom rules.
- A `parser-floor` CI job checks that the lowest `nikic/php-parser` allowed analyses modern PHP.

### Changed
- A violation of a rule set to `error` is always reported as an error, whatever severity a custom rule gave it, so the JSON report matches its schema. `RuleSet::build()` returns the rules with their severities; a rule the container decorates keeps the severity of its config entry.
- With no modules, `cordon:verify` still validates `config/cordon.php` (root keys, rules, listeners, host) and exits with code `2` on an error, before saying no modules were found.
- The PHPStan rules report only while their rule is set to `error`.
- `ModuleResolver`, `Reporter` and `DependencyExtractor` are `@internal`: Cordon only uses them with the drivers it ships.
- The generated docs and the outdated baseline warning no longer say `php artisan` (#23).

### Fixed
- `cordon:verify` resolved the modules twice and read the baseline once per use (#20).
- Every report, the baseline, `cordon:docs` and `cordon:graph` are the same byte for byte whatever order the files are read in: the rules see references sorted by file and line (the line a violation reports is its first reference), and the event inventory lists publishers and listeners in file order.
- Class names written in another letter case (`\app\modules\billing\events\invoicepaid`) are read like PHP reads them: a listener's event under an `events` namespace, `#[\cordon\attributes\publicapi]`, an `EventServiceProvider` and the `Event` facade are recognised whatever their case. They used to turn a listener into a plain use (and could report a cycle) or ignore the attribute.
- The PHPStan rule reported nothing for the file being edited in editor mode (`--tmp-file`): its temporary path matched no module.

## [0.3.1] - 2026-11-05

Expand Down
18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ composer bench # analyses a synthetic project of 1,000 files; fails above 10 s

`php tests/Benchmark/run.php 5000 50` runs a larger benchmark (files, modules, optional time budget in seconds).

Coverage and mutation testing need pcov (or Xdebug):

```bash
composer coverage # the whole suite, fails below 95% line coverage
composer mutate # mutates the classes whose tests declare mutates(), fails below 88%
```

To mutate a class, add `mutates(TheClass::class);` to its test file. A surviving mutant either gets a test or, when it cannot change behaviour (an equivalent mutant), a line in the pull request saying why.

The oracles in `tests/Oracle/` check the extractor against independent sources:

```bash
composer oracle # the slower oracle tests, left out of composer test
php tests/Oracle/check-matrix.php # 1,800+ positions x name forms x containers
php tests/Oracle/calibrate.php # the matrix must fail with known bugs put back
tests/Oracle/run-reflection.sh # the matrix against PHP reflection, PHP 8.2 to 8.5 in Docker
```

## Pull requests

- One topic per pull request, with tests. Bug fixes start with a failing test.
Expand Down
Loading
Loading