mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-20 23:41:57 +02:00
fix import order
This commit is contained in:
parent
1a8ed46b02
commit
d04b66adef
@ -36,6 +36,11 @@ final class Attribute
|
||||
*/
|
||||
public const LAST_TOKEN_POSITION = 'last_token_position';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RESOLVED_NAME = 'resolved_name';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -651,7 +651,7 @@ final class DocBlockManipulator
|
||||
if ($attributeAwareNode->getAttribute('resolved_name')) {
|
||||
$fqnName = $attributeAwareNode->getAttribute('resolved_name');
|
||||
} else {
|
||||
$fqnName = $attributeAwareNode->getAttribute('resolved_names')[0] ?? $attributeAwareNode->name;
|
||||
$fqnName = $attributeAwareNode->getAttribute(Attribute::RESOLVED_NAMES)[0] ?? $attributeAwareNode->name;
|
||||
}
|
||||
|
||||
return ltrim($fqnName, '\\');
|
||||
|
@ -18,22 +18,11 @@ use Rector\BetterPhpDocParser\Attributes\Ast\PhpDoc\Type\AttributeAwareIntersect
|
||||
use Rector\BetterPhpDocParser\Attributes\Ast\PhpDoc\Type\AttributeAwareThisTypeNode;
|
||||
use Rector\BetterPhpDocParser\Attributes\Ast\PhpDoc\Type\AttributeAwareUnionTypeNode;
|
||||
use Rector\BetterPhpDocParser\Attributes\Attribute\Attribute;
|
||||
use Rector\BetterPhpDocParser\Attributes\Attribute\Attribute as PhpDocAttribute;
|
||||
use Rector\BetterPhpDocParser\Attributes\Contract\Ast\AttributeAwareNodeInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\PhpDocNodeDecoratorInterface;
|
||||
|
||||
final class FqnNamePhpDocNodeDecorator implements PhpDocNodeDecoratorInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RESOLVED_NAMES = 'resolved_names';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const RESOLVED_NAME = 'resolved_name';
|
||||
|
||||
/**
|
||||
* @var NamespaceAnalyzer
|
||||
*/
|
||||
@ -68,7 +57,7 @@ final class FqnNamePhpDocNodeDecorator implements PhpDocNodeDecoratorInterface
|
||||
$node
|
||||
);
|
||||
|
||||
$attributeAwarePhpDocNode->setAttribute(self::RESOLVED_NAME, $fqnName);
|
||||
$attributeAwarePhpDocNode->setAttribute(Attribute::RESOLVED_NAME, $fqnName);
|
||||
|
||||
return $attributeAwarePhpDocNode;
|
||||
}
|
||||
@ -84,11 +73,11 @@ final class FqnNamePhpDocNodeDecorator implements PhpDocNodeDecoratorInterface
|
||||
|
||||
/** @var AttributeAwareVarTagValueNode $attributeAwarePhpDocNode */
|
||||
$resolvedNames = $this->collectResolvedNames($attributeAwarePhpDocNode->type);
|
||||
$attributeAwarePhpDocNode->setAttribute(self::RESOLVED_NAMES, $resolvedNames);
|
||||
$attributeAwarePhpDocNode->setAttribute(Attribute::RESOLVED_NAMES, $resolvedNames);
|
||||
|
||||
/** @var AttributeAwareNodeInterface $attributeAwaretType */
|
||||
$attributeAwaretType = $attributeAwarePhpDocNode->type;
|
||||
$attributeAwaretType->setAttribute(self::RESOLVED_NAMES, $resolvedNames);
|
||||
$attributeAwaretType->setAttribute(Attribute::RESOLVED_NAMES, $resolvedNames);
|
||||
|
||||
return $attributeAwarePhpDocNode;
|
||||
}
|
||||
@ -122,10 +111,10 @@ final class FqnNamePhpDocNodeDecorator implements PhpDocNodeDecoratorInterface
|
||||
$resolvedNames = array_merge($resolvedNames, $this->collectResolvedNames($subtype));
|
||||
}
|
||||
} elseif ($typeNode instanceof AttributeAwareArrayTypeNode || $typeNode instanceof AttributeAwareThisTypeNode) {
|
||||
$resolvedNames[] = $typeNode->getAttribute(PhpDocAttribute::TYPE_AS_STRING);
|
||||
$resolvedNames[] = $typeNode->getAttribute(Attribute::TYPE_AS_STRING);
|
||||
} elseif ($typeNode instanceof AttributeAwareIdentifierTypeNode) {
|
||||
if ($typeNode->getAttribute(self::RESOLVED_NAME)) {
|
||||
$resolvedNames[] = $typeNode->getAttribute(self::RESOLVED_NAME);
|
||||
if ($typeNode->getAttribute(Attribute::RESOLVED_NAME)) {
|
||||
$resolvedNames[] = $typeNode->getAttribute(Attribute::RESOLVED_NAME);
|
||||
} elseif ($typeNode->getAttribute(Attribute::TYPE_AS_STRING)) {
|
||||
$resolvedNames[] = $typeNode->getAttribute(Attribute::TYPE_AS_STRING);
|
||||
}
|
||||
|
@ -53,7 +53,11 @@ final class NamespaceAnalyzer
|
||||
{
|
||||
foreach ($useNodes as $useNode) {
|
||||
$useUseNode = $useNode->uses[0];
|
||||
$nodeUseName = $useUseNode->name->toString();
|
||||
if ($useUseNode->alias) {
|
||||
$nodeUseName = $useUseNode->alias->name;
|
||||
} else {
|
||||
$nodeUseName = $useUseNode->name->toString();
|
||||
}
|
||||
|
||||
if (Strings::endsWith($nodeUseName, '\\' . $type)) {
|
||||
return $nodeUseName;
|
||||
|
@ -7,7 +7,6 @@ use Fully\Qualified\ClassName\TheActual\Foo\Bar;
|
||||
use Fully\Qualified\ClassName\TheActual\Bar\Foo;
|
||||
use Fully\Qualified\ClassName\SomeTotallyDifferentButLastListed\Bar\Foo as BarFooLast;
|
||||
|
||||
|
||||
class InjectFromVarWithTypeOfSameName
|
||||
{
|
||||
/**
|
||||
@ -45,7 +44,6 @@ class InjectFromVarWithTypeOfSameName
|
||||
private $someBarDependency;
|
||||
|
||||
/**
|
||||
* @Inject
|
||||
*
|
||||
* @var Foo
|
||||
*/
|
||||
|
@ -29,6 +29,7 @@ final class InjectAnnotationClassRectorTest extends AbstractRectorTestCase
|
||||
__DIR__ . '/Fixture/fixture5.php.inc',
|
||||
__DIR__ . '/Fixture/inject_from_var.php.inc',
|
||||
__DIR__ . '/Fixture/inject_from_var2.php.inc',
|
||||
// alias order
|
||||
__DIR__ . '/Fixture/inject_from_var3.php.inc',
|
||||
]);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user