diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddArrayReturnDocTypeRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddArrayReturnDocTypeRector.php index 1855e494f13..ed5d8a05ab1 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddArrayReturnDocTypeRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddArrayReturnDocTypeRector.php @@ -24,6 +24,7 @@ use Rector\Privatization\TypeManipulator\NormalizeTypeToRespectArrayScalarType; use Rector\Privatization\TypeManipulator\TypeNormalizer; use Rector\TypeDeclaration\NodeTypeAnalyzer\DetailedTypeAnalyzer; use Rector\TypeDeclaration\TypeAnalyzer\AdvancedArrayAnalyzer; +use Rector\TypeDeclaration\TypeAnalyzer\IterableTypeAnalyzer; use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer; use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer\ReturnTypeDeclarationReturnTypeInfererTypeInferer; use Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard; @@ -74,7 +75,12 @@ final class AddArrayReturnDocTypeRector extends \Rector\Core\Rector\AbstractRect * @var \Rector\Privatization\TypeManipulator\TypeNormalizer */ private $typeNormalizer; - public function __construct(\Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer $returnTypeInferer, \Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard $classMethodReturnTypeOverrideGuard, \Rector\TypeDeclaration\TypeAnalyzer\AdvancedArrayAnalyzer $advancedArrayAnalyzer, \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger $phpDocTypeChanger, \Rector\Privatization\TypeManipulator\NormalizeTypeToRespectArrayScalarType $normalizeTypeToRespectArrayScalarType, \Rector\DeadCode\PhpDoc\TagRemover\ReturnTagRemover $returnTagRemover, \Rector\TypeDeclaration\NodeTypeAnalyzer\DetailedTypeAnalyzer $detailedTypeAnalyzer, \Rector\Privatization\TypeManipulator\TypeNormalizer $typeNormalizer) + /** + * @readonly + * @var \Rector\TypeDeclaration\TypeAnalyzer\IterableTypeAnalyzer + */ + private $iterableTypeAnalyzer; + public function __construct(\Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer $returnTypeInferer, \Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard $classMethodReturnTypeOverrideGuard, \Rector\TypeDeclaration\TypeAnalyzer\AdvancedArrayAnalyzer $advancedArrayAnalyzer, \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger $phpDocTypeChanger, \Rector\Privatization\TypeManipulator\NormalizeTypeToRespectArrayScalarType $normalizeTypeToRespectArrayScalarType, \Rector\DeadCode\PhpDoc\TagRemover\ReturnTagRemover $returnTagRemover, \Rector\TypeDeclaration\NodeTypeAnalyzer\DetailedTypeAnalyzer $detailedTypeAnalyzer, \Rector\Privatization\TypeManipulator\TypeNormalizer $typeNormalizer, \Rector\TypeDeclaration\TypeAnalyzer\IterableTypeAnalyzer $iterableTypeAnalyzer) { $this->returnTypeInferer = $returnTypeInferer; $this->classMethodReturnTypeOverrideGuard = $classMethodReturnTypeOverrideGuard; @@ -84,6 +90,7 @@ final class AddArrayReturnDocTypeRector extends \Rector\Core\Rector\AbstractRect $this->returnTagRemover = $returnTagRemover; $this->detailedTypeAnalyzer = $detailedTypeAnalyzer; $this->typeNormalizer = $typeNormalizer; + $this->iterableTypeAnalyzer = $iterableTypeAnalyzer; } public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition { @@ -177,6 +184,9 @@ CODE_SAMPLE } private function shouldSkipType(\PHPStan\Type\Type $newType, \PHPStan\Type\Type $currentType, \PhpParser\Node\Stmt\ClassMethod $classMethod, \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo $phpDocInfo) : bool { + if (!$this->iterableTypeAnalyzer->isIterableType($newType)) { + return \true; + } if ($newType instanceof \PHPStan\Type\ArrayType && $this->shouldSkipArrayType($newType, $classMethod, $phpDocInfo)) { return \true; } diff --git a/rules/TypeDeclaration/TypeAnalyzer/IterableTypeAnalyzer.php b/rules/TypeDeclaration/TypeAnalyzer/IterableTypeAnalyzer.php new file mode 100644 index 00000000000..54aed47f311 --- /dev/null +++ b/rules/TypeDeclaration/TypeAnalyzer/IterableTypeAnalyzer.php @@ -0,0 +1,62 @@ +reflectionProvider = $reflectionProvider; + } + public function isIterableType(\PHPStan\Type\Type $type) : bool + { + if ($this->isUnionOfIterableTypes($type)) { + return \true; + } + if ($type instanceof \PHPStan\Type\ArrayType) { + return \true; + } + if ($type instanceof \PHPStan\Type\IterableType) { + return \true; + } + if ($type instanceof \PHPStan\Type\Generic\GenericObjectType) { + if (!$this->reflectionProvider->hasClass($type->getClassName())) { + return \false; + } + $genericObjectTypeClassReflection = $this->reflectionProvider->getClass($type->getClassName()); + if ($genericObjectTypeClassReflection->implementsInterface('Traversable')) { + return \true; + } + } + return \false; + } + private function isUnionOfIterableTypes(\PHPStan\Type\Type $type) : bool + { + if (!$type instanceof \PHPStan\Type\UnionType) { + return \false; + } + foreach ($type->getTypes() as $unionedType) { + // nullable union is allowed + if ($unionedType instanceof \PHPStan\Type\NullType) { + continue; + } + if (!$this->isIterableType($unionedType)) { + return \false; + } + } + return \true; + } +} diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index b1f0150889c..6f3bc22ea60 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -16,11 +16,11 @@ final class VersionResolver /** * @var string */ - public const PACKAGE_VERSION = '840bd5e3e6af1fd5474ec8717c75c6b5400e1737'; + public const PACKAGE_VERSION = '49f1596404278c63a37841eb720aabf97601311e'; /** * @var string */ - public const RELEASE_DATE = '2022-01-05 12:23:16'; + public const RELEASE_DATE = '2022-01-05 12:45:14'; public static function resolvePackageVersion() : string { $process = new \RectorPrefix20220105\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__); diff --git a/src/functions/node_helper.php b/src/functions/node_helper.php index e6e59004ca5..2bb08b7aced 100644 --- a/src/functions/node_helper.php +++ b/src/functions/node_helper.php @@ -6,6 +6,15 @@ namespace RectorPrefix20220105; use PhpParser\Node; use PhpParser\PrettyPrinter\Standard; use RectorPrefix20220105\Tracy\Dumper; +if (!\function_exists('dump_with_depth')) { + /** + * @param mixed $value + */ + function dump_with_depth($value, int $depth = 2) : void + { + \RectorPrefix20220105\Tracy\Dumper::dump($value, [\RectorPrefix20220105\Tracy\Dumper::DEPTH => $depth]); + } +} if (!\function_exists('dn')) { function dn(\PhpParser\Node $node, int $depth = 2) : void { diff --git a/vendor/autoload.php b/vendor/autoload.php index 775efb6d9e0..29248b3f5c2 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit4786b9bf3ccba2bd289627c76c84f87f::getLoader(); +return ComposerAutoloaderInitd2c47e9b1c523de03caede4ae2ea2722::getLoader(); diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 14209e5073e..cdb2aa59efd 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -3105,6 +3105,7 @@ return array( 'Rector\\TypeDeclaration\\TypeAlreadyAddedChecker\\ReturnTypeAlreadyAddedChecker' => $baseDir . '/rules/TypeDeclaration/TypeAlreadyAddedChecker/ReturnTypeAlreadyAddedChecker.php', 'Rector\\TypeDeclaration\\TypeAnalyzer\\AdvancedArrayAnalyzer' => $baseDir . '/rules/TypeDeclaration/TypeAnalyzer/AdvancedArrayAnalyzer.php', 'Rector\\TypeDeclaration\\TypeAnalyzer\\GenericClassStringTypeNormalizer' => $baseDir . '/rules/TypeDeclaration/TypeAnalyzer/GenericClassStringTypeNormalizer.php', + 'Rector\\TypeDeclaration\\TypeAnalyzer\\IterableTypeAnalyzer' => $baseDir . '/rules/TypeDeclaration/TypeAnalyzer/IterableTypeAnalyzer.php', 'Rector\\TypeDeclaration\\TypeAnalyzer\\ObjectTypeComparator' => $baseDir . '/rules/TypeDeclaration/TypeAnalyzer/ObjectTypeComparator.php', 'Rector\\TypeDeclaration\\TypeInferer\\AssignToPropertyTypeInferer' => $baseDir . '/rules/TypeDeclaration/TypeInferer/AssignToPropertyTypeInferer.php', 'Rector\\TypeDeclaration\\TypeInferer\\ParamTypeInferer' => $baseDir . '/rules/TypeDeclaration/TypeInferer/ParamTypeInferer.php', diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index b0f5b38cace..69aa5664f2c 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit4786b9bf3ccba2bd289627c76c84f87f +class ComposerAutoloaderInitd2c47e9b1c523de03caede4ae2ea2722 { private static $loader; @@ -22,15 +22,15 @@ class ComposerAutoloaderInit4786b9bf3ccba2bd289627c76c84f87f return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit4786b9bf3ccba2bd289627c76c84f87f', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInitd2c47e9b1c523de03caede4ae2ea2722', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__))); - spl_autoload_unregister(array('ComposerAutoloaderInit4786b9bf3ccba2bd289627c76c84f87f', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInitd2c47e9b1c523de03caede4ae2ea2722', 'loadClassLoader')); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); if ($useStaticLoader) { require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit4786b9bf3ccba2bd289627c76c84f87f::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInitd2c47e9b1c523de03caede4ae2ea2722::getInitializer($loader)); } else { $classMap = require __DIR__ . '/autoload_classmap.php'; if ($classMap) { @@ -42,12 +42,12 @@ class ComposerAutoloaderInit4786b9bf3ccba2bd289627c76c84f87f $loader->register(true); if ($useStaticLoader) { - $includeFiles = Composer\Autoload\ComposerStaticInit4786b9bf3ccba2bd289627c76c84f87f::$files; + $includeFiles = Composer\Autoload\ComposerStaticInitd2c47e9b1c523de03caede4ae2ea2722::$files; } else { $includeFiles = require __DIR__ . '/autoload_files.php'; } foreach ($includeFiles as $fileIdentifier => $file) { - composerRequire4786b9bf3ccba2bd289627c76c84f87f($fileIdentifier, $file); + composerRequired2c47e9b1c523de03caede4ae2ea2722($fileIdentifier, $file); } return $loader; @@ -59,7 +59,7 @@ class ComposerAutoloaderInit4786b9bf3ccba2bd289627c76c84f87f * @param string $file * @return void */ -function composerRequire4786b9bf3ccba2bd289627c76c84f87f($fileIdentifier, $file) +function composerRequired2c47e9b1c523de03caede4ae2ea2722($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 4e83142473d..0fc3509d7c0 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit4786b9bf3ccba2bd289627c76c84f87f +class ComposerStaticInitd2c47e9b1c523de03caede4ae2ea2722 { public static $files = array ( '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php', @@ -3500,6 +3500,7 @@ class ComposerStaticInit4786b9bf3ccba2bd289627c76c84f87f 'Rector\\TypeDeclaration\\TypeAlreadyAddedChecker\\ReturnTypeAlreadyAddedChecker' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeAlreadyAddedChecker/ReturnTypeAlreadyAddedChecker.php', 'Rector\\TypeDeclaration\\TypeAnalyzer\\AdvancedArrayAnalyzer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeAnalyzer/AdvancedArrayAnalyzer.php', 'Rector\\TypeDeclaration\\TypeAnalyzer\\GenericClassStringTypeNormalizer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeAnalyzer/GenericClassStringTypeNormalizer.php', + 'Rector\\TypeDeclaration\\TypeAnalyzer\\IterableTypeAnalyzer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeAnalyzer/IterableTypeAnalyzer.php', 'Rector\\TypeDeclaration\\TypeAnalyzer\\ObjectTypeComparator' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeAnalyzer/ObjectTypeComparator.php', 'Rector\\TypeDeclaration\\TypeInferer\\AssignToPropertyTypeInferer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeInferer/AssignToPropertyTypeInferer.php', 'Rector\\TypeDeclaration\\TypeInferer\\ParamTypeInferer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeInferer/ParamTypeInferer.php', @@ -3850,9 +3851,9 @@ class ComposerStaticInit4786b9bf3ccba2bd289627c76c84f87f public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit4786b9bf3ccba2bd289627c76c84f87f::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit4786b9bf3ccba2bd289627c76c84f87f::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit4786b9bf3ccba2bd289627c76c84f87f::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInitd2c47e9b1c523de03caede4ae2ea2722::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInitd2c47e9b1c523de03caede4ae2ea2722::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInitd2c47e9b1c523de03caede4ae2ea2722::$classMap; }, null, ClassLoader::class); } diff --git a/vendor/scoper-autoload.php b/vendor/scoper-autoload.php index 36270e9b32a..c7cf58ee59d 100644 --- a/vendor/scoper-autoload.php +++ b/vendor/scoper-autoload.php @@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php'; if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) { spl_autoload_call('RectorPrefix20220105\AutoloadIncluder'); } -if (!class_exists('ComposerAutoloaderInit4786b9bf3ccba2bd289627c76c84f87f', false) && !interface_exists('ComposerAutoloaderInit4786b9bf3ccba2bd289627c76c84f87f', false) && !trait_exists('ComposerAutoloaderInit4786b9bf3ccba2bd289627c76c84f87f', false)) { - spl_autoload_call('RectorPrefix20220105\ComposerAutoloaderInit4786b9bf3ccba2bd289627c76c84f87f'); +if (!class_exists('ComposerAutoloaderInitd2c47e9b1c523de03caede4ae2ea2722', false) && !interface_exists('ComposerAutoloaderInitd2c47e9b1c523de03caede4ae2ea2722', false) && !trait_exists('ComposerAutoloaderInitd2c47e9b1c523de03caede4ae2ea2722', false)) { + spl_autoload_call('RectorPrefix20220105\ComposerAutoloaderInitd2c47e9b1c523de03caede4ae2ea2722'); } if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) { spl_autoload_call('RectorPrefix20220105\Helmich\TypoScriptParser\Parser\AST\Statement'); @@ -51,6 +51,11 @@ if (!class_exists('Symplify\SmartFileSystem\SmartFileInfo', false) && !interface // Functions whitelisting. For more information see: // https://github.com/humbug/php-scoper/blob/master/README.md#functions-whitelisting +if (!function_exists('dump_with_depth')) { + function dump_with_depth() { + return \RectorPrefix20220105\dump_with_depth(...func_get_args()); + } +} if (!function_exists('dn')) { function dn() { return \RectorPrefix20220105\dn(...func_get_args()); @@ -66,9 +71,9 @@ if (!function_exists('print_node')) { return \RectorPrefix20220105\print_node(...func_get_args()); } } -if (!function_exists('composerRequire4786b9bf3ccba2bd289627c76c84f87f')) { - function composerRequire4786b9bf3ccba2bd289627c76c84f87f() { - return \RectorPrefix20220105\composerRequire4786b9bf3ccba2bd289627c76c84f87f(...func_get_args()); +if (!function_exists('composerRequired2c47e9b1c523de03caede4ae2ea2722')) { + function composerRequired2c47e9b1c523de03caede4ae2ea2722() { + return \RectorPrefix20220105\composerRequired2c47e9b1c523de03caede4ae2ea2722(...func_get_args()); } } if (!function_exists('scanPath')) {