mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-29 07:20:52 +00:00
d79b1c7718
31c1deb3f9
Defer type-resolving in IterableTypeAnalyzer (#3760)
30 lines
688 B
PHP
30 lines
688 B
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\CodingStyle\TypeAnalyzer;
|
|
|
|
use PHPStan\Type\IterableType;
|
|
use PHPStan\Type\Type;
|
|
use PHPStan\Type\UnionType;
|
|
final class IterableTypeAnalyzer
|
|
{
|
|
public function detect(Type $type) : bool
|
|
{
|
|
if ($type instanceof IterableType) {
|
|
return \true;
|
|
}
|
|
if ($type->isArray()->yes()) {
|
|
return \true;
|
|
}
|
|
if ($type instanceof UnionType) {
|
|
foreach ($type->getTypes() as $unionedType) {
|
|
if (!$this->detect($unionedType)) {
|
|
return \false;
|
|
}
|
|
}
|
|
return \true;
|
|
}
|
|
return \false;
|
|
}
|
|
}
|