mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-25 04:03:55 +01:00
drop normalizeTypes() from DocBlockAnalyzer
This commit is contained in:
parent
56347bf93c
commit
71528faf6d
@ -24,8 +24,8 @@ use PHPStan\PhpDocParser\Ast\Type\TypeNode;
|
|||||||
use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
|
use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
|
||||||
use Rector\Exception\NotImplementedException;
|
use Rector\Exception\NotImplementedException;
|
||||||
use Rector\ReflectionDocBlock\DocBlock\DocBlockFactory;
|
use Rector\ReflectionDocBlock\DocBlock\DocBlockFactory;
|
||||||
use Symplify\BetterPhpDocParser\PhpDocParser\PhpDocInfo;
|
|
||||||
use Symplify\BetterPhpDocParser\PhpDocParser\PhpDocInfoFactory;
|
use Symplify\BetterPhpDocParser\PhpDocParser\PhpDocInfoFactory;
|
||||||
|
use Symplify\BetterPhpDocParser\PhpDocParser\TypeResolver;
|
||||||
use Symplify\BetterPhpDocParser\Printer\PhpDocInfoPrinter;
|
use Symplify\BetterPhpDocParser\Printer\PhpDocInfoPrinter;
|
||||||
use Symplify\BetterReflectionDocBlock\Tag\TolerantVar;
|
use Symplify\BetterReflectionDocBlock\Tag\TolerantVar;
|
||||||
use Symplify\PackageBuilder\Reflection\PrivatesAccessor;
|
use Symplify\PackageBuilder\Reflection\PrivatesAccessor;
|
||||||
@ -72,18 +72,25 @@ final class DocBlockAnalyzer
|
|||||||
*/
|
*/
|
||||||
private $node;
|
private $node;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var TypeResolver
|
||||||
|
*/
|
||||||
|
private $typeResolver;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
DocBlockFactory $docBlockFactory,
|
DocBlockFactory $docBlockFactory,
|
||||||
PhpDocInfoFactory $phpDocInfoFactory,
|
PhpDocInfoFactory $phpDocInfoFactory,
|
||||||
PrivatesAccessor $privatesAccessor,
|
PrivatesAccessor $privatesAccessor,
|
||||||
PhpDocInfoPrinter $phpDocInfoPrinter,
|
PhpDocInfoPrinter $phpDocInfoPrinter,
|
||||||
NamespaceAnalyzer $namespaceAnalyzer
|
NamespaceAnalyzer $namespaceAnalyzer,
|
||||||
|
TypeResolver $typeResolver
|
||||||
) {
|
) {
|
||||||
$this->docBlockFactory = $docBlockFactory;
|
$this->docBlockFactory = $docBlockFactory;
|
||||||
$this->phpDocInfoFactory = $phpDocInfoFactory;
|
$this->phpDocInfoFactory = $phpDocInfoFactory;
|
||||||
$this->privatesAccessor = $privatesAccessor;
|
$this->privatesAccessor = $privatesAccessor;
|
||||||
$this->phpDocInfoPrinter = $phpDocInfoPrinter;
|
$this->phpDocInfoPrinter = $phpDocInfoPrinter;
|
||||||
$this->namespaceAnalyzer = $namespaceAnalyzer;
|
$this->namespaceAnalyzer = $namespaceAnalyzer;
|
||||||
|
$this->typeResolver = $typeResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasAnnotation(Node $node, string $annotation): bool
|
public function hasAnnotation(Node $node, string $annotation): bool
|
||||||
@ -134,7 +141,7 @@ final class DocBlockAnalyzer
|
|||||||
* @todo no need to check for nullable, just replace types
|
* @todo no need to check for nullable, just replace types
|
||||||
* @todo check one service above, it
|
* @todo check one service above, it
|
||||||
*/
|
*/
|
||||||
public function renameNullable(Node $node, string $oldType, string $newType): void
|
public function changeType(Node $node, string $oldType, string $newType): void
|
||||||
{
|
{
|
||||||
$this->node = $node;
|
$this->node = $node;
|
||||||
|
|
||||||
@ -179,17 +186,21 @@ final class DocBlockAnalyzer
|
|||||||
*/
|
*/
|
||||||
public function getVarTypes(Node $node): ?array
|
public function getVarTypes(Node $node): ?array
|
||||||
{
|
{
|
||||||
/** @var TolerantVar[] $varTags */
|
if ($node->getDocComment() === null) {
|
||||||
$varTags = $this->getTagsByName($node, 'var');
|
|
||||||
if (! count($varTags)) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$varTag = array_shift($varTags);
|
$phpDocInfo = $this->phpDocInfoFactory->createFrom($node->getDocComment()->getText());
|
||||||
|
$varTagValue = $phpDocInfo->getVarTagValue();
|
||||||
|
|
||||||
$types = explode('|', (string) $varTag);
|
$typesAsString = $this->typeResolver->resolveDocType($varTagValue->type);
|
||||||
|
|
||||||
return $this->normalizeTypes($types);
|
$fullyQualifiedTypes = [];
|
||||||
|
foreach (explode('|', $typesAsString) as $type) {
|
||||||
|
$fullyQualifiedTypes[] = $this->namespaceAnalyzer->resolveTypeToFullyQualified([$type], $node);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $fullyQualifiedTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTypeForParam(Node $node, string $paramName): ?string
|
public function getTypeForParam(Node $node, string $paramName): ?string
|
||||||
@ -258,25 +269,6 @@ final class DocBlockAnalyzer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string[] $types
|
|
||||||
* @return string[]
|
|
||||||
*/
|
|
||||||
private function normalizeTypes(array $types): array
|
|
||||||
{
|
|
||||||
// remove preslash: {\]SomeClass
|
|
||||||
$types = array_map(function (string $type) {
|
|
||||||
return ltrim(trim($type), '\\');
|
|
||||||
}, $types);
|
|
||||||
|
|
||||||
// remove arrays: Type{[][][]}
|
|
||||||
$types = array_map(function (string $type) {
|
|
||||||
return rtrim($type, '[]');
|
|
||||||
}, $types);
|
|
||||||
|
|
||||||
return $types;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function resolveNewTypeObjectFromString(string $type): Type
|
private function resolveNewTypeObjectFromString(string $type): Type
|
||||||
{
|
{
|
||||||
if (isset($this->typesToObjects[$type])) {
|
if (isset($this->typesToObjects[$type])) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user