diff --git a/config/set/php73.php b/config/set/php73.php index b3a699be7c2e..3f46395efbd3 100644 --- a/config/set/php73.php +++ b/config/set/php73.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use Rector\Php52\Rector\Switch_\ContinueToBreakInSwitchRector; use Rector\Php73\Rector\BooleanOr\IsCountableRector; use Rector\Php73\Rector\ConstFetch\SensitiveConstantNameRector; use Rector\Php73\Rector\FuncCall\ArrayKeyFirstLastRector; @@ -46,4 +47,5 @@ $services->set(StringifyStrNeedlesRector::class); $services->set(JsonThrowOnErrorRector::class); $services->set(RegexDashEscapeRector::class); + $services->set(ContinueToBreakInSwitchRector::class); }; diff --git a/packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Php74Test.php b/packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Php74Test.php index d8491359b11c..e2d9f14c36de 100644 --- a/packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Php74Test.php +++ b/packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Php74Test.php @@ -22,6 +22,9 @@ public function test(SmartFileInfo $smartFileInfo): void $this->doTestFileInfo($smartFileInfo); } + /** + * @return Iterator + */ public function provideData(): Iterator { return StaticFixtureFinder::yieldDirectoryExclusively(__DIR__ . '/FixturePhp74'); diff --git a/packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Php80Test.php b/packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Php80Test.php index 42825eb0c85a..e3d3f5f1d290 100644 --- a/packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Php80Test.php +++ b/packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Php80Test.php @@ -22,6 +22,9 @@ public function test(SmartFileInfo $smartFileInfo): void $this->doTestFileInfo($smartFileInfo); } + /** + * @return Iterator + */ public function provideData(): Iterator { return StaticFixtureFinder::yieldDirectoryExclusively(__DIR__ . '/FixturePhp80'); diff --git a/packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/PropertyFetchTypeResolverTest.php b/packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/PropertyFetchTypeResolverTest.php index c9eaddd4fc90..fcb288aa2751 100644 --- a/packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/PropertyFetchTypeResolverTest.php +++ b/packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/PropertyFetchTypeResolverTest.php @@ -18,6 +18,9 @@ public function test(SmartFileInfo $smartFileInfo): void $this->doTestFileInfo($smartFileInfo); } + /** + * @return Iterator + */ public function provideData(): Iterator { return StaticFixtureFinder::yieldDirectoryExclusively(__DIR__ . '/Fixture'); diff --git a/rules/type-declaration/src/Rector/ClassMethod/AddArrayReturnDocTypeRector.php b/rules/type-declaration/src/Rector/ClassMethod/AddArrayReturnDocTypeRector.php index 5d7eec20b0d5..9f76e8535fa0 100644 --- a/rules/type-declaration/src/Rector/ClassMethod/AddArrayReturnDocTypeRector.php +++ b/rules/type-declaration/src/Rector/ClassMethod/AddArrayReturnDocTypeRector.php @@ -10,6 +10,7 @@ use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode; use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode; use PHPStan\Type\ArrayType; +use PHPStan\Type\Generic\GenericObjectType; use PHPStan\Type\IterableType; use PHPStan\Type\MixedType; use PHPStan\Type\Type; @@ -176,6 +177,13 @@ public function refactor(Node $node): ?Node return null; } + if ($inferredReturnType instanceof GenericObjectType && $currentReturnType instanceof MixedType) { + $types = $inferredReturnType->getTypes(); + if ($types[0] instanceof MixedType && $types[1] instanceof ArrayType) { + return null; + } + } + $this->phpDocTypeChanger->changeReturnType($phpDocInfo, $inferredReturnType); $this->returnTagRemover->removeReturnTagIfUseless($phpDocInfo, $node); diff --git a/rules/type-declaration/tests/Rector/ClassMethod/AddArrayReturnDocTypeRector/Fixture/skip_some_iterator.php.inc b/rules/type-declaration/tests/Rector/ClassMethod/AddArrayReturnDocTypeRector/Fixture/skip_some_iterator.php.inc new file mode 100644 index 000000000000..cdf70a2b770f --- /dev/null +++ b/rules/type-declaration/tests/Rector/ClassMethod/AddArrayReturnDocTypeRector/Fixture/skip_some_iterator.php.inc @@ -0,0 +1,24 @@ +> + */ + public static function someIterator(): Iterator + { + yield [100 => new SmartFileInfo('...')]; + } +} + +?> diff --git a/rules/type-declaration/tests/Rector/ClassMethod/AddArrayReturnDocTypeRector/Fixture/some_iterator.php.inc b/rules/type-declaration/tests/Rector/ClassMethod/AddArrayReturnDocTypeRector/Fixture/some_iterator.php.inc deleted file mode 100644 index 6ba249d7b83e..000000000000 --- a/rules/type-declaration/tests/Rector/ClassMethod/AddArrayReturnDocTypeRector/Fixture/some_iterator.php.inc +++ /dev/null @@ -1,52 +0,0 @@ -> - */ - public static function someIterator(): Iterator - { - yield [100 => new SmartFileInfo('...')]; - } -} - -?> ------ - - */ - public function someMethod(): Iterator - { - return self::someIterator(); - } - - /** - * @return \Iterator> - */ - public static function someIterator(): Iterator - { - yield [100 => new SmartFileInfo('...')]; - } -} - -?>