diff --git a/rules-tests/CodeQuality/Rector/MethodCall/AssertEmptyNullableObjectToAssertInstanceofRector/Fixture/keep_custom_message.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/AssertEmptyNullableObjectToAssertInstanceofRector/Fixture/keep_custom_message.php.inc new file mode 100644 index 00000000..faa74b0a --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/AssertEmptyNullableObjectToAssertInstanceofRector/Fixture/keep_custom_message.php.inc @@ -0,0 +1,37 @@ +assertNull($someObject, 'some message'); + } +} + +?> +----- +assertNotInstanceOf(\CodeQuality\Rector\MethodCall\AssertEmptyNullableObjectToAssertInstanceofRector\Source\SomeTypeObject::class, $someObject, 'some message'); + } +} + +?> diff --git a/rules/CodeQuality/Rector/MethodCall/AssertEmptyNullableObjectToAssertInstanceofRector.php b/rules/CodeQuality/Rector/MethodCall/AssertEmptyNullableObjectToAssertInstanceofRector.php index 1edefd41..de019754 100644 --- a/rules/CodeQuality/Rector/MethodCall/AssertEmptyNullableObjectToAssertInstanceofRector.php +++ b/rules/CodeQuality/Rector/MethodCall/AssertEmptyNullableObjectToAssertInstanceofRector.php @@ -47,7 +47,6 @@ public function test() } } CODE_SAMPLE - , <<<'CODE_SAMPLE' use PHPUnit\Framework\TestCase; @@ -99,7 +98,6 @@ public function refactor(Node $node): ?Node } $firstArgType = $this->getType($firstArg->value); - if (! $firstArgType instanceof UnionType) { return null; } @@ -118,9 +116,15 @@ public function refactor(Node $node): ?Node $fullyQualified = new FullyQualified($pureType->getClassName()); + $customMessageArg = $node->getArgs()[1] ?? null; + $node->args[0] = new Arg(new ClassConstFetch($fullyQualified, 'class')); $node->args[1] = $firstArg; + if ($customMessageArg instanceof Arg) { + $node->args[] = $customMessageArg; + } + return $node; } }