Skip to content

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

Open
@ricfio

Description

@ricfio

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions