From 0414d6b2db2437a725a4178463638890ce26d6e8 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 27 Sep 2025 16:18:33 +0700 Subject: [PATCH 1/2] [NodeTypeResolver] Apply logic Mixed inside Union check on TypeFactory::createUnionOrSingleType() --- rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php | 6 ------ src/NodeTypeResolver/PHPStan/Type/TypeFactory.php | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php b/rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php index cc19d5298b6..7da5166967a 100644 --- a/rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php +++ b/rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php @@ -129,12 +129,6 @@ private function unionToSingleType(array $staticTypesByArgumentPosition, bool $r if ($staticTypeByArgumentPosition[$position] instanceof UnionType) { foreach ($staticTypeByArgumentPosition[$position]->getTypes() as $subType) { - // has another type over mixed is not allowed, even on native type - if ($subType instanceof MixedType) { - $staticTypeByArgumentPosition[$position] = new MixedType(); - continue 2; - } - if ($removeMixedArray && $subType instanceof ArrayType && $this->isArrayMixedMixedType($subType)) { $staticTypeByArgumentPosition[$position] = new MixedType(); continue 2; diff --git a/src/NodeTypeResolver/PHPStan/Type/TypeFactory.php b/src/NodeTypeResolver/PHPStan/Type/TypeFactory.php index 95fc0bb3598..6f12a85490d 100644 --- a/src/NodeTypeResolver/PHPStan/Type/TypeFactory.php +++ b/src/NodeTypeResolver/PHPStan/Type/TypeFactory.php @@ -168,6 +168,12 @@ private function createUnionOrSingleType(array $types): Type return $types[0]; } + foreach ($types as $type) { + if ($type instanceof MixedType) { + return new MixedType(); + } + } + return new UnionType($types); } From b6cead2c09b74194d811c658ce8f2e21f96c34dc Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 27 Sep 2025 16:19:56 +0700 Subject: [PATCH 2/2] [NodeTypeResolver] Apply logic Mixed inside Union check on TypeFactory::createUnionOrSingleType() --- rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php b/rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php index 7da5166967a..2c5f1d7334d 100644 --- a/rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php +++ b/rules/TypeDeclaration/NodeAnalyzer/CallTypesResolver.php @@ -127,9 +127,9 @@ private function unionToSingleType(array $staticTypesByArgumentPosition, bool $r $unionedType ); - if ($staticTypeByArgumentPosition[$position] instanceof UnionType) { + if ($removeMixedArray && $staticTypeByArgumentPosition[$position] instanceof UnionType) { foreach ($staticTypeByArgumentPosition[$position]->getTypes() as $subType) { - if ($removeMixedArray && $subType instanceof ArrayType && $this->isArrayMixedMixedType($subType)) { + if ($subType instanceof ArrayType && $this->isArrayMixedMixedType($subType)) { $staticTypeByArgumentPosition[$position] = new MixedType(); continue 2; }