Skip to content

Commit 1e091dc

Browse files
committed
[CodeQuality] Skip already has return type on TypeWillReturnCallableArrowFunctionRector
1 parent a5fc689 commit 1e091dc

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\Class_\TypeWillReturnCallableArrowFunctionRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Rector\PHPUnit\Tests\CodeQuality\Rector\Class_\TypeWillReturnCallableArrowFunctionRector\Source\SomeMockedClass;
7+
8+
final class SkipAlreadyReturnTyped extends TestCase
9+
{
10+
public function test($value): void
11+
{
12+
$this->createMock(SomeMockedClass::class)
13+
->method('nativeObject')
14+
->willReturnCallback(fn (object $object): \stdClass => $value);
15+
}
16+
}
17+
18+
?>

rules/CodeQuality/Rector/Class_/TypeWillReturnCallableArrowFunctionRector.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,16 @@ public function refactor(Node $node): ?Class_
239239
$hasChanged = true;
240240
}
241241

242-
$returnTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode(
243-
$parameterTypesAndReturnType->getReturnType(),
244-
TypeKind::RETURN
245-
);
242+
if (! $innerArg->returnType instanceof Node) {
243+
$returnTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode(
244+
$parameterTypesAndReturnType->getReturnType(),
245+
TypeKind::RETURN
246+
);
246247

247-
if ($returnTypeNode instanceof Node) {
248-
$innerArg->returnType = $returnTypeNode;
249-
$hasChanged = true;
248+
if ($returnTypeNode instanceof Node) {
249+
$innerArg->returnType = $returnTypeNode;
250+
$hasChanged = true;
251+
}
250252
}
251253
});
252254

0 commit comments

Comments
 (0)