Skip to content

Commit

Permalink
[CodeQuality] Skip not from Symfony Response object on AssertSameResp…
Browse files Browse the repository at this point in the history
…onseCodeWithDebugContentsRector (#551)

* [CodeQuality] Skip not from Symfony Response object on AssertSameResponseCodeWithDebugContentsRector

* fix

* cs fix
  • Loading branch information
samsonasik authored Dec 26, 2023
1 parent 5f1e96d commit 1f44b34
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Rector\Symfony\Tests\CodeQuality\Rector\MethodCall\AssertSameResponseCodeWithDebugContentsRector\Fixture;

use PHPUnit\Framework\TestCase;

class SkipNotResponseObjectTest extends TestCase
{
public function test(object $obj)
{
$this->assertSame(200, $obj->getStatusCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand Down Expand Up @@ -124,6 +125,15 @@ private function matchResponseExpr(Expr $expr): ?Expr
return null;
}

$varType = $this->nodeTypeResolver->getType($expr->var);
if (! $varType instanceof ObjectType) {
return null;
}

if (! $varType->isInstanceof('Symfony\Component\HttpFoundation\Response')->yes()) {
return null;
}

// must be status method call
if (! $this->isName($expr->name, 'getStatusCode')) {
return null;
Expand Down

0 comments on commit 1f44b34

Please sign in to comment.