From a6978f5999b9276e7bdf6832a5395af6fcc9ace5 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 29 Jun 2026 16:25:16 +0200 Subject: [PATCH] [CodeQuality] Skip AssertIssetToSpecificMethodRector on ArrayAccess objects isset($obj[$key]) on an ArrayAccess object is not equivalent to assertArrayHasKey($key, $obj): the key may be any type (assertArrayHasKey() requires int|string) and offsetExists() semantics can differ from array_key_exists(). Converting it produced code that throws for non-scalar keys. Skip the rule when the subject is an ArrayAccess object. --- .../Fixture/skip_array_access_object.php.inc | 16 ++++++++++++ .../Source/SomeArrayAccessStore.php | 26 +++++++++++++++++++ .../AssertIssetToSpecificMethodRector.php | 8 ++++++ 3 files changed, 50 insertions(+) create mode 100644 rules-tests/CodeQuality/Rector/MethodCall/AssertIssetToSpecificMethodRector/Fixture/skip_array_access_object.php.inc create mode 100644 rules-tests/CodeQuality/Rector/MethodCall/AssertIssetToSpecificMethodRector/Source/SomeArrayAccessStore.php diff --git a/rules-tests/CodeQuality/Rector/MethodCall/AssertIssetToSpecificMethodRector/Fixture/skip_array_access_object.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/AssertIssetToSpecificMethodRector/Fixture/skip_array_access_object.php.inc new file mode 100644 index 000000000..d32905361 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/AssertIssetToSpecificMethodRector/Fixture/skip_array_access_object.php.inc @@ -0,0 +1,16 @@ +assertTrue(isset($store[$key]), 'message'); + $this->assertFalse(isset($store[$key])); + } +} diff --git a/rules-tests/CodeQuality/Rector/MethodCall/AssertIssetToSpecificMethodRector/Source/SomeArrayAccessStore.php b/rules-tests/CodeQuality/Rector/MethodCall/AssertIssetToSpecificMethodRector/Source/SomeArrayAccessStore.php new file mode 100644 index 000000000..3ddd050b9 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/AssertIssetToSpecificMethodRector/Source/SomeArrayAccessStore.php @@ -0,0 +1,26 @@ +isObjectType($issetExpr->var, new ObjectType('ArrayAccess'))) { + return null; + } + return $this->refactorArrayDimFetchNode($node, $issetExpr); }