Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

forbidReturnValueInYieldingMethod #152

Merged
merged 5 commits into from
Sep 7, 2023
Merged

Conversation

janedbal
Copy link
Member

@janedbal janedbal commented Sep 7, 2023

No description provided.

@janedbal janedbal merged commit c588201 into master Sep 7, 2023
10 checks passed
@janedbal janedbal deleted the return-value-in-yielding-method branch September 7, 2023 12:13
@@ -580,6 +583,28 @@ enum MyEnum {
}
```

### forbidReturnValueInYieldingMethod
- Disallows returning values in yielding methods unless marked to return Generator as the value is accessible only via [Generator::getReturn](https://www.php.net/manual/en/generator.getreturn.php)
- To prevent misuse, this rule can be configured to even stricter mode where it reports such returns regardless of return type declared
Copy link
Member

Choose a reason for hiding this comment

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

Looking at this for second time, I find this as such a niche use-case that I'd make it strict by default with option to disable it.

With PHPStan error identifiers, it's sounds like a good tradeoff (to whitelist proper usages)

}

if ($methodReflection !== null) {
return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
Copy link
Member

Choose a reason for hiding this comment

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

I don't see test cases for generics and I'm not sure if this method is going to return once you use generics in the method definition.

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.

None yet

2 participants