Skip to content

Fix duplicate registration of RepositoryMethodCallRule#764

Merged
ondrejmirtes merged 2 commits into
phpstan:2.0.xfrom
janedbal:fix-duplicate-repository-method-call-rule
Jun 2, 2026
Merged

Fix duplicate registration of RepositoryMethodCallRule#764
ondrejmirtes merged 2 commits into
phpstan:2.0.xfrom
janedbal:fix-duplicate-repository-method-call-rule

Conversation

@janedbal
Copy link
Copy Markdown
Contributor

@janedbal janedbal commented Jun 2, 2026

Problem

RepositoryMethodCallRule is currently registered twice in rules.neon:

  1. In the rules: section (autowired, so checkOrderByFields defaults to false):
    rules:
        - PHPStan\Rules\Doctrine\ORM\RepositoryMethodCallRule
  2. As a tagged service in services:, wiring checkOrderByFields to the bleeding-edge toggle:
    services:
        -
            class: PHPStan\Rules\Doctrine\ORM\RepositoryMethodCallRule
            arguments:
                checkOrderByFields: %featureToggles.bleedingEdge%
            tags:
                - phpstan.rules.rule

Both registrations carry the phpstan.rules.rule tag, so PHPStan instantiates and runs the rule twice. As a result every magic findBy* / findOneBy* violation is reported as a duplicate error.

The services: entry was added in 5485522 ("Check field names of orderBy parameter in findBy and findOneBy"), while the rules: entry already existed — making the rules: line a stray duplicate. The same commit also updated the entityRepositoryDynamicReturn-0.json integration fixture to expect the doubled output, which hid the regression.

Fix

  • Remove the rules: entry and keep only the services: registration, which is the intended one since it wires the checkOrderByFields toggle.
  • Restore the entityRepositoryDynamicReturn-0.json fixture so each findOneBy() / findBy() error is expected once.

Co-Authored-By: Claude Code

janedbal added 2 commits June 2, 2026 22:17
RepositoryMethodCallRule was registered twice: once in the `rules:`
section (autowired with checkOrderByFields defaulting to false) and
again as a tagged service in `services:` wiring
checkOrderByFields to the bleedingEdge feature toggle.

Both registrations carry the phpstan.rules.rule tag, so the rule
executed twice and reported every magic findBy*/findOneBy* violation
as a duplicate.

Keep only the `services:` registration, which is the intended one as
it wires the checkOrderByFields toggle introduced together with the
duplicate.

Co-Authored-By: Claude Code
The duplicate RepositoryMethodCallRule registration made the
findOneBy()/findBy() field errors appear twice; the fixture had been
updated to expect the doubled output. With the duplicate registration
removed, each error is reported once again.

Co-Authored-By: Claude Code
@ondrejmirtes ondrejmirtes merged commit e20e8bf into phpstan:2.0.x Jun 2, 2026
51 checks passed
@ondrejmirtes
Copy link
Copy Markdown
Member

Thank you!

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.

2 participants