From 6ef02de15db3e9a4e1065820467ecc9d09187ade Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 21 May 2026 09:05:14 +0000 Subject: [PATCH] fix(AssertIsTypeMethodCallRector): guard against non-string arg crashing isset on enum case When `isType()` is called with an enum case argument, `ValueResolver::getValue()` returns an enum object. Using it as an array key in `isset()` caused a fatal error: "Cannot access offset of type SomeEnum in isset or empty". Add `is_string()` guard before the array lookup so non-string args are safely skipped. Fixes https://github.com/rectorphp/rector/issues/9765 --- .../Fixture/skip_non_string_arg.php.inc | 20 +++++++++++++++++++ .../Class_/AssertIsTypeMethodCallRector.php | 4 ++++ 2 files changed, 24 insertions(+) create mode 100644 rules-tests/PHPUnit120/Rector/Class_/AssertIsTypeMethodCallRector/Fixture/skip_non_string_arg.php.inc diff --git a/rules-tests/PHPUnit120/Rector/Class_/AssertIsTypeMethodCallRector/Fixture/skip_non_string_arg.php.inc b/rules-tests/PHPUnit120/Rector/Class_/AssertIsTypeMethodCallRector/Fixture/skip_non_string_arg.php.inc new file mode 100644 index 00000000..4a4ca308 --- /dev/null +++ b/rules-tests/PHPUnit120/Rector/Class_/AssertIsTypeMethodCallRector/Fixture/skip_non_string_arg.php.inc @@ -0,0 +1,20 @@ +assertThat([], $this->isType(SkipNonStringArgEnum::ONE)); + } +} diff --git a/rules/PHPUnit120/Rector/Class_/AssertIsTypeMethodCallRector.php b/rules/PHPUnit120/Rector/Class_/AssertIsTypeMethodCallRector.php index 7adca290..d9bd9f59 100644 --- a/rules/PHPUnit120/Rector/Class_/AssertIsTypeMethodCallRector.php +++ b/rules/PHPUnit120/Rector/Class_/AssertIsTypeMethodCallRector.php @@ -114,6 +114,10 @@ public function refactor(Node $node): Node|null } $argValue = $this->valueResolver->getValue($arg); + if (! is_string($argValue)) { + return null; + } + if (isset(self::IS_TYPE_VALUE_TO_METHOD[$argValue])) { if ($node instanceof MethodCall) { return new MethodCall($node->var, self::IS_TYPE_VALUE_TO_METHOD[$argValue]);