arkitect icon indicating copy to clipboard operation
arkitect copied to clipboard

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

Open ricfio opened this issue 4 years ago • 3 comments

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).

ricfio avatar Nov 27 '21 14:11 ricfio

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.

AlessandroMinoccheri avatar Dec 02 '21 08:12 AlessandroMinoccheri

@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)

micheleorselli avatar Dec 02 '21 16:12 micheleorselli

Sure @micheleorselli , I added this new issue: https://github.com/phparkitect/arkitect/issues/209

ricfio avatar Dec 05 '21 16:12 ricfio