Repository navigation
Ignore missing iterable value types of data providers in closed projects - #379
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
projectType: closed(PHPStan 2.4.0, bleeding edgefixMissingReturnTypes), the missing return types of methods that can be overridden are reported byMissingReturnTypeFixRule, a rule onCollectedDataNode.AnalyserResultFinalizerpasses ignore error extensions that node and a scope without a function, soDataProviderReturnTypeIgnoreExtensionno longer recognized data providers and reportedmissingType.iterableValueon them.On a large private project this was 438 false positives in closed mode, 0 in open mode.
Fix
DataProviderMethodCollector(onInClassNode) 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.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
DataProviderReturnTypeIgnoreExtensionClosedProjectTestruns aCompositeRuleofMissingImplementedMethodReturnTypehintRuleandMissingReturnTypeFixRulewithprojectType: closed, over the existing fixture plus a trait fixture. Both tests fail without the fix. The test skips itself on PHPStan versions withoutMissingReturnTypeFixRule.Notes
@phpstan-ignore phpstanApi.instanceofAssumptionforinstanceof 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.