mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-20 10:02:29 +00:00
bdfd24339f
2e977bd3aa
deploy to original repository
40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\PHPStanStaticTypeMapper;
|
|
|
|
use PHPStan\Type\ArrayType;
|
|
use PHPStan\Type\Type;
|
|
use PHPStan\Type\TypeWithClassName;
|
|
use PHPStan\Type\UnionType;
|
|
final class DoctrineTypeAnalyzer
|
|
{
|
|
public function isDoctrineCollectionWithIterableUnionType(Type $type) : bool
|
|
{
|
|
if (!$type instanceof UnionType) {
|
|
return \false;
|
|
}
|
|
$arrayType = null;
|
|
$hasDoctrineCollectionType = \false;
|
|
foreach ($type->getTypes() as $unionedType) {
|
|
if ($this->isCollectionObjectType($unionedType)) {
|
|
$hasDoctrineCollectionType = \true;
|
|
}
|
|
if ($unionedType instanceof ArrayType) {
|
|
$arrayType = $unionedType;
|
|
}
|
|
}
|
|
if (!$hasDoctrineCollectionType) {
|
|
return \false;
|
|
}
|
|
return $arrayType !== null;
|
|
}
|
|
private function isCollectionObjectType(Type $type) : bool
|
|
{
|
|
if (!$type instanceof TypeWithClassName) {
|
|
return \false;
|
|
}
|
|
return $type->getClassName() === 'Doctrine\\Common\\Collections\\Collection';
|
|
}
|
|
}
|