Skip to content

Ignore missing iterable value types of data providers in closed projects - #379

Merged
ondrejmirtes merged 2 commits into
2.1.xfrom
closed-project-data-provider-ignore
Dec 5, 2026
Merged

ondrejmirtes merged 2 commits into
2.1.xfrom
closed-project-data-provider-ignore

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

With projectType: closed (PHPStan 2.4.0, bleeding edge fixMissingReturnTypes), the missing return types of methods that can be overridden are reported by MissingReturnTypeFixRule, a rule on CollectedDataNode. AnalyserResultFinalizer passes ignore error extensions that node and a scope without a function, so DataProviderReturnTypeIgnoreExtension no longer recognized data providers and reported missingType.iterableValue on them.

On a large private project this was 438 false positives in closed mode, 0 in open mode.

Fix

  • New DataProviderMethodCollector (on InClassNode) records the file and start line of the data providers of each test class. It's registered under the same condition as the ignore extension.
  • For errors on CollectedDataNode, the extension matches the error's file and line against the collected data. This also covers data providers declared in traits, whose errors are reported in the trait's file.

Test

DataProviderReturnTypeIgnoreExtensionClosedProjectTest runs a CompositeRule of MissingImplementedMethodReturnTypehintRule and MissingReturnTypeFixRule with projectType: closed, over the existing fixture plus a trait fixture. Both tests fail without the fix. The test skips itself on PHPStan versions without MissingReturnTypeFixRule.

Notes

  • Uses @phpstan-ignore phpstanApi.instanceofAssumption for instanceof CollectedDataNode. A more general alternative would be for PHPStan to put the class and method of such errors in their metadata, so that every ignore extension can use it.
  • As before, only data providers that are methods of the test class itself are considered.

In a closed project (projectType: closed), PHPStan 2.4 reports the missing
return types of methods that can be overridden from MissingReturnTypeFixRule,
a rule on CollectedDataNode. Ignore error extensions get that node and a scope
without a function, so DataProviderReturnTypeIgnoreExtension did not recognize
the data providers and their missing iterable value types were reported.

DataProviderMethodCollector records the file and start line of the data
providers of test classes, and the extension matches errors reported on
CollectedDataNode against them.

Amp-Thread-ID: https://ampcode.com/threads/T-01a241be-e622-75dd-bbf3-b2f123235eda
The data provider ignore extension relies on how PHPStan 2.4 reports missing
return types, so the tests no longer need to check whether its rules exist.

Amp-Thread-ID: https://ampcode.com/threads/T-01a241be-e622-75dd-bbf3-b2f123235eda
@ondrejmirtes
ondrejmirtes merged commit bd9caaf into 2.1.x Dec 5, 2026
113 checks passed
@ondrejmirtes
ondrejmirtes deleted the closed-project-data-provider-ignore branch December 5, 2026 09:18
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