Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ComplexArray
{
return [
'id' => new \stdClass(),
'other' => false,
'context' => [
'id' => 1,
'data' => [
Expand All @@ -17,6 +18,11 @@ class ComplexArray
],
'values' => [
'name' => '111',
'age' => 1,
],
'values_other' => [
'name' => '111',
'age' => 1,
],
];
}
Expand All @@ -37,6 +43,7 @@ class ComplexArray
{
return [
'id' => new \stdClass(),
'other' => false,
'context' => [
'id' => 1,
'data' => [
Expand All @@ -46,6 +53,11 @@ class ComplexArray
],
'values' => [
'name' => '111',
'age' => 1,
],
'values_other' => [
'name' => '111',
'age' => 1,
],
];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\AddReturnDocblockDataProviderRector\Fixture;

use DateTime;
use DateTimeImmutable;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

final class MultiObjects extends TestCase
{
#[DataProvider('provideData')]
public function testSomething()
{
}

public static function provideData(): iterable
{
yield [[new DateTime(), 'format']];
yield [[new DateTimeImmutable(), 'format']];
}
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\AddReturnDocblockDataProviderRector\Fixture;

use DateTime;
use DateTimeImmutable;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

final class MultiObjects extends TestCase
{
#[DataProvider('provideData')]
public function testSomething()
{
}

/**
* @return \Iterator<array<int, array<int, (\DateTime | \DateTimeImmutable | string)>>>
*/
public static function provideData(): iterable
{
yield [[new DateTime(), 'format']];
yield [[new DateTimeImmutable(), 'format']];
}
}

?>
2 changes: 1 addition & 1 deletion rules/Privatization/TypeManipulator/TypeNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* @var int
*/
private const MAX_PRINTED_UNION_DOC_LENGHT = 60;
private const MAX_PRINTED_UNION_DOC_LENGHT = 77;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be tricky to keep in readable line. The longer the docblock will be, the more mess might get int. But let's give 77 a try.


public function __construct(
private TypeFactory $typeFactory,
Expand Down
10 changes: 10 additions & 0 deletions src/NodeTypeResolver/PHPStan/Type/TypeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ private function unwrapConstantArrayTypes(ConstantArrayType $constantArrayType):
$nestedFlattenKeyType = new MixedType();
}

if ($nestedFlattenItemType instanceof ConstantArrayType) {
$innerArrayTypes = $this->unwrapConstantArrayTypes($nestedFlattenItemType);
foreach ($innerArrayTypes as $innerArrayType) {
// preserve outer array -> inner array structure: array<outerKey, innerArray>
$unwrappedTypes[] = new ArrayType($nestedFlattenKeyType, $innerArrayType);
}

continue;
}
Comment on lines +208 to +216
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this loop again to make result of inner constant array to avoid just added the last one,


$unwrappedTypes[] = new ArrayType($nestedFlattenKeyType, $nestedFlattenItemType);
}

Expand Down
Loading