Skip to content

Skip test classes in NewOverSettersRule - #314

Merged
TomasVotruba merged 1 commit into
mainfrom
skip-controllers-new-over-setters
Sep 23, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
skip-controllers-new-over-setters

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

The NewOverSettersRule reports classes that are always new-ed with the same setters and suggests promoting those values to the constructor.

Test classes trip a false positive: a test instantiates the subject with new and then calls its methods to exercise behavior. Those calls are the test act, not construction-time configuration, so they should not drive a constructor-promotion suggestion.

Example from a downstream project - a model is wired as a service in production (only conditionally invoked from an event subscriber), but two unit tests do new GrapesJsBuilderModel(...) followed by ->addOrEditEntity($email). Since addOrEditEntity starts with add, it was collected as a setter and the rule fired, even though the class is never configured this way in production.

The collector now skips test classes via the existing TestClassDetector.

@TomasVotruba
TomasVotruba merged commit fa3c397 into main Sep 23, 2026
8 checks passed
@TomasVotruba
TomasVotruba deleted the skip-controllers-new-over-setters branch September 23, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant