mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit 7e741fee0551af70bb6b3f45c95905fdf9d618ce
7e741fee05
Keep comments in annotations when converting them to attributes (#5650)
This commit is contained in:
parent
194c0359f1
commit
d7100344be
|
@ -110,7 +110,7 @@ use Symfony\Component\Routing\Annotation\Route;
|
|||
class SymfonyRoute
|
||||
{
|
||||
/**
|
||||
* @Route("/path", name="action")
|
||||
* @Route("/path", name="action") api route
|
||||
*/
|
||||
public function action()
|
||||
{
|
||||
|
@ -122,7 +122,7 @@ use Symfony\Component\Routing\Annotation\Route;
|
|||
|
||||
class SymfonyRoute
|
||||
{
|
||||
#[Route(path: '/path', name: 'action')]
|
||||
#[Route(path: '/path', name: 'action')] // api route
|
||||
public function action()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\Transform\Rector\ConstFetch;
|
||||
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use Rector\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\Transform\ValueObject\ConstFetchToClassConstFetch;
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'a4445df500e51deb893319e180c3fbdf64e8dc25';
|
||||
public const PACKAGE_VERSION = '7e741fee0551af70bb6b3f45c95905fdf9d618ce';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-02-21 15:03:30';
|
||||
public const RELEASE_DATE = '2024-02-21 22:15:12';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace Rector\BetterPhpDocParser\PhpDoc;
|
|||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||
use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\AbstractValuesAwareNode;
|
||||
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Stringable;
|
||||
final class DoctrineAnnotationTagValueNode extends AbstractValuesAwareNode
|
||||
{
|
||||
|
@ -16,11 +17,14 @@ final class DoctrineAnnotationTagValueNode extends AbstractValuesAwareNode
|
|||
/**
|
||||
* @param ArrayItemNode[] $values
|
||||
*/
|
||||
public function __construct(IdentifierTypeNode $identifierTypeNode, ?string $originalContent = null, array $values = [], ?string $silentKey = null)
|
||||
public function __construct(IdentifierTypeNode $identifierTypeNode, ?string $originalContent = null, array $values = [], ?string $silentKey = null, ?string $comment = null)
|
||||
{
|
||||
$this->identifierTypeNode = $identifierTypeNode;
|
||||
$this->hasChanged = \true;
|
||||
parent::__construct($values, $originalContent, $silentKey);
|
||||
if (!\in_array($comment, ['', null], \true)) {
|
||||
$this->setAttribute(AttributeKey::ATTRIBUTE_COMMENT, $comment);
|
||||
}
|
||||
}
|
||||
public function __toString() : string
|
||||
{
|
||||
|
|
|
@ -277,9 +277,10 @@ final class DoctrineAnnotationDecorator implements PhpDocNodeDecoratorInterface
|
|||
// mimics doctrine behavior just in phpdoc-parser syntax :)
|
||||
// https://github.com/doctrine/annotations/blob/c66f06b7c83e9a2a7523351a9d5a4b55f885e574/lib/Doctrine/Common/Annotations/DocParser.php#L742
|
||||
$values = $this->staticDoctrineAnnotationParser->resolveAnnotationMethodCall($nestedTokenIterator, $currentPhpNode);
|
||||
$comment = $this->staticDoctrineAnnotationParser->getCommentFromRestOfAnnotation($nestedTokenIterator, $annotationContent);
|
||||
$identifierTypeNode = new IdentifierTypeNode($tagName);
|
||||
$identifierTypeNode->setAttribute(PhpDocAttributeKey::RESOLVED_CLASS, $fullyQualifiedAnnotationClass);
|
||||
$doctrineAnnotationTagValueNode = new DoctrineAnnotationTagValueNode($identifierTypeNode, $annotationContent, $values, SilentKeyMap::CLASS_NAMES_TO_SILENT_KEYS[$fullyQualifiedAnnotationClass] ?? null);
|
||||
$doctrineAnnotationTagValueNode = new DoctrineAnnotationTagValueNode($identifierTypeNode, $annotationContent, $values, SilentKeyMap::CLASS_NAMES_TO_SILENT_KEYS[$fullyQualifiedAnnotationClass] ?? null, $comment);
|
||||
$doctrineAnnotationTagValueNode->setAttribute(PhpDocAttributeKey::START_AND_END, $startAndEnd);
|
||||
return new SpacelessPhpDocTagNode($tagName, $doctrineAnnotationTagValueNode);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\BetterPhpDocParser\PhpDocParser;
|
||||
|
||||
use RectorPrefix202402\Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprNode;
|
||||
use PHPStan\PhpDocParser\Lexer\Lexer;
|
||||
|
@ -29,6 +30,16 @@ final class StaticDoctrineAnnotationParser
|
|||
* @var \Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\ArrayParser
|
||||
*/
|
||||
private $arrayParser;
|
||||
/**
|
||||
* @var string
|
||||
* @see https://regex101.com/r/aU2knc/1
|
||||
*/
|
||||
private const NEWLINES_REGEX = "#\r?\n#";
|
||||
/**
|
||||
* @var string
|
||||
* @see https://regex101.com/r/Pthg5d/1
|
||||
*/
|
||||
private const END_OF_VALUE_CHARACTERS_REGEX = '/^[)} \\r\\n"\']+$/i';
|
||||
public function __construct(PlainValueParser $plainValueParser, ArrayParser $arrayParser)
|
||||
{
|
||||
$this->plainValueParser = $plainValueParser;
|
||||
|
@ -76,6 +87,18 @@ final class StaticDoctrineAnnotationParser
|
|||
$key => $value,
|
||||
];
|
||||
}
|
||||
public function getCommentFromRestOfAnnotation(BetterTokenIterator $tokenIterator, string $annotationContent) : string
|
||||
{
|
||||
// we skip all the remaining tokens from the end of the declaration of values
|
||||
while (\preg_match(self::END_OF_VALUE_CHARACTERS_REGEX, $tokenIterator->currentTokenValue())) {
|
||||
$tokenIterator->next();
|
||||
}
|
||||
// the remaining of the annotation content is the comment
|
||||
$comment = \substr($annotationContent, $tokenIterator->currentTokenOffset());
|
||||
// we only keep the first line as this will be added as a line comment at the end of the attribute
|
||||
$commentLines = Strings::split($comment, self::NEWLINES_REGEX);
|
||||
return $commentLines[0];
|
||||
}
|
||||
/**
|
||||
* @see https://github.com/doctrine/annotations/blob/c66f06b7c83e9a2a7523351a9d5a4b55f885e574/lib/Doctrine/Common/Annotations/DocParser.php#L1051-L1079
|
||||
*
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\NodeTypeResolver\DependencyInjection;
|
||||
|
||||
use Throwable;
|
||||
use PhpParser\Lexer;
|
||||
use PHPStan\Analyser\NodeScopeResolver;
|
||||
use PHPStan\Analyser\ScopeFactory;
|
||||
|
@ -19,6 +18,7 @@ use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\Dy
|
|||
use RectorPrefix202402\Symfony\Component\Console\Input\ArrayInput;
|
||||
use RectorPrefix202402\Symfony\Component\Console\Output\ConsoleOutput;
|
||||
use RectorPrefix202402\Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Throwable;
|
||||
use RectorPrefix202402\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* Factory so Symfony app can use services from PHPStan container
|
||||
|
@ -27,11 +27,6 @@ use RectorPrefix202402\Webmozart\Assert\Assert;
|
|||
*/
|
||||
final class PHPStanServicesFactory
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \PHPStan\DependencyInjection\Container
|
||||
*/
|
||||
private $container;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -44,6 +39,11 @@ includes:
|
|||
in your included phpstan configuration.
|
||||
|
||||
MESSAGE_ERROR;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \PHPStan\DependencyInjection\Container
|
||||
*/
|
||||
private $container;
|
||||
public function __construct()
|
||||
{
|
||||
$containerFactory = new ContainerFactory(\getcwd());
|
||||
|
|
|
@ -249,4 +249,8 @@ final class AttributeKey
|
|||
* @var string
|
||||
*/
|
||||
public const IS_USED_AS_ARG_BY_REF_VALUE = 'is_used_as_arg_by_ref_value';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const ATTRIBUTE_COMMENT = 'attribute_comment';
|
||||
}
|
||||
|
|
|
@ -84,7 +84,12 @@ final class PhpAttributeGroupFactory
|
|||
// keep FQN in the attribute, so it can be easily detected later
|
||||
$attributeName->setAttribute(AttributeKey::PHP_ATTRIBUTE_NAME, $annotationToAttribute->getAttributeClass());
|
||||
$attribute = new Attribute($attributeName, $args);
|
||||
return new AttributeGroup([$attribute]);
|
||||
$attributeGroup = new AttributeGroup([$attribute]);
|
||||
$comment = $doctrineAnnotationTagValueNode->getAttribute(AttributeKey::ATTRIBUTE_COMMENT);
|
||||
if ($comment) {
|
||||
$attributeGroup->setAttribute(AttributeKey::ATTRIBUTE_COMMENT, $comment);
|
||||
}
|
||||
return $attributeGroup;
|
||||
}
|
||||
/**
|
||||
* @api tests
|
||||
|
|
|
@ -113,6 +113,15 @@ final class BetterStandardPrinter extends Standard
|
|||
$content = parent::p($node, $parentFormatPreserved);
|
||||
return $node->getAttribute(AttributeKey::WRAPPED_IN_PARENTHESES) === \true ? '(' . $content . ')' : $content;
|
||||
}
|
||||
protected function pAttributeGroup(Node\AttributeGroup $node) : string
|
||||
{
|
||||
$ret = parent::pAttributeGroup($node);
|
||||
$comment = $node->getAttribute(AttributeKey::ATTRIBUTE_COMMENT);
|
||||
if (!\in_array($comment, ['', null], \true)) {
|
||||
$ret .= ' // ' . $comment;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
protected function pExpr_ArrowFunction(ArrowFunction $arrowFunction) : string
|
||||
{
|
||||
if (!$arrowFunction->hasAttribute(AttributeKey::COMMENT_CLOSURE_RETURN_MIRRORED)) {
|
||||
|
|
|
@ -504,8 +504,8 @@
|
|||
},
|
||||
{
|
||||
"name": "illuminate\/container",
|
||||
"version": "v10.45.0",
|
||||
"version_normalized": "10.45.0.0",
|
||||
"version": "v10.45.1",
|
||||
"version_normalized": "10.45.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/illuminate\/container.git",
|
||||
|
@ -561,8 +561,8 @@
|
|||
},
|
||||
{
|
||||
"name": "illuminate\/contracts",
|
||||
"version": "v10.45.0",
|
||||
"version_normalized": "10.45.0.0",
|
||||
"version": "v10.45.1",
|
||||
"version_normalized": "10.45.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/illuminate\/contracts.git",
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue