Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions config/sets/symfony/symfony6/symfony61/symfony61-console.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@
use Rector\Symfony\Symfony61\Rector\Class_\CommandPropertyToAttributeRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rules([
CommandConfigureToAttributeRector::class,
CommandPropertyToAttributeRector::class,
]);
$rectorConfig->rules([CommandConfigureToAttributeRector::class, CommandPropertyToAttributeRector::class]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Symfony\Symfony62\Rector\Class_\SecurityAttributeToIsGrantedAttributeRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Symfony\Symfony62\Rector\Class_\SecurityAttributeToIsGrantedAttributeRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(SecurityAttributeToIsGrantedAttributeRector::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Symfony\Symfony63\Rector\Class_\ParamAndEnvAttributeRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Symfony\Symfony63\Rector\Class_\ParamAndEnvAttributeRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rules([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Rector\Renaming\Rector\Name\RenameClassRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
// @see https://github.com/symfony/symfony/blob/7.0/UPGRADE-7.0.md#frameworkbundle
'Symfony\Component\Serializer\Normalizer\ObjectNormalizer' => 'Symfony\Component\Serializer\Normalizer\NormalizerInterface',
'Symfony\Component\Serializer\Normalizer\PropertyNormalizer' => 'Symfony\Component\Serializer\Normalizer\NormalizerInterface',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
'Symfony\Component\DependencyInjection\Attribute\AutowireLocator'
),
]);
};
};
4 changes: 1 addition & 3 deletions config/sets/symfony/symfony7/symfony73/symfony73-console.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@
use Rector\Symfony\Symfony73\Rector\Class_\InvokableCommandInputAttributeRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rules([
CommandHelpToAttributeRector::class, InvokableCommandInputAttributeRector::class
]);
$rectorConfig->rules([CommandHelpToAttributeRector::class, InvokableCommandInputAttributeRector::class]);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace AppBundle\Controller\Attributes;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

final class CleanupArrayReturnShape extends AbstractController
{
/**
* @return array{hello: string}
*/
#[Template("with_some_template.twig")]
public function indexAction()
{
return [
'hello' => 'world'
];
}
}

?>
-----
<?php

namespace AppBundle\Controller\Attributes;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

final class CleanupArrayReturnShape extends AbstractController
{
public function indexAction(): \Symfony\Component\HttpFoundation\Response
{
return $this->render('with_some_template.twig', [
'hello' => 'world'
]);
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Return_;
use PhpParser\NodeVisitor;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode;
use PHPStan\Type\ArrayType;
use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
Expand Down Expand Up @@ -176,7 +179,7 @@ private function replaceTemplateAnnotation(
return $this->refactorClassMethod($classMethod, $doctrineAnnotationTagValueNode ?: $templateAttribute);
}

// global @Template access
// global @Template/#[Template] access
if ($classTagValueNodeOrAttribute instanceof DoctrineAnnotationTagValueNode || $classTagValueNodeOrAttribute instanceof Attribute) {
return $this->refactorClassMethod($classMethod, $classTagValueNodeOrAttribute);
}
Expand Down Expand Up @@ -221,6 +224,9 @@ private function refactorClassMethod(
return null;
});

// remove return array shape details
$this->removeReturnArrayShapeDocblock($classMethod);

if (! $this->emptyReturnNodeFinder->hasNoOrEmptyReturns($classMethod)) {
return $hasChanged;
}
Expand Down Expand Up @@ -393,4 +399,25 @@ private function refactorStmtsAwareNode(
}
return $hasChanged;
}

private function removeReturnArrayShapeDocblock(ClassMethod $classMethod): void
{
$classMethodPhpDocInfo = $this->phpDocInfoFactory->createFromNode($classMethod);
if (! $classMethodPhpDocInfo instanceof PhpDocInfo) {
return;
}

$returnTagValueNode = $classMethodPhpDocInfo->getReturnTagValue();
if (! $returnTagValueNode instanceof ReturnTagValueNode) {
return;
}

if (! $returnTagValueNode->type instanceof ArrayShapeNode) {
return;
}

if ($classMethodPhpDocInfo->removeByName('@return')) {
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($classMethod);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Sensio\Bundle\FrameworkExtraBundle\Configuration;

#[\Attribute]
class Template
{
}
Loading