fix method annotation

This commit is contained in:
TomasVotruba 2020-03-04 23:22:29 +01:00
parent baa057d48b
commit 1b937ec0e0
7 changed files with 31 additions and 27 deletions

View File

@ -40,7 +40,7 @@ final class SensioTemplateTagValueNode extends AbstractTagValueNode implements S
$contentItems = [];
if ($this->template) {
$contentItems[] = $this->template;
$contentItems[] = '"' . $this->template . '"';
}
if ($this->owner) {
@ -55,7 +55,7 @@ final class SensioTemplateTagValueNode extends AbstractTagValueNode implements S
return '';
}
return implode(', ', $contentItems);
return '(' . implode(', ', $contentItems) . ')';
}
public function getTemplate(): ?string

View File

@ -34,6 +34,9 @@ final class SensioTemplatePhpDocNodeFactory extends AbstractPhpDocNodeFactory
return null;
}
// to skip tokens for this node
$this->resolveContentFromTokenIterator($tokenIterator);
return new SensioTemplateTagValueNode(
$template->getTemplate(),
$template->getOwner(),

View File

@ -32,7 +32,7 @@ use Symplify\PackageBuilder\Reflection\PrivatesCaller;
/**
* @see \Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser\Class_\DoctrinePhpDocParserTest
* @see \Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser\Property_\OrmTagParserPropertyTest
* @see \Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser\Property_\ParserPropertyTest
*/
final class BetterPhpDocParser extends PhpDocParser
{
@ -130,6 +130,10 @@ final class BetterPhpDocParser extends PhpDocParser
$this->isComment = false;
// here are all 3 annotations
// dump($tokenIterator);
// @todo test later, this might be removed
try {
$tokenIterator->consumeTokenType(Lexer::TOKEN_OPEN_PHPDOC);
} catch (ParserException $parserException) {
@ -143,6 +147,7 @@ final class BetterPhpDocParser extends PhpDocParser
$children = [];
if (! $tokenIterator->isCurrentTokenType(Lexer::TOKEN_CLOSE_PHPDOC)) {
$children[] = $this->parseChildAndStoreItsPositions($tokenIterator);
while ($tokenIterator->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL) && ! $tokenIterator->isCurrentTokenType(
Lexer::TOKEN_CLOSE_PHPDOC
)) {
@ -150,6 +155,7 @@ final class BetterPhpDocParser extends PhpDocParser
}
}
// here should be 3 children too
if (! $this->isComment) {
// might be in the middle of annotations
$tokenIterator->tryConsumeTokenType(Lexer::TOKEN_CLOSE_PHPDOC);
@ -216,14 +222,12 @@ final class BetterPhpDocParser extends PhpDocParser
$tokenStart = $this->getTokenIteratorIndex($tokenIterator);
$phpDocNode = $this->privatesCaller->callPrivateMethod($this, 'parseChild', $tokenIterator);
$tokenEnd = $this->getTokenIteratorIndex($tokenIterator);
$tokenEnd = $this->adjustTokenEndToFitClassAnnotation($tokenIterator, $tokenEnd);
$tokenEnd = $this->resolveTokenEnd($tokenIterator);
$startEndValueObject = new StartEndValueObject($tokenStart, $tokenEnd);
$attributeAwareNode = $this->attributeAwareNodeFactory->createFromNode($phpDocNode, $docContent);
$attributeAwareNode->setAttribute(Attribute::START_END, $startEndValueObject);
$possibleMultilineText = $this->multilineSpaceFormatPreserver->resolveCurrentPhpDocNodeText(
@ -358,6 +362,13 @@ final class BetterPhpDocParser extends PhpDocParser
return trim($originalContent);
}
private function resolveTokenEnd(TokenIterator $tokenIterator): int
{
$tokenEnd = $this->getTokenIteratorIndex($tokenIterator);
return $this->adjustTokenEndToFitClassAnnotation($tokenIterator, $tokenEnd);
}
private function isTagMatchedByFactories(string $tag): bool
{
$currentPhpNode = $this->currentNodeProvider->getNode();

View File

@ -6,6 +6,7 @@ namespace Rector\Symfony\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocNode\Sensio\SensioMethodTagValueNode;
use Rector\BetterPhpDocParser\PhpDocNode\Symfony\SymfonyRouteTagValueNode;
use Rector\Core\Rector\AbstractRector;
@ -84,6 +85,7 @@ PHP
return null;
}
/** @var PhpDocInfo|null $phpDocInfo */
$phpDocInfo = $node->getAttribute(AttributeKey::PHP_DOC_INFO);
if ($phpDocInfo === null) {
return null;

View File

@ -4,8 +4,6 @@ declare(strict_types=1);
namespace Sensio\Bundle\FrameworkExtraBundle\Configuration;
use RuntimeException;
if (class_exists('Sensio\Bundle\FrameworkExtraBundle\Configuration\Template')) {
return;
}
@ -13,9 +11,12 @@ if (class_exists('Sensio\Bundle\FrameworkExtraBundle\Configuration\Template')) {
// mimics https://github.com/sensiolabs/SensioFrameworkExtraBundle/blob/master/Configuration/Template.php, is missing localy
/**
* The Template class handles the Template annotation parts.
*
* @author Fabien Potencier <fabien@symfony.com>
* @Annotation
*/
class Template
class Template extends ConfigurationAnnotation
{
/**
* The template.
@ -45,16 +46,6 @@ class Template
*/
private $owner = [];
public function __construct(array $values)
{
foreach ($values as $k => $v) {
if (! method_exists($this, $name = 'set' . $k)) {
throw new RuntimeException(sprintf('Unknown key "%s" for annotation "@%s".', $k, static::class));
}
$this->{$name}($v);
}
}
/**
* Returns the array of templates variables.
*
@ -68,7 +59,7 @@ class Template
/**
* @param bool $streamable
*/
public function setIsStreamable($streamable): void
public function setIsStreamable($streamable)
{
$this->streamable = $streamable;
}
@ -86,7 +77,7 @@ class Template
*
* @param array $vars The template variables
*/
public function setVars($vars): void
public function setVars($vars)
{
$this->vars = $vars;
}
@ -96,7 +87,7 @@ class Template
*
* @param string $template The template logic name
*/
public function setValue($template): void
public function setValue($template)
{
$this->setTemplate($template);
}
@ -116,7 +107,7 @@ class Template
*
* @param string $template The template
*/
public function setTemplate($template): void
public function setTemplate($template)
{
$this->template = $template;
}
@ -145,10 +136,7 @@ class Template
return false;
}
/**
* @param array $owner
*/
public function setOwner(array $owner): void
public function setOwner(array $owner)
{
$this->owner = $owner;
}