Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Rector\Tests\Unambiguous\Rector\Expression\FluentSettersToStandaloneCallMethodRector\Fixture;

use PHPUnit\Framework\TestCase;
use Rector\Tests\Unambiguous\Rector\Expression\FluentSettersToStandaloneCallMethodRector\Source\SomeSetterClass;

final class SkipMocks extends TestCase
{
public function test()
{
$this->createMock(SomeSetterClass::class)
->expects($this->once())
->method('some');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Rector\Tests\Unambiguous\Rector\Expression\FluentSettersToStandaloneCallMethodRector\Source;

final class SomeSetterClass
class SomeSetterClass
{
private ?string $name = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Unambiguous\Rector\Expression;

use PHPStan\Type\ObjectType;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
Expand All @@ -13,6 +14,7 @@
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Return_;
use PHPStan\Reflection\ClassReflection;
use Rector\Naming\Naming\PropertyNaming;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Rector\AbstractRector;
Expand Down Expand Up @@ -107,6 +109,10 @@ public function refactor(Node $node): ?array

$rootExpr = $currentMethodCall;

if ($this->shouldSkipForVendorOrInternal($firstMethodCall)) {
return null;
}

$variableName = $this->resolveVariableName($rootExpr);
$someVariable = new Variable($variableName);

Expand Down Expand Up @@ -137,4 +143,22 @@ private function resolveVariableName(Expr $expr): string

return 'someVariable';
}

private function shouldSkipForVendorOrInternal(MethodCall $firstMethodCall): bool
{
$callerType = $this->getType($firstMethodCall);
if ($callerType instanceof ObjectType) {
$classReflection = $callerType->getClassReflection();
if (! $classReflection instanceof ClassReflection) {
return false;
}

$fileName = $classReflection->getFileName();
if ($fileName === null || str_contains($fileName, 'vendor')) {
return true;
}
}

return false;
}
}
Loading