phpat icon indicating copy to clipboard operation
phpat copied to clipboard

Add combination operators to selectors

Open gplanchat opened this issue 2 years ago • 0 comments

Enhancement description While defining my rules, I need to define some fine grained rules such as:

  • If class implements interface X, I want it to use trait A or B or C
  • if class uses trait A, I want its class to implement interface A and one of ( B or C )

Currently, all rules are combining as an and operator. Those operators may be useful:

  • all of (and operator)
  • any of (or operator)
  • none of (not operator)
  • one of (xor operator)
  • at least X of
  • at most X of

Suggested approach or solution By creating new selectors, I can now define more precise rules

$this->newRule
    ->classesThat(Selector::implementInterface('EventSauce\EventSourcing\AggregateRoot'))
    ->mustInclude()
    ->classesThat(
        Selector::oneOf(
            Selector::haveClassName('EventSauce\EventSourcing\AggregateRootWithAggregates'),
            Selector::haveClassName('EventSauce\EventSourcing\AggregateRootBehaviour'),
            Selector::haveClassName('EventSauce\EventSourcing\AggregateAlwaysAppliesEvents'),
        )
    )
    ->build();

gplanchat avatar Jun 15 '22 07:06 gplanchat