Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! Add test case for #3222
Browse files Browse the repository at this point in the history
  • Loading branch information
rector-bot committed May 4, 2020
1 parent ace24f8 commit acf4d1b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
29 changes: 13 additions & 16 deletions packages/better-php-doc-parser/src/PhpDocInfo/PhpDocInfoFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ final class PhpDocInfoFactory
* @var ParamPhpDocNodeFactory
*/
private $paramPhpDocNodeFactory;
// create empty node
/**
* @var string
*/
private const CONTENT = '';
/**
* @var mixed[]
*/
private const TOKENS = [];

public function __construct(
PhpDocParser $phpDocParser,
Expand All @@ -82,14 +91,6 @@ public function createFromNode(Node $node): ?PhpDocInfo

if ($node->getDocComment() === null) {
return null;

if ($node->getComments() !== []) {
return null;
}
// create empty node
$content = '';
$tokens = [];
$phpDocNode = new AttributeAwarePhpDocNode([]);
} else {
$content = $node->getDocComment()->getText();
$tokens = $this->lexer->tokenize($content);
Expand All @@ -104,13 +105,9 @@ public function createEmpty(Node $node): PhpDocInfo
{
/** needed for @see PhpDocNodeFactoryInterface */
$this->currentNodeProvider->setNode($node);

// create empty node
$content = '';
$tokens = [];
$phpDocNode = new AttributeAwarePhpDocNode([]);

return $this->createFromPhpDocNode($phpDocNode, $content, $tokens, $node);
return $this->createFromPhpDocNode($phpDocNode, self::CONTENT, self::TOKENS, $node);
}

private function parseTokensToPhpDocNode(array $tokens): AttributeAwarePhpDocNode
Expand Down Expand Up @@ -142,16 +139,16 @@ private function setPositionOfLastToken(AttributeAwarePhpDocNode $attributeAware
}

private function createFromPhpDocNode(
AttributeAwarePhpDocNode $phpDocNode,
AttributeAwarePhpDocNode $attributeAwarePhpDocNode,
string $content,
array $tokens,
Node $node
): PhpDocInfo {
/** @var AttributeAwarePhpDocNode $phpDocNode */
$phpDocNode = $this->attributeAwareNodeFactory->createFromNode($phpDocNode, $content);
$attributeAwarePhpDocNode = $this->attributeAwareNodeFactory->createFromNode($attributeAwarePhpDocNode, $content);

$phpDocInfo = new PhpDocInfo(
$phpDocNode,
$attributeAwarePhpDocNode,
$tokens,
$content,
$this->staticTypeMapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,6 @@ public function updateNodeWithPhpDocInfo(Node $node): void
if ($phpDoc === '') {
dump($phpDocInfo);
die;

if ($phpDocInfo->getOriginalPhpDocNode()->children !== []) {
// all comments were removed → null
$node->setAttribute('comments', null);
}

return;
}

// no change, don't save it
Expand Down

0 comments on commit acf4d1b

Please sign in to comment.