Skip to content

Make phpunit.dataProviderPublic auto-fixable - #366

Merged
staabm merged 1 commit into
phpstan:2.1.xfrom
staabm:fixable-public
Nov 28, 2026
Merged

staabm merged 1 commit into
phpstan:2.1.xfrom
staabm:fixable-public

Conversation

@staabm

@staabm staabm commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

analog 22c6949 - fixing this error was suggested by ondrej

@staabm
staabm marked this pull request as ready for review November 27, 2026 14:21
@staabm

staabm commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

#367 should be fixed first, and than this one needs a rebase

@staabm
staabm marked this pull request as draft November 27, 2026 14:51
@staabm

staabm commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

// @SanderMuller

@staabm
staabm marked this pull request as ready for review November 28, 2026 07:34

@SanderMuller SanderMuller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking over the trait lookup from #367. I checked 8a46ab1 against 2.1.x (a3436e6) with PHPStan 2.3.7.

  • testFixDataProviderPublic fails with the src change reverted and passes with it.
  • A private provider in a trait gets the fix in the trait. A protected provider in a parent class in another file gets the fix in the parent's file.
  • A public trait method that the class aliases as protected (use ProvidesData { provide as protected; }) gets the error but no fix. The fix would leave the method unchanged, so PHPStan drops it instead of offering a fix that does nothing. A provider renamed through an alias (provide as protected dataProvide) also gets no fix.
  • If another subclass overrides the provider as protected, the fix makes that subclass a fatal error. PHPStan reports it on the next run (method.visibility), and the static fix has the same property with method.nonStatic.
  • The test suite (141 tests), PHPStan, phpcs and lint pass locally. CI is green.

Performance: the extra findMethodNode() call costs little. My test file has 300 classes, each with a protected non-static provider. With only the lookup, the analysis takes 3.21 s, against 3.14 s on 2.1.x. Each new fix adds about 1 ms in a 450-line file and about 10 ms in a 4,500-line file. That is the cost of the fix diff, and it applies only to files that have the error.

@staabm
staabm merged commit f161708 into phpstan:2.1.x Nov 28, 2026
114 checks passed
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.

3 participants