diff --git a/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Fixture/add_instance_only_once.php.inc b/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Fixture/add_instance_only_once.php.inc index 7922a205..74423e42 100644 --- a/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Fixture/add_instance_only_once.php.inc +++ b/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Fixture/add_instance_only_once.php.inc @@ -46,7 +46,7 @@ final class AddInstanceOnlyOnce extends TestCase public function test(): void { $someObject = $this->getSomeObject(); - $this->assertInstanceof(\Rector\PHPUnit\Tests\CodeQuality\Rector\ClassMethod\AddInstanceofAssertForNullableInstanceRector\Source\SomeClassUsedInTests::class, $someObject); + $this->assertInstanceOf(\Rector\PHPUnit\Tests\CodeQuality\Rector\ClassMethod\AddInstanceofAssertForNullableInstanceRector\Source\SomeClassUsedInTests::class, $someObject); $value = $someObject->getSomeMethod(); $this->assertSame(123, $value); diff --git a/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Fixture/call_on_nullable.php.inc b/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Fixture/call_on_nullable.php.inc index 487bb889..b8eaa3a7 100644 --- a/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Fixture/call_on_nullable.php.inc +++ b/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Fixture/call_on_nullable.php.inc @@ -43,7 +43,7 @@ final class CallOnNullable extends TestCase public function test(): void { $someObject = $this->getSomeObject(); - $this->assertInstanceof(\Rector\PHPUnit\Tests\CodeQuality\Rector\ClassMethod\AddInstanceofAssertForNullableInstanceRector\Source\SomeClassUsedInTests::class, $someObject); + $this->assertInstanceOf(\Rector\PHPUnit\Tests\CodeQuality\Rector\ClassMethod\AddInstanceofAssertForNullableInstanceRector\Source\SomeClassUsedInTests::class, $someObject); $value = $someObject->getSomeMethod(); $this->assertSame(123, $value); diff --git a/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Fixture/multiple_assert.php.inc b/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Fixture/multiple_assert.php.inc index ae339bc6..12fecfa5 100644 --- a/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Fixture/multiple_assert.php.inc +++ b/rules-tests/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector/Fixture/multiple_assert.php.inc @@ -57,13 +57,13 @@ final class MultipleAssert extends TestCase public function test(): void { $someObject = $this->getSomeObject(); - $this->assertInstanceof(\Rector\PHPUnit\Tests\CodeQuality\Rector\ClassMethod\AddInstanceofAssertForNullableInstanceRector\Source\SomeClassUsedInTests::class, $someObject); + $this->assertInstanceOf(\Rector\PHPUnit\Tests\CodeQuality\Rector\ClassMethod\AddInstanceofAssertForNullableInstanceRector\Source\SomeClassUsedInTests::class, $someObject); $value = $someObject->getSomeMethod(); $this->assertSame(123, $value); $someObject2 = $this->getSomeObject2(); - $this->assertInstanceof(\Rector\PHPUnit\Tests\CodeQuality\Rector\ClassMethod\AddInstanceofAssertForNullableInstanceRector\Source\SomeClassUsedInTests::class, $someObject2); + $this->assertInstanceOf(\Rector\PHPUnit\Tests\CodeQuality\Rector\ClassMethod\AddInstanceofAssertForNullableInstanceRector\Source\SomeClassUsedInTests::class, $someObject2); $value2 = $someObject2->getSomeMethod(); $this->assertSame(123, $value2); diff --git a/rules/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector.php b/rules/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector.php index 812a7166..b7704f2e 100644 --- a/rules/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector.php +++ b/rules/CodeQuality/Rector/ClassMethod/AddInstanceofAssertForNullableInstanceRector.php @@ -74,7 +74,7 @@ final class SomeTest extends TestCase public function test() { $someObject = $this->getSomeObject(); - $this->assertInstanceof(SomeClass::class, $someObject); + $this->assertInstanceOf(SomeClass::class, $someObject); $value = $someObject->getSomeMethod(); } @@ -130,8 +130,8 @@ public function refactor(Node $node): ?Node } // adding type here + popping the variable name out - $assertInstanceofExpression = $this->createAssertInstanceof($matchedNullableVariableNameToType); - array_splice($node->stmts, $key + $next, 0, [$assertInstanceofExpression]); + $assertInstanceOfExpression = $this->createAssertInstanceOf($matchedNullableVariableNameToType); + array_splice($node->stmts, $key + $next, 0, [$assertInstanceOfExpression]); // remove variable name from nullable ones $hasChanged = true; @@ -162,14 +162,14 @@ private function isNullableType(Type $type): bool return count($type->getTypes()) === 2; } - private function createAssertInstanceof(VariableNameToType $variableNameToType): Expression + private function createAssertInstanceOf(VariableNameToType $variableNameToType): Expression { $args = [ new Arg(new ClassConstFetch(new FullyQualified($variableNameToType->getObjectType()), 'class')), new Arg(new Variable($variableNameToType->getVariableName())), ]; - $methodCall = new MethodCall(new Variable('this'), 'assertInstanceof', $args); + $methodCall = new MethodCall(new Variable('this'), 'assertInstanceOf', $args); return new Expression($methodCall); }