From e16c1d58032fe356ecfb444458c730600b6694db Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 21 Nov 2024 04:38:30 +0700 Subject: [PATCH] [CodeQuality] Handle crash on return array constant on ExplicitReturnNullRector (#6458) * [CodeQuality] Handle crash on return array constant on ExplicitReturnNullRector * fix --- .../Fixture/array_constant.php.inc | 14 ++++++++++++++ rules/TypeDeclaration/TypeNormalizer.php | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 rules-tests/CodeQuality/Rector/ClassMethod/ExplicitReturnNullRector/Fixture/array_constant.php.inc diff --git a/rules-tests/CodeQuality/Rector/ClassMethod/ExplicitReturnNullRector/Fixture/array_constant.php.inc b/rules-tests/CodeQuality/Rector/ClassMethod/ExplicitReturnNullRector/Fixture/array_constant.php.inc new file mode 100644 index 00000000000..403e66450a4 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/ClassMethod/ExplicitReturnNullRector/Fixture/array_constant.php.inc @@ -0,0 +1,14 @@ + ['foo' => 'fooValue']]], + [null, []], + ]; + } +} diff --git a/rules/TypeDeclaration/TypeNormalizer.php b/rules/TypeDeclaration/TypeNormalizer.php index 8ae2b22f2ec..4b5acdece85 100644 --- a/rules/TypeDeclaration/TypeNormalizer.php +++ b/rules/TypeDeclaration/TypeNormalizer.php @@ -84,9 +84,9 @@ public function normalizeArrayTypeAndArrayNever(Type $type): Type assert($traversedType instanceof ConstantArrayType); // not sure why, but with direct new node everything gets nulled to MixedType - $this->privatesAccessor->setPrivateProperty($traversedType, 'keyType', new MixedType()); + $this->privatesAccessor->setPrivateProperty($traversedType, 'keyTypes', [new MixedType()]); - $this->privatesAccessor->setPrivateProperty($traversedType, 'itemType', new MixedType()); + $this->privatesAccessor->setPrivateProperty($traversedType, 'valueTypes', [new MixedType()]); return $traversedType; }