Skip to content

Commit 9c002d1

Browse files
committed
Updated Rector to commit 1ebb7aa29bfff54059d455ee6f908fa47a7416c3
rectorphp/rector-src@1ebb7aa [CodeQuality] Allow transform static to self on final class on ConvertStaticPrivateConstantToSelfRector (#6295)
1 parent 7d52cf2 commit 9c002d1

File tree

6 files changed

+66
-33
lines changed

6 files changed

+66
-33
lines changed

vendor/composer/installed.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,12 +1877,12 @@
18771877
"source": {
18781878
"type": "git",
18791879
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
1880-
"reference": "49e82cc11057193c840821d8602c1144869b9c8a"
1880+
"reference": "2d6a8ca3ca18dd0bbd64d5f793fb1b68444f48cc"
18811881
},
18821882
"dist": {
18831883
"type": "zip",
1884-
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/49e82cc11057193c840821d8602c1144869b9c8a",
1885-
"reference": "49e82cc11057193c840821d8602c1144869b9c8a",
1884+
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/2d6a8ca3ca18dd0bbd64d5f793fb1b68444f48cc",
1885+
"reference": "2d6a8ca3ca18dd0bbd64d5f793fb1b68444f48cc",
18861886
"shasum": ""
18871887
},
18881888
"require": {
@@ -1912,7 +1912,7 @@
19121912
"tomasvotruba\/unused-public": "^0.3.10",
19131913
"tracy\/tracy": "^2.10"
19141914
},
1915-
"time": "2024-09-02T10:41:34+00:00",
1915+
"time": "2024-09-08T17:10:25+00:00",
19161916
"default-branch": true,
19171917
"type": "rector-extension",
19181918
"extra": {

vendor/composer/installed.php

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

vendor/rector/extension-installer/src/GeneratedConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
final class GeneratedConfig
1111
{
12-
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'));
12+
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'));
1313
private function __construct()
1414
{
1515
}

vendor/rector/rector-symfony/rules/CodeQuality/Rector/ClassMethod/TemplateAnnotationToThisRenderRector.php

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -132,44 +132,65 @@ public function indexAction()
132132
*/
133133
public function getNodeTypes() : array
134134
{
135-
return [ClassMethod::class, Class_::class];
135+
return [Class_::class];
136136
}
137137
/**
138-
* @param Class_|ClassMethod $node
138+
* @param Class_ $node
139139
*/
140140
public function refactor(Node $node) : ?Node
141141
{
142-
if ($node instanceof Class_) {
143-
return $this->addAbstractControllerParentClassIfMissing($node);
142+
if (!$this->annotationAnalyzer->hasClassMethodWithTemplateAnnotation($node)) {
143+
return null;
144+
}
145+
$this->decorateAbstractControllerParentClass($node);
146+
$hasChanged = \false;
147+
$classDoctrineAnnotationTagValueNode = $this->annotationAnalyzer->getDoctrineAnnotationTagValueNode($node, SymfonyAnnotation::TEMPLATE);
148+
foreach ($node->getMethods() as $classMethod) {
149+
if (!$classMethod->isPublic()) {
150+
continue;
151+
}
152+
$hasClassMethodChanged = $this->replaceTemplateAnnotation($classMethod, $classDoctrineAnnotationTagValueNode);
153+
if ($hasClassMethodChanged) {
154+
$hasChanged = \true;
155+
}
144156
}
145-
return $this->replaceTemplateAnnotation($node);
157+
if (!$hasChanged) {
158+
return null;
159+
}
160+
// cleanup Class_ @Template annotaion
161+
if ($classDoctrineAnnotationTagValueNode instanceof DoctrineAnnotationTagValueNode) {
162+
$this->removeDoctrineAnnotationTagValueNode($node, $classDoctrineAnnotationTagValueNode);
163+
}
164+
return $node;
146165
}
147-
private function addAbstractControllerParentClassIfMissing(Class_ $class) : ?Class_
166+
private function decorateAbstractControllerParentClass(Class_ $class) : void
148167
{
149168
if ($class->extends instanceof Name) {
150-
return null;
151-
}
152-
if (!$this->annotationAnalyzer->hasClassMethodWithTemplateAnnotation($class)) {
153-
return null;
169+
return;
154170
}
171+
// this will make $this->render() method available
155172
$class->extends = new FullyQualified('Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController');
156-
return $class;
157173
}
158-
private function replaceTemplateAnnotation(ClassMethod $classMethod) : ?ClassMethod
174+
private function replaceTemplateAnnotation(ClassMethod $classMethod, ?DoctrineAnnotationTagValueNode $classDoctrineAnnotationTagValueNode) : bool
159175
{
160176
if (!$classMethod->isPublic()) {
161-
return null;
177+
return \false;
162178
}
163179
$doctrineAnnotationTagValueNode = $this->annotationAnalyzer->getDoctrineAnnotationTagValueNode($classMethod, SymfonyAnnotation::TEMPLATE);
164-
if (!$doctrineAnnotationTagValueNode instanceof DoctrineAnnotationTagValueNode) {
165-
return null;
180+
if ($doctrineAnnotationTagValueNode instanceof DoctrineAnnotationTagValueNode) {
181+
return $this->refactorClassMethod($classMethod, $doctrineAnnotationTagValueNode);
166182
}
167-
return $this->refactorClassMethod($classMethod, $doctrineAnnotationTagValueNode);
183+
// global @Template access
184+
if ($classDoctrineAnnotationTagValueNode instanceof DoctrineAnnotationTagValueNode) {
185+
return $this->refactorClassMethod($classMethod, $classDoctrineAnnotationTagValueNode);
186+
}
187+
return \false;
168188
}
169-
private function refactorClassMethod(ClassMethod $classMethod, DoctrineAnnotationTagValueNode $templateDoctrineAnnotationTagValueNode) : ?ClassMethod
189+
private function refactorClassMethod(ClassMethod $classMethod, DoctrineAnnotationTagValueNode $templateDoctrineAnnotationTagValueNode) : bool
170190
{
171191
$hasThisRenderOrReturnsResponse = $this->hasLastReturnResponse($classMethod);
172-
$this->traverseNodesWithCallable($classMethod, function (Node $node) use($templateDoctrineAnnotationTagValueNode, $hasThisRenderOrReturnsResponse, $classMethod) : ?int {
192+
$hasChanged = \false;
193+
$this->traverseNodesWithCallable($classMethod, function (Node $node) use($templateDoctrineAnnotationTagValueNode, $hasThisRenderOrReturnsResponse, $classMethod, &$hasChanged) : ?int {
173194
// keep as similar type
174195
if ($node instanceof Closure || $node instanceof Function_) {
175196
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
@@ -178,14 +199,15 @@ private function refactorClassMethod(ClassMethod $classMethod, DoctrineAnnotatio
178199
return null;
179200
}
180201
$this->refactorStmtsAwareNode($node, $templateDoctrineAnnotationTagValueNode, $hasThisRenderOrReturnsResponse, $classMethod);
202+
$hasChanged = \true;
181203
return null;
182204
});
183205
if (!$this->emptyReturnNodeFinder->hasNoOrEmptyReturns($classMethod)) {
184-
return null;
206+
return $hasChanged;
185207
}
186208
$thisRenderMethodCall = $this->thisRenderFactory->create(null, $templateDoctrineAnnotationTagValueNode, $classMethod);
187209
$this->refactorNoReturn($classMethod, $thisRenderMethodCall, $templateDoctrineAnnotationTagValueNode);
188-
return $classMethod;
210+
return \true;
189211
}
190212
private function hasLastReturnResponse(ClassMethod $classMethod) : bool
191213
{
@@ -242,11 +264,14 @@ private function refactorReturnWithValue(Return_ $return, bool $hasThisRenderOrR
242264
$this->removeDoctrineAnnotationTagValueNode($classMethod, $doctrineAnnotationTagValueNode);
243265
$this->returnTypeDeclarationUpdater->updateClassMethod($classMethod, SymfonyClass::RESPONSE);
244266
}
245-
private function removeDoctrineAnnotationTagValueNode(ClassMethod $classMethod, DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode) : void
267+
/**
268+
* @param \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\ClassMethod $node
269+
*/
270+
private function removeDoctrineAnnotationTagValueNode($node, DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode) : void
246271
{
247-
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);
272+
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
248273
$this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $doctrineAnnotationTagValueNode);
249-
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($classMethod);
274+
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node);
250275
}
251276
private function refactorStmtsAwareNode(StmtsAwareInterface $stmtsAware, DoctrineAnnotationTagValueNode $templateDoctrineAnnotationTagValueNode, bool $hasThisRenderOrReturnsResponse, ClassMethod $classMethod) : void
252277
{

vendor/rector/rector-symfony/rules/Configs/Rector/Class_/ParameterBagToAutowireAttributeRector.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
final class ParameterBagToAutowireAttributeRector extends AbstractRector implements MinPhpVersionInterface
2828
{
2929
/**
30+
* @readonly
3031
* @var \Rector\Symfony\Configs\NodeFactory\AutowiredParamFactory
3132
*/
3233
private $autowiredParamFactory;

vendor/rector/rector-symfony/src/Annotation/AnnotationAnalyzer.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,24 @@ public function __construct(PhpDocInfoFactory $phpDocInfoFactory)
2222
}
2323
public function hasClassMethodWithTemplateAnnotation(Class_ $class) : bool
2424
{
25+
$classTemplateAnnotation = $this->getDoctrineAnnotationTagValueNode($class, SymfonyAnnotation::TEMPLATE);
26+
if ($classTemplateAnnotation instanceof DoctrineAnnotationTagValueNode) {
27+
return \true;
28+
}
2529
foreach ($class->getMethods() as $classMethod) {
26-
$templateDoctrineAnnotationTagValueNode = $this->getDoctrineAnnotationTagValueNode($classMethod, SymfonyAnnotation::TEMPLATE);
27-
if ($templateDoctrineAnnotationTagValueNode instanceof DoctrineAnnotationTagValueNode) {
30+
$classMethodTemplateAnnotation = $this->getDoctrineAnnotationTagValueNode($classMethod, SymfonyAnnotation::TEMPLATE);
31+
if ($classMethodTemplateAnnotation instanceof DoctrineAnnotationTagValueNode) {
2832
return \true;
2933
}
3034
}
3135
return \false;
3236
}
33-
public function getDoctrineAnnotationTagValueNode(ClassMethod $classMethod, string $annotationClass) : ?DoctrineAnnotationTagValueNode
37+
/**
38+
* @param \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\ClassMethod $node
39+
*/
40+
public function getDoctrineAnnotationTagValueNode($node, string $annotationClass) : ?DoctrineAnnotationTagValueNode
3441
{
35-
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($classMethod);
42+
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($node);
3643
if (!$phpDocInfo instanceof PhpDocInfo) {
3744
return null;
3845
}

0 commit comments

Comments
 (0)