Skip to content

Commit 1b9c1e6

Browse files
committed
Note about removing ParametersAcceptorSelector::selectSingle()
1 parent f25de9c commit 1b9c1e6

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

UPGRADING.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ Identifiers are also required in custom rules.
123123

124124
Learn more: [Using RuleErrorBuilder to enrich reported errors in custom rules](https://phpstan.org/blog/using-rule-error-builder)
125125

126-
Before:
126+
**Before**:
127127

128128
```php
129129
return ['My error'];
130130
```
131131

132-
After:
132+
**After**:
133133

134134
```php
135135
return [
@@ -143,6 +143,47 @@ return [
143143

144144
Learn more: [Why Is instanceof *Type Wrong and Getting Deprecated?](https://phpstan.org/blog/why-is-instanceof-type-wrong-and-getting-deprecated)
145145

146+
### Removed deprecated `ParametersAcceptorSelector::selectSingle()`
147+
148+
Use [`ParametersAcceptorSelector::selectFromArgs()`](https://apiref.phpstan.org/2.0.x/PHPStan.Reflection.ParametersAcceptorSelector.html#_selectFromArgs) instead. It should be used in most places where `selectSingle()` was previously used, like dynamic return type extensions.
149+
150+
**Before**:
151+
152+
```php
153+
$defaultReturnType = ParametersAcceptorSelector::selectSingle($functionReflection->getVariants())->getReturnType();
154+
```
155+
156+
**After**:
157+
158+
```php
159+
$defaultReturnType = ParametersAcceptorSelector::selectFromArgs(
160+
$scope,
161+
$functionCall->getArgs(),
162+
$functionReflection->getVariants()
163+
)->getReturnType();
164+
```
165+
166+
If you're analysing function or method body itself and you're using one of the following methods, ask for `getParameters()` and `getReturnType()` directly on the reflection object:
167+
168+
* [InClassMethodNode::getMethodReflection()](https://apiref.phpstan.org/2.0.x/PHPStan.Node.InClassMethodNode.html)
169+
* [InFunctionNode::getFunctionReflection()](https://apiref.phpstan.org/2.0.x/PHPStan.Node.InFunctionNode.html)
170+
* [FunctionReturnStatementsNode::getFunctionReflection()](https://apiref.phpstan.org/2.0.x/PHPStan.Node.FunctionReturnStatementsNode.html)
171+
* [MethodReturnStatementsNode::getMethodReflection()](https://apiref.phpstan.org/2.0.x/PHPStan.Node.MethodReturnStatementsNode.html)
172+
* [Scope::getFunction()](https://apiref.phpstan.org/2.0.x/PHPStan.Analyser.Scope.html#_getFunction)
173+
174+
**Before**:
175+
176+
```php
177+
$function = $node->getFunctionReflection();
178+
$returnType = ParametersAcceptorSelector::selectSingle($function->getVariants())->getReturnType();
179+
```
180+
181+
**After**:
182+
183+
```
184+
$returnType = $node->getFunctionReflection()->getReturnType();
185+
```
186+
146187
### Changed `TypeSpecifier::create()` and `SpecifiedTypes` constructor parameters
147188

148189
[`PHPStan\Analyser\TypeSpecifier::create()`](https://apiref.phpstan.org/2.0.x/PHPStan.Analyser.TypeSpecifier.html#_create) now accepts (all parameters are required):

0 commit comments

Comments
 (0)