Skip to content

Configure mago guard to enforce the library's layering - #249

Open
simon-mundy wants to merge 1 commit into
php-db:0.6.xfrom
simon-mundy:qa/mago-guard
Open

simon-mundy wants to merge 1 commit into
php-db:0.6.xfrom
simon-mundy:qa/mago-guard

Conversation

@simon-mundy

@simon-mundy simon-mundy commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Configure guard in mago.toml.

Dependency May be used only from
PhpDb\Container\ PhpDb (ConfigProvider), Container
PhpDb\TableGateway\ TableGateway, Container
PhpDb\RowGateway\ RowGateway, TableGateway, Container
PhpDb\Metadata\ Metadata, TableGateway, Container
PhpDb\Sql\ Sql and the layers above it, Adapter\Platform, PhpDb

These use restrictions, not layering. A layering list denies every dependency it doesn't explicitly permit, including PHP built-ins such as #[Override]. Restrictions forbid only what they name and leave everything else allowed. The two known back-edges are permitted explicitly, so they are documented in the config and cannot spread to other namespaces.

Structural inclusions: Codebase baseline rules/conventions.

  • classes in an Exception namespace are named *Exception;
  • interfaces are named *Interface;
  • classes in PhpDb\Container are named *Factory, apart from AdapterInterfaceDelegator.

Tests are excluded: Test code may depend on anything.

Omissions

  • must-be-final: making public classes final is an API decision.
  • must-implement: it only checks a class's own implements clause, not inherited interfaces.

Verification

  • mago guard reports no issues on this branch, and with Bring src/Adapter to Mago compliance #248 (Adapter) merged in.
  • Two deliberate 'mistakes' added temporarily were both reported during initial testing:
    • a class in PhpDb\Sql that takes and returns a TableGateway: disallowed-use, disallowed-parameter-type and disallowed-return-type;
    • an interface not named *Interface: must-be-named.
  • mago format --check, mago lint, mago analyze and mago guard run correctly on PHP 8.3, 8.4 and 8.5.
  • The full PHPUnit suite passes. Only mago.toml changes.

mago guard had no perimeter or structural rules, so it passed without
checking anything. Add five perimeter restrictions that forbid upward
dependencies between the library's layers, and three naming rules the
codebase already follows. Restrictions forbid only the dependencies they
name, so everything else stays allowed; the two known back-edges are
permitted on purpose. Tests are excluded, since they may depend on
anything.
@codecov

codecov Bot commented Nov 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@simon-mundy simon-mundy self-assigned this Nov 4, 2026
@simon-mundy
simon-mundy requested a review from tyrsson November 4, 2026 08:54
@simon-mundy simon-mundy added the qa Improvements in quality assurance of the project label Nov 4, 2026
@github-project-automation github-project-automation Bot moved this to Todo in @phpdb Nov 4, 2026
@simon-mundy simon-mundy added this to the 0.6.0 milestone Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

qa Improvements in quality assurance of the project

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant