From 94aba5f73623ae6a84eb26b1fe56b66bf3736630 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 29 Apr 2019 11:40:52 +0200 Subject: [PATCH 1/2] decouple addTypeSpecificTag() in DocBlockManipulator --- .../NodeAnalyzer/DocBlockManipulator.php | 54 ++++++++----------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/packages/NodeTypeResolver/src/PhpDoc/NodeAnalyzer/DocBlockManipulator.php b/packages/NodeTypeResolver/src/PhpDoc/NodeAnalyzer/DocBlockManipulator.php index fe10a7455106..2b06e507c261 100644 --- a/packages/NodeTypeResolver/src/PhpDoc/NodeAnalyzer/DocBlockManipulator.php +++ b/packages/NodeTypeResolver/src/PhpDoc/NodeAnalyzer/DocBlockManipulator.php @@ -241,42 +241,12 @@ public function getTagsByName(Node $node, string $name): array public function addVarTag(Node $node, string $type): void { - // there might be no phpdoc at all - if ($node->getDocComment() !== null) { - $phpDocInfo = $this->createPhpDocInfoFromNode($node); - $phpDocNode = $phpDocInfo->getPhpDocNode(); - - $varTagValueNode = new AttributeAwareVarTagValueNode(new AttributeAwareIdentifierTypeNode( - '\\' . $type - ), '', ''); - $phpDocNode->children[] = new AttributeAwarePhpDocTagNode('@var', $varTagValueNode); - - $this->updateNodeWithPhpDocInfo($node, $phpDocInfo); - } else { - // create completely new docblock - $varDocComment = sprintf("/**\n * @var %s\n */", $type); - $node->setDocComment(new Doc($varDocComment)); - } + $this->addTypeSpecificTag($node, 'var', $type); } public function addReturnTag(Node $node, string $type): void { - // there might be no phpdoc at all - if ($node->getDocComment() !== null) { - $phpDocInfo = $this->createPhpDocInfoFromNode($node); - $phpDocNode = $phpDocInfo->getPhpDocNode(); - - $varTagValueNode = new AttributeAwareVarTagValueNode(new AttributeAwareIdentifierTypeNode( - '\\' . $type - ), '', ''); - $phpDocNode->children[] = new AttributeAwarePhpDocTagNode('@return', $varTagValueNode); - - $this->updateNodeWithPhpDocInfo($node, $phpDocInfo); - } else { - // create completely new docblock - $varDocComment = sprintf("/**\n * @return %s\n */", $type); - $node->setDocComment(new Doc($varDocComment)); - } + $this->addTypeSpecificTag($node, 'return', $type); } /** @@ -455,6 +425,26 @@ public function changeUnderscoreType(Node $node, string $namespacePrefix, ?array $this->updateNodeWithPhpDocInfo($node, $phpDocInfo); } + private function addTypeSpecificTag(Node $node, string $name, string $type): void + { + // there might be no phpdoc at all + if ($node->getDocComment() !== null) { + $phpDocInfo = $this->createPhpDocInfoFromNode($node); + $phpDocNode = $phpDocInfo->getPhpDocNode(); + + $varTagValueNode = new AttributeAwareVarTagValueNode(new AttributeAwareIdentifierTypeNode( + '\\' . $type + ), '', ''); + $phpDocNode->children[] = new AttributeAwarePhpDocTagNode('@' . $name, $varTagValueNode); + + $this->updateNodeWithPhpDocInfo($node, $phpDocInfo); + } else { + // create completely new docblock + $varDocComment = sprintf("/**\n * @%s %s\n */", $name, $type); + $node->setDocComment(new Doc($varDocComment)); + } + } + private function updateNodeWithPhpDocInfo(Node $node, PhpDocInfo $phpDocInfo): void { // skip if has no doc comment From 9427b46ed9dbbcf97e8d230049a960d8f158dce6 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 29 Apr 2019 11:45:20 +0200 Subject: [PATCH 2/2] Notice file rectors on run [closes #1355] --- src/Guard/RectorGuard.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Guard/RectorGuard.php b/src/Guard/RectorGuard.php index ead7d24b2145..49ee2f6f1590 100644 --- a/src/Guard/RectorGuard.php +++ b/src/Guard/RectorGuard.php @@ -3,6 +3,7 @@ namespace Rector\Guard; use Rector\Exception\NoRectorsLoadedException; +use Rector\FileSystemRector\FileSystemFileProcessor; use Rector\PhpParser\NodeTraverser\RectorNodeTraverser; final class RectorGuard @@ -12,14 +13,26 @@ final class RectorGuard */ private $rectorNodeTraverser; - public function __construct(RectorNodeTraverser $rectorNodeTraverser) - { + /** + * @var FileSystemFileProcessor + */ + private $fileSystemFileProcessor; + + public function __construct( + RectorNodeTraverser $rectorNodeTraverser, + FileSystemFileProcessor $fileSystemFileProcessor + ) { $this->rectorNodeTraverser = $rectorNodeTraverser; + $this->fileSystemFileProcessor = $fileSystemFileProcessor; } public function ensureSomeRectorsAreRegistered(): void { - if ($this->rectorNodeTraverser->getRectorCount() !== 0) { + if ($this->rectorNodeTraverser->getRectorCount() > 0) { + return; + } + + if ($this->fileSystemFileProcessor->getFileSystemRectorsCount() > 0) { return; }