Add NotHaveDependencyWithTheseMethods(...) and except(...) clauses to add rules and improve expressivity
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).
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.
@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)
Sure @micheleorselli , I added this new issue: https://github.com/phparkitect/arkitect/issues/209