Open Wirone opened 1 year ago
Hi @Wirone thanks for this interesting issue, I have a little question. If you write multiple expectations and a class violates them, Do you expect an error or more errors for that class? Because if you expect only one error the message could be not useful for the user if we show only one single violation. It's better to return multiple errors for the class with all the violations to understand well, what do you think?
@AlessandroMinoccheri it depends π
I believe there are scenarios when you would like to have multiple expectations but only one error if any of the expectations is not met (but print only those failed). For that "ideal" example, when there is no Rector
suffix it could be something like:
Codito\Rector\Money\Rule\Foo has 1 violation
should have a name that matches *Rector because we need to satisfy Rector's contract for rules and keep Rector naming convention
But when both expectation are not met, it could be:
Codito\Rector\Money\Rule\Foo has 1 violation
should have a name that matches *Rector AND should extend AbstractRector because we need to satisfy Rector's contract for rules and keep Rector naming convention
Probably because
should be defined better (shorter, like "it's a convention for rules"), but you get the point π
In general, I would like to avoid duplicating Rule::allClasses()->that(new ResideInOneOfTheseNamespaces('Codito\Rector\Money\Rule'))
. Since it's the same selector, IMHO it should be ready for reusing for different expectations. But currently the analysis result is invalid (2 out of 4 errors does not make sense because they mix expectations and explanations from different concerns).
We could make the class return from the that immutable, so that can be reused in different "shoulds".
Bug Report
Summary
Consider such configuration:
Since result of the
should()
is aBecauseParser
it does not allow multiple expectations for the same selection, I wanted to reuse result ofthat()
to make 2 separate rules. Unfortunately, it does not behave as I expected.Current behavior
For class that does not satisfy both rules (empty
Codito\Rector\Money\Rule\Foo
class) I get:How to reproduce
codito/rector-money
src/Rule
directorymake arkitect
Expected behavior
I would expect only 2 errors for such scenario:
Ideally, it would be great to be able to define rule like this:
and set multiple expectations for single rule.