Skip to content

Suggestion for clearer dependency constraint syntax for standalone modules #492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
pfazzi opened this issue May 1, 2025 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@pfazzi
Copy link
Collaborator

pfazzi commented May 1, 2025

Feature Request

Q A
New Feature yes
RFC yes
BC Break no

Summary

We have some modules in the codebase that are designed to be standalone, depending only on PHP core classes. A typical example is our Clock module.

Currently, we express this constraint like this:

// The Clock module should be standalone.
// It can only use PHP core classes like DateTime.
Rule::allClasses()
    ->that(new ResideInOneOfTheseNamespaces('Acme\Clock'))
    ->should(new NotHaveDependencyOutsideNamespace(
        'Acme\Clock',
        externalDependenciesToExclude: ['DateTimeImmutable', 'DateTime']
    ))
    ->because('the Clock module must be almost standalone');

We’ve found this expression a bit verbose and hard to generalize. To make the intent more clear and easier to read, I’d like to propose supporting a more concise alternative:

Rule::namespace('Acme\Clock')
    ->canDependOnlyOn('DateTimeImmutable', 'DateTime');

This alternative would improve the readability of the rule, especially when applied to multiple modules with similar constraints (e.g., pure helpers, adapters, or low-level libraries).

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants