Skip to content

Commit a011960

Browse files
authored
add generic template to node-returning methods with same param and return union (#406)
Narrows the return type to the passed node type via @template. Satisfies the new PreferGenericTemplateOnSameUnionTypeRule from symplify/phpstan-rules.
1 parent e56a1cd commit a011960

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎rules/DowngradePhp80/Rector/Expression/DowngradeMatchToSwitchRector.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ private function isEqualScope(Match_ $match, ?Scope $containerScope): bool
237237
return $matchScope->getParentScope() === $containerScope->getParentScope();
238238
}
239239

240+
/**
241+
* @template TNode of Arg|FuncCall|Assign|Expression|Return_
242+
* @param TNode $containerArrowFunction
243+
* @return TNode|null
244+
*/
240245
private function refactorInArrowFunction(
241246
Arg|FuncCall|Assign|Expression|Return_ $containerArrowFunction,
242247
ArrowFunction $arrowFunction,

‎rules/DowngradePhp81/Rector/FunctionLike/DowngradeNewInInitializerRector.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ private function isParamSkipped(Param $param): bool
146146
return $param->type instanceof IntersectionType;
147147
}
148148

149+
/**
150+
* @template TFunctionLike of ClassMethod|Closure|Function_
151+
* @param TFunctionLike $functionLike
152+
* @return TFunctionLike
153+
*/
149154
private function replaceNewInParams(ClassMethod|Closure|Function_ $functionLike): ClassMethod|Closure|Function_
150155
{
151156
$isConstructor = $functionLike instanceof ClassMethod && $this->isName($functionLike, MethodName::CONSTRUCT);

‎rules/DowngradePhp82/Rector/Class_/DowngradeUnionIntersectionRector.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ public function refactor(Node $node): ?Node
8181
return $this->processClassLike($node);
8282
}
8383

84+
/**
85+
* @template TFunctionLike of ClassMethod|Function_|Closure|ArrowFunction
86+
* @param TFunctionLike $functionLike
87+
* @return TFunctionLike|null
88+
*/
8489
private function processFunctionLike(
8590
ClassMethod|Function_|Closure|ArrowFunction $functionLike
8691
): null|ClassMethod|Function_|Closure|ArrowFunction {

0 commit comments

Comments
 (0)