From 55aff579dd7b7f765f198b360c6c894f1b3414e3 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 19 Aug 2025 17:56:30 +0700 Subject: [PATCH] [CodeQuality] Skip first class callable and argument less on MatchAssertSameExpectedTypeRector --- .../Fixture/skip_argument_less.php.inc | 13 +++++++++++++ .../Fixture/skip_first_class_callable.php.inc | 13 +++++++++++++ .../MatchAssertSameExpectedTypeRector.php | 8 ++++++++ 3 files changed, 34 insertions(+) create mode 100644 rules-tests/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector/Fixture/skip_argument_less.php.inc create mode 100644 rules-tests/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector/Fixture/skip_first_class_callable.php.inc diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector/Fixture/skip_argument_less.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector/Fixture/skip_argument_less.php.inc new file mode 100644 index 00000000..1bbaceb1 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector/Fixture/skip_argument_less.php.inc @@ -0,0 +1,13 @@ +assertSame(1); + } +} diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector/Fixture/skip_first_class_callable.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector/Fixture/skip_first_class_callable.php.inc new file mode 100644 index 00000000..879c370f --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector/Fixture/skip_first_class_callable.php.inc @@ -0,0 +1,13 @@ +assertSame(...); + } +} diff --git a/rules/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector.php b/rules/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector.php index 24f0dee1..4068f152 100644 --- a/rules/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector.php +++ b/rules/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector.php @@ -86,6 +86,14 @@ public function refactor(Node $node): ?Node return null; } + if ($node->isFirstClassCallable()) { + return null; + } + + if (count($node->getArgs()) < 2) { + return null; + } + $expectedArg = $node->getArgs()[0]; if (! $expectedArg->value instanceof String_ && ! $expectedArg->value instanceof LNumber) { return null;