Skip to content

Commit

Permalink
Updated Rector to commit 1ebb7aa29bfff54059d455ee6f908fa47a7416c3
Browse files Browse the repository at this point in the history
rectorphp/rector-src@1ebb7aa [CodeQuality] Allow transform static to self on final class on ConvertStaticPrivateConstantToSelfRector (#6295)
  • Loading branch information
TomasVotruba committed Sep 8, 2024
1 parent 7d52cf2 commit 9c002d1
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 33 deletions.
8 changes: 4 additions & 4 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -1877,12 +1877,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "49e82cc11057193c840821d8602c1144869b9c8a"
"reference": "2d6a8ca3ca18dd0bbd64d5f793fb1b68444f48cc"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/49e82cc11057193c840821d8602c1144869b9c8a",
"reference": "49e82cc11057193c840821d8602c1144869b9c8a",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/2d6a8ca3ca18dd0bbd64d5f793fb1b68444f48cc",
"reference": "2d6a8ca3ca18dd0bbd64d5f793fb1b68444f48cc",
"shasum": ""
},
"require": {
Expand Down Expand Up @@ -1912,7 +1912,7 @@
"tomasvotruba\/unused-public": "^0.3.10",
"tracy\/tracy": "^2.10"
},
"time": "2024-09-02T10:41:34+00:00",
"time": "2024-09-08T17:10:25+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
Expand Down
2 changes: 1 addition & 1 deletion vendor/composer/installed.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vendor/rector/extension-installer/src/GeneratedConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main fb26209'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main cfebdb1'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 93a04b0'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 49e82cc'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main fb26209'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main cfebdb1'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 93a04b0'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 2d6a8ca'));
private function __construct()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,44 +132,65 @@ public function indexAction()
*/
public function getNodeTypes() : array
{
return [ClassMethod::class, Class_::class];
return [Class_::class];
}
/**
* @param Class_|ClassMethod $node
* @param Class_ $node
*/
public function refactor(Node $node) : ?Node
{
if ($node instanceof Class_) {
return $this->addAbstractControllerParentClassIfMissing($node);
if (!$this->annotationAnalyzer->hasClassMethodWithTemplateAnnotation($node)) {
return null;
}
$this->decorateAbstractControllerParentClass($node);
$hasChanged = \false;
$classDoctrineAnnotationTagValueNode = $this->annotationAnalyzer->getDoctrineAnnotationTagValueNode($node, SymfonyAnnotation::TEMPLATE);
foreach ($node->getMethods() as $classMethod) {
if (!$classMethod->isPublic()) {
continue;
}
$hasClassMethodChanged = $this->replaceTemplateAnnotation($classMethod, $classDoctrineAnnotationTagValueNode);
if ($hasClassMethodChanged) {
$hasChanged = \true;
}
}
return $this->replaceTemplateAnnotation($node);
if (!$hasChanged) {
return null;
}
// cleanup Class_ @Template annotaion
if ($classDoctrineAnnotationTagValueNode instanceof DoctrineAnnotationTagValueNode) {
$this->removeDoctrineAnnotationTagValueNode($node, $classDoctrineAnnotationTagValueNode);
}
return $node;
}
private function addAbstractControllerParentClassIfMissing(Class_ $class) : ?Class_
private function decorateAbstractControllerParentClass(Class_ $class) : void
{
if ($class->extends instanceof Name) {
return null;
}
if (!$this->annotationAnalyzer->hasClassMethodWithTemplateAnnotation($class)) {
return null;
return;
}
// this will make $this->render() method available
$class->extends = new FullyQualified('Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController');
return $class;
}
private function replaceTemplateAnnotation(ClassMethod $classMethod) : ?ClassMethod
private function replaceTemplateAnnotation(ClassMethod $classMethod, ?DoctrineAnnotationTagValueNode $classDoctrineAnnotationTagValueNode) : bool
{
if (!$classMethod->isPublic()) {
return null;
return \false;
}
$doctrineAnnotationTagValueNode = $this->annotationAnalyzer->getDoctrineAnnotationTagValueNode($classMethod, SymfonyAnnotation::TEMPLATE);
if (!$doctrineAnnotationTagValueNode instanceof DoctrineAnnotationTagValueNode) {
return null;
if ($doctrineAnnotationTagValueNode instanceof DoctrineAnnotationTagValueNode) {
return $this->refactorClassMethod($classMethod, $doctrineAnnotationTagValueNode);
}
return $this->refactorClassMethod($classMethod, $doctrineAnnotationTagValueNode);
// global @Template access
if ($classDoctrineAnnotationTagValueNode instanceof DoctrineAnnotationTagValueNode) {
return $this->refactorClassMethod($classMethod, $classDoctrineAnnotationTagValueNode);
}
return \false;
}
private function refactorClassMethod(ClassMethod $classMethod, DoctrineAnnotationTagValueNode $templateDoctrineAnnotationTagValueNode) : ?ClassMethod
private function refactorClassMethod(ClassMethod $classMethod, DoctrineAnnotationTagValueNode $templateDoctrineAnnotationTagValueNode) : bool
{
$hasThisRenderOrReturnsResponse = $this->hasLastReturnResponse($classMethod);
$this->traverseNodesWithCallable($classMethod, function (Node $node) use($templateDoctrineAnnotationTagValueNode, $hasThisRenderOrReturnsResponse, $classMethod) : ?int {
$hasChanged = \false;
$this->traverseNodesWithCallable($classMethod, function (Node $node) use($templateDoctrineAnnotationTagValueNode, $hasThisRenderOrReturnsResponse, $classMethod, &$hasChanged) : ?int {
// keep as similar type
if ($node instanceof Closure || $node instanceof Function_) {
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
Expand All @@ -178,14 +199,15 @@ private function refactorClassMethod(ClassMethod $classMethod, DoctrineAnnotatio
return null;
}
$this->refactorStmtsAwareNode($node, $templateDoctrineAnnotationTagValueNode, $hasThisRenderOrReturnsResponse, $classMethod);
$hasChanged = \true;
return null;
});
if (!$this->emptyReturnNodeFinder->hasNoOrEmptyReturns($classMethod)) {
return null;
return $hasChanged;
}
$thisRenderMethodCall = $this->thisRenderFactory->create(null, $templateDoctrineAnnotationTagValueNode, $classMethod);
$this->refactorNoReturn($classMethod, $thisRenderMethodCall, $templateDoctrineAnnotationTagValueNode);
return $classMethod;
return \true;
}
private function hasLastReturnResponse(ClassMethod $classMethod) : bool
{
Expand Down Expand Up @@ -242,11 +264,14 @@ private function refactorReturnWithValue(Return_ $return, bool $hasThisRenderOrR
$this->removeDoctrineAnnotationTagValueNode($classMethod, $doctrineAnnotationTagValueNode);
$this->returnTypeDeclarationUpdater->updateClassMethod($classMethod, SymfonyClass::RESPONSE);
}
private function removeDoctrineAnnotationTagValueNode(ClassMethod $classMethod, DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode) : void
/**
* @param \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\ClassMethod $node
*/
private function removeDoctrineAnnotationTagValueNode($node, DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode) : void
{
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
$this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $doctrineAnnotationTagValueNode);
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($classMethod);
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node);
}
private function refactorStmtsAwareNode(StmtsAwareInterface $stmtsAware, DoctrineAnnotationTagValueNode $templateDoctrineAnnotationTagValueNode, bool $hasThisRenderOrReturnsResponse, ClassMethod $classMethod) : void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
final class ParameterBagToAutowireAttributeRector extends AbstractRector implements MinPhpVersionInterface
{
/**
* @readonly
* @var \Rector\Symfony\Configs\NodeFactory\AutowiredParamFactory
*/
private $autowiredParamFactory;
Expand Down
15 changes: 11 additions & 4 deletions vendor/rector/rector-symfony/src/Annotation/AnnotationAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,24 @@ public function __construct(PhpDocInfoFactory $phpDocInfoFactory)
}
public function hasClassMethodWithTemplateAnnotation(Class_ $class) : bool
{
$classTemplateAnnotation = $this->getDoctrineAnnotationTagValueNode($class, SymfonyAnnotation::TEMPLATE);
if ($classTemplateAnnotation instanceof DoctrineAnnotationTagValueNode) {
return \true;
}
foreach ($class->getMethods() as $classMethod) {
$templateDoctrineAnnotationTagValueNode = $this->getDoctrineAnnotationTagValueNode($classMethod, SymfonyAnnotation::TEMPLATE);
if ($templateDoctrineAnnotationTagValueNode instanceof DoctrineAnnotationTagValueNode) {
$classMethodTemplateAnnotation = $this->getDoctrineAnnotationTagValueNode($classMethod, SymfonyAnnotation::TEMPLATE);
if ($classMethodTemplateAnnotation instanceof DoctrineAnnotationTagValueNode) {
return \true;
}
}
return \false;
}
public function getDoctrineAnnotationTagValueNode(ClassMethod $classMethod, string $annotationClass) : ?DoctrineAnnotationTagValueNode
/**
* @param \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\ClassMethod $node
*/
public function getDoctrineAnnotationTagValueNode($node, string $annotationClass) : ?DoctrineAnnotationTagValueNode
{
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($classMethod);
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($node);
if (!$phpDocInfo instanceof PhpDocInfo) {
return null;
}
Expand Down

0 comments on commit 9c002d1

Please sign in to comment.