Skip to content

Commit

Permalink
[TypeDeclaration] Skip already typed param on AddClosureParamTypeForA…
Browse files Browse the repository at this point in the history
…rrayReduceRector (#6737)
  • Loading branch information
samsonasik authored Feb 15, 2025
1 parent 6137332 commit 19aff25
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\FunctionLike\AddClosureParamTypeForArrayReduceRector\Fixture;

class SkipAlreadyTypedParam
{
/**
* @param list<string> $array
*/
public function run(array $array)
{
return array_reduce($array, function (string $carry, ?string $value) {
return $carry . $value;
}, '');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,7 @@ private function refactorParameter(Param $param, Type $type): bool

// already set → no change
if ($param->type instanceof Node) {
$currentParamType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($param->type);
if ($this->typeComparator->areTypesEqual($currentParamType, $type)) {
return false;
}
return false;
}

$paramTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($type, TypeKind::PARAM);
Expand Down

0 comments on commit 19aff25

Please sign in to comment.