diff --git a/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockReturnArrayFromDirectArrayInstanceRector/Fixture/two_nested_levels.php.inc b/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockReturnArrayFromDirectArrayInstanceRector/Fixture/two_nested_levels.php.inc new file mode 100644 index 00000000000..5ad4b578ba7 --- /dev/null +++ b/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockReturnArrayFromDirectArrayInstanceRector/Fixture/two_nested_levels.php.inc @@ -0,0 +1,48 @@ + [ + 'id' => 1, + 'name' => '111', + ], + 'another_key' => [ + 'id' => 1, + 'name' => '111', + ], + ]; + } +} + +?> +----- +> + */ + public function run(): array + { + return [ + 'key' => [ + 'id' => 1, + 'name' => '111', + ], + 'another_key' => [ + 'id' => 1, + 'name' => '111', + ], + ]; + } +} + +?> diff --git a/rules/CodingStyle/Rector/Enum_/EnumCaseToPascalCaseRector.php b/rules/CodingStyle/Rector/Enum_/EnumCaseToPascalCaseRector.php index 2b6f80b520a..e3b48e80ded 100644 --- a/rules/CodingStyle/Rector/Enum_/EnumCaseToPascalCaseRector.php +++ b/rules/CodingStyle/Rector/Enum_/EnumCaseToPascalCaseRector.php @@ -195,6 +195,7 @@ private function isEnumCase(ClassReflection $classReflection, string $name, stri if ($classReflection->hasEnumCase($name)) { return true; } + return $classReflection->hasEnumCase($pascalName); } diff --git a/rules/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockReturnArrayFromDirectArrayInstanceRector.php b/rules/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockReturnArrayFromDirectArrayInstanceRector.php index 5230c2b6140..3d9ad973c4f 100644 --- a/rules/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockReturnArrayFromDirectArrayInstanceRector.php +++ b/rules/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockReturnArrayFromDirectArrayInstanceRector.php @@ -16,12 +16,15 @@ use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\FloatType; use PHPStan\Type\IntegerType; +use PHPStan\Type\IntersectionType; use PHPStan\Type\MixedType; use PHPStan\Type\NeverType; use PHPStan\Type\StringType; use PHPStan\Type\Type; +use PHPStan\Type\UnionType; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\Comments\NodeDocBlock\DocBlockUpdater; +use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory; use Rector\Rector\AbstractRector; use Rector\StaticTypeMapper\StaticTypeMapper; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -35,7 +38,8 @@ final class DocblockReturnArrayFromDirectArrayInstanceRector extends AbstractRec public function __construct( private readonly PhpDocInfoFactory $phpDocInfoFactory, private readonly DocBlockUpdater $docBlockUpdater, - private readonly StaticTypeMapper $staticTypeMapper + private readonly StaticTypeMapper $staticTypeMapper, + private readonly TypeFactory $typeFactory ) { } @@ -145,6 +149,20 @@ private function constantToGenericType(Type $type): Type return new FloatType(); } + if ($type instanceof UnionType || $type instanceof IntersectionType) { + $genericComplexTypes = []; + foreach ($type->getTypes() as $splitType) { + $genericComplexTypes[] = $this->constantToGenericType($splitType); + } + + $genericComplexTypes = $this->typeFactory->uniquateTypes($genericComplexTypes); + if (count($genericComplexTypes) > 1) { + return new UnionType($genericComplexTypes); + } + + return $genericComplexTypes[0]; + } + // unclear return new MixedType(); }