Skip to content
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

Add NotHaveDependencyWithTheseMethods(...) and except(...) clauses to add rules and improve expressivity #206

Open
ricfio opened this issue Nov 27, 2021 · 3 comments
Labels

Comments

@ricfio
Copy link
Contributor

ricfio commented Nov 27, 2021

Feature Request

Q A
New Feature yes
RFC yes
BC Break no

Summary

I think that could be useful require that a specific function must be called only inside a specific Class (wrapper).

For example:
I would like that json_encode(..) and json_encode(..) functions not be called outside of my JsonHelper class wrapper because i want encapsulate my json serialization / deserialization logic inside JsonHelper.

PS
I don't known how we could express this rules, because we may need a new exception clause (not a php exception) to apply to Rule::allClasses() that at this time does not exists (I believe).

See the ->except(..) and NotHaveDependencyWithTheseMethods clauses below, please.

    $rules[] = Rule::allClasses()
        ->except(new TheseClasses('JsonHelper'))
        ->that(new ResideInOneOfTheseNamespaces('App'))
        ->should(new NotHaveDependencyWithTheseMethods('json_encode','json_decode'))
        ->because("we want wrap our serialization and deserialization logic");

If there will be interest on the two above proposals we can split this issue in two separated issues (srp solid principles).

@AlessandroMinoccheri
Copy link
Member

Hi @ricfio this is an interesting feature, but for us, the next release will only parse dependencies between classes and not parsing methods.

In the future, we can discuss it.

@micheleorselli
Copy link
Contributor

@ricfio would you mind create a different issue for "except"? Is something we discussed earlier and, at that time, we decided to not include it in the DSL. Main reason: ->except could be interpreted as a way to

  • exclude classes from being evaluated (allClasses -> except)
  • exclude classes from the that clause (that(ResideInOneOfTheseNamespaces) -> except)
  • exclude classes from the should clause (should(NotHaveDependenciesOutside) -> except)

@ricfio
Copy link
Contributor Author

ricfio commented Dec 5, 2021

Sure @micheleorselli , I added this new issue:
#209

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

No branches or pull requests

3 participants