Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Oct 27, 2025

As we are now validating data-providers by its return/yield statements, I think we should no longer throw a

Method DataProviderIterableValueTest\Foo::dataProvider() return type has no value type specified in iterable type iterable.

error onto the PHPStan user


requires phpstan/phpstan-src#4488

@staabm staabm marked this pull request as ready for review October 27, 2025 07:44

public function shouldIgnore(Error $error, Node $node, Scope $scope): bool
{
if (! $node instanceof InClassMethodNode) { // @phpstan-ignore phpstanApi.instanceofAssumption
Copy link
Member

Choose a reason for hiding this comment

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

This assumes an implementation detail that missingType.iterableValue is reported by a rule that hooks onto InClassMethodNode.

You can remove this instanceof and just ask for $scope->isInClass(), $scope->getFunction() etc.

Copy link
Contributor Author

@staabm staabm Oct 27, 2025

Choose a reason for hiding this comment

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

got this code from the docs :).

doc-fix in phpstan/phpstan#13726

thank you.

@ondrejmirtes
Copy link
Member

BTW I love this, it's genius :)

@ondrejmirtes ondrejmirtes merged commit 5c89d74 into phpstan:2.0.x Oct 27, 2025
70 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the ign branch October 27, 2025 11:08
@VincentLanglet
Copy link
Contributor

@staabm @ondrejmirtes Is there an easy way to (?)

  • take advantage of the DataProviderDataRule
  • without enabling the DataProviderReturnTypeIgnoreExtension

Would it be ok to have such option ?

Maybe like

checkDataProviderData: %featureToggles.bleedingEdge% ignoreDataProviderReturnType: %featureToggles.bleedingEdge% PHPStan\Type\PHPUnit\DataProviderReturnTypeIgnoreExtension:	phpstan.ignoreErrorExtension: %phpunit.ignoreDataProviderReturnType% 

or

checkDataProviderData: %featureToggles.bleedingEdge% checkDataProviderReturnType: false PHPStan\Type\PHPUnit\DataProviderReturnTypeIgnoreExtension:	phpstan.ignoreErrorExtension: [%phpunit.ignoreDataProviderReturnType%, not(%phpunit.checkDataProviderReturnType%)] 

if such syntax exists...

In our codebase, we appreciate the fact PHPStan enforce the detailed phpdoc of iterable (for documentation purpose), and even if the return/yield statement are now checked, we still find some interest in the required phpdoc.

@ondrejmirtes
Copy link
Member

So I realize I don't want to have a long-term option for turning off DataProviderDataRule. I only want it to be conditional now in 2.x based on bleedingEdge.

As for the data provider return types, I can imagine there to be an option named something like reportMissingDataProviderReturnType that would default to false. You could set it to true to disable the ignore errors extension.

Feel free to send a PR.

@VincentLanglet
Copy link
Contributor

Feel free to send a PR.

Like this #253 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants