From bebec458da5ade2c395277d28a8963c5039e7731 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 25 Dec 2024 18:09:24 +0700 Subject: [PATCH 1/2] [CodeQuality] Skip compare string to Stringable object on AssertEqualsToSameRector --- .../Fixture/skip_stringable_object.php.inc | 14 ++++++++++++++ .../Source/SimpleStringable.php | 13 +++++++++++++ .../Rector/MethodCall/AssertEqualsToSameRector.php | 10 +++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Fixture/skip_stringable_object.php.inc create mode 100644 rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Source/SimpleStringable.php diff --git a/rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Fixture/skip_stringable_object.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Fixture/skip_stringable_object.php.inc new file mode 100644 index 00000000..e1ef88cb --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Fixture/skip_stringable_object.php.inc @@ -0,0 +1,14 @@ +assertEquals('value', new SimpleStringable()); + } +} diff --git a/rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Source/SimpleStringable.php b/rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Source/SimpleStringable.php new file mode 100644 index 00000000..a7b37610 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Source/SimpleStringable.php @@ -0,0 +1,13 @@ +isObjectType( + $node->args[1]->value, + new ObjectType('Stringable') + )) { + return null; + } } $hasChanged = $this->identifierManipulator->renameNodeWithMap($node, self::RENAME_METHODS_MAP); From f14e0152a5fc9c39bab71ff47714076576d7ca84 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 25 Dec 2024 18:11:06 +0700 Subject: [PATCH 2/2] [CodeQuality] Skip compare string to Stringable object on AssertEqualsToSameRector --- .../CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php b/rules/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php index 1aa44b48..921271a2 100644 --- a/rules/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php +++ b/rules/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php @@ -116,7 +116,7 @@ public function refactor(Node $node): ?Node } if ($firstArgType instanceof StringType && $secondArgType instanceof ObjectType && $this->isObjectType( - $node->args[1]->value, + $args[1]->value, new ObjectType('Stringable') )) { return null;