Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ parameters:
paths:
- src/NodeNameResolver/NodeNameResolver.php
- src/BetterPhpDocParser/PhpDocParser/BetterPhpDocParser.php
- src/BetterPhpDocParser/PhpDocParser/DoctrineAnnotationDecorator.php
- src/BetterPhpDocParser/NodeDecorator/DoctrineAnnotationDecorator.php

-
identifier: symplify.forbiddenFuncCall
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Rector\Tests\DeadCode\Rector\Assign\RemoveDoubleSelfAssignRector\Fixture;

$first = $second = createValidator();
$first = $second = 1234;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\PhpDocParser;
namespace Rector\BetterPhpDocParser\NodeDecorator;

use PhpParser\Node as PhpNode;
use PHPStan\PhpDocParser\Ast\Node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\PhpDocParser;
namespace Rector\BetterPhpDocParser\NodeDecorator;

use PhpParser\Node as PhpNode;
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstFetchNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\PhpDocParser;
namespace Rector\BetterPhpDocParser\NodeDecorator;

use Nette\Utils\Strings;
use PhpParser\Node;
Expand All @@ -21,6 +21,8 @@
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDoc\SpacelessPhpDocTagNode;
use Rector\BetterPhpDocParser\PhpDocInfo\TokenIteratorFactory;
use Rector\BetterPhpDocParser\PhpDocParser\ClassAnnotationMatcher;
use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser;
use Rector\BetterPhpDocParser\ValueObject\DoctrineAnnotation\SilentKeyMap;
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
use Rector\BetterPhpDocParser\ValueObject\StartAndEnd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Rector\BetterPhpDocParser\PhpDocParser;
namespace Rector\BetterPhpDocParser\NodeDecorator;

use PhpParser\Node as PhpNode;
use PHPStan\PhpDocParser\Ast\Node;
Expand Down
24 changes: 22 additions & 2 deletions src/BetterPhpDocParser/PhpDocParser/BetterPhpDocParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
use PHPStan\PhpDocParser\Parser\TypeParser;
use PHPStan\PhpDocParser\ParserConfig;
use Rector\BetterPhpDocParser\Contract\PhpDocParser\PhpDocNodeDecoratorInterface;
use Rector\BetterPhpDocParser\NodeDecorator\ArrayItemClassNameDecorator;
use Rector\BetterPhpDocParser\NodeDecorator\ConstExprClassNameDecorator;
use Rector\BetterPhpDocParser\NodeDecorator\DoctrineAnnotationDecorator;
use Rector\BetterPhpDocParser\NodeDecorator\PhpDocTagGenericUsesDecorator;
use Rector\BetterPhpDocParser\PhpDocInfo\TokenIteratorFactory;
use Rector\BetterPhpDocParser\ValueObject\Parser\BetterTokenIterator;
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
Expand All @@ -44,16 +48,32 @@ final class BetterPhpDocParser extends PhpDocParser
private const string MULTI_NEW_LINES_REGEX = '#(?<new_line>\r\n|\n){2,}#';

/**
* @param PhpDocNodeDecoratorInterface[] $phpDocNodeDecorators
* @var PhpDocNodeDecoratorInterface[]
*/
private readonly array $phpDocNodeDecorators;

public function __construct(
ParserConfig $parserConfig,
TypeParser $typeParser,
ConstExprParser $constExprParser,
private readonly TokenIteratorFactory $tokenIteratorFactory,
private readonly array $phpDocNodeDecorators,
ConstExprClassNameDecorator $constExprClassNameDecorator,
DoctrineAnnotationDecorator $doctrineAnnotationDecorator,
ArrayItemClassNameDecorator $arrayItemClassNameDecorator,
PhpDocTagGenericUsesDecorator $phpDocTagGenericUsesDecorator,
private readonly PrivatesAccessor $privatesAccessor,
) {
// The decorator order below is significant; keep it as is. DoctrineAnnotationDecorator must
// run before ArrayItemClassNameDecorator, which resolves class names inside the array items the
// former produces. A wrong order silently drops annotation class usages and strips their imports.
// They are injected explicitly, not autodiscovered, so the order stays under our control.
$this->phpDocNodeDecorators = [
$constExprClassNameDecorator,
$doctrineAnnotationDecorator,
$arrayItemClassNameDecorator,
$phpDocTagGenericUsesDecorator,
];

parent::__construct(
// ParserConfig
$parserConfig,
Expand Down
21 changes: 0 additions & 21 deletions src/DependencyInjection/LazyContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,11 @@
use Rector\Application\Provider\CurrentFileProvider;
use Rector\BetterPhpDocParser\Comment\CommentsMerger;
use Rector\BetterPhpDocParser\Contract\BasePhpDocNodeVisitorInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocParser\PhpDocNodeDecoratorInterface;
use Rector\BetterPhpDocParser\PhpDocNodeVisitor\ArrayTypePhpDocNodeVisitor;
use Rector\BetterPhpDocParser\PhpDocNodeVisitor\CallableTypePhpDocNodeVisitor;
use Rector\BetterPhpDocParser\PhpDocNodeVisitor\IntersectionTypeNodePhpDocNodeVisitor;
use Rector\BetterPhpDocParser\PhpDocNodeVisitor\TemplatePhpDocNodeVisitor;
use Rector\BetterPhpDocParser\PhpDocNodeVisitor\UnionTypeNodePhpDocNodeVisitor;
use Rector\BetterPhpDocParser\PhpDocParser\ArrayItemClassNameDecorator;
use Rector\BetterPhpDocParser\PhpDocParser\ConstExprClassNameDecorator;
use Rector\BetterPhpDocParser\PhpDocParser\DoctrineAnnotationDecorator;
use Rector\BetterPhpDocParser\PhpDocParser\PhpDocTagGenericUsesDecorator;
use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser;
use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\ArrayParser;
use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\PlainValueParser;
Expand Down Expand Up @@ -107,16 +102,6 @@ final class LazyContainerFactory
DefaultValueNodeVisitor::class,
];

/**
* @var array<class-string<PhpDocNodeDecoratorInterface>>
*/
private const array PHP_DOC_NODE_DECORATOR_CLASSES = [
ConstExprClassNameDecorator::class,
DoctrineAnnotationDecorator::class,
ArrayItemClassNameDecorator::class,
PhpDocTagGenericUsesDecorator::class,
];

/**
* @var array<class-string>
*/
Expand Down Expand Up @@ -276,12 +261,6 @@ static function (AbstractRector $rector) use ($rectorConfig): void {

$rectorConfig->autodiscover(__DIR__ . '/../StaticTypeMapper/PhpParser');

$this->registerTagged(
$rectorConfig,
self::PHP_DOC_NODE_DECORATOR_CLASSES,
PhpDocNodeDecoratorInterface::class
);

$this->registerTagged(
$rectorConfig,
self::BASE_PHP_DOC_NODE_VISITORS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
use PhpParser\Node\Stmt\Nop;
use PhpParser\Node\Stmt\Use_;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use Rector\BetterPhpDocParser\NodeDecorator\DoctrineAnnotationDecorator;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDocInfo\TokenIteratorFactory;
use Rector\BetterPhpDocParser\PhpDocParser\DoctrineAnnotationDecorator;
use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser;
use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode;
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
Expand Down
Loading