Skip to content

Commit 5eee71e

Browse files
authored
[CodeQuality] Skip first class callable on DecorateWillReturnMapWithExpectsMockRector (#654)
* [CodeQuality] Skip first class callable on DecorateWillReturnMapWithExpectsMockRector * Fix * Fix
1 parent a2e10b5 commit 5eee71e

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\Expression\DecorateWillReturnMapWithExpectsMockRector\Fixture;
6+
7+
final class SkipFirstClassCallable extends \PHPUnit\Framework\TestCase
8+
{
9+
public function test()
10+
{
11+
$someMock = $this->createMock(\stdClass::class);
12+
$someMock->method('some')->willReturnMap(...);
13+
}
14+
}
15+
16+
?>

rules/CodeQuality/Rector/Expression/DecorateWillReturnMapWithExpectsMockRector.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,16 @@ public function refactor(Node $node)
108108
return null;
109109
}
110110

111+
if ($methodCall->isFirstClassCallable()) {
112+
return null;
113+
}
114+
111115
// count values in will map arg
112-
$willReturnMapArg = $methodCall->getArgs()[0];
116+
$willReturnMapArg = $methodCall->getArgs()[0] ?? null;
117+
if (! $willReturnMapArg instanceof Arg) {
118+
return null;
119+
}
120+
113121
if (! $willReturnMapArg->value instanceof Array_) {
114122
return null;
115123
}

0 commit comments

Comments
 (0)