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
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace AppBundle\Controller;

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

final class RemoveDoubleReturn extends AbstractController
{
/**
* @Template("AppBundle:Module:next.html.twig")
*
* @return Response
*
* @return array
*/
public function indexAction(): array
{
return [];
}
}

?>
-----
<?php

namespace AppBundle\Controller;

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

final class RemoveDoubleReturn extends AbstractController
{
public function indexAction(): \Symfony\Component\HttpFoundation\Response
{
return $this->render('AppBundle:Module:next.html.twig');
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

final class WithArrayReturnType extends AbstractController
{
/**
* @return \Symfony\Component\HttpFoundation\Response
*/
public function indexAction(): \Symfony\Component\HttpFoundation\Response
{
return $this->render('AppBundle:Module:index.html.twig');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ use Symfony\Component\HttpFoundation\Response;

final class ClassWithReturnTypes extends AbstractController
{
/**
* @return \Symfony\Component\HttpFoundation\Response
*/
public function index2Action(): \Symfony\Component\HttpFoundation\Response
{
if (true) {
Expand All @@ -57,9 +54,6 @@ final class ClassWithReturnTypes extends AbstractController
return $this->render('AppBundle:Module:index2.html.twig');
}

/**
* @return Response
*/
public function index3Action(): Response
{
return $this->render('AppBundle:Module:index3.html.twig');
Expand Down
25 changes: 3 additions & 22 deletions src/TypeDeclaration/ReturnTypeDeclarationUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
use PHPStan\Type\ArrayType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\UnionType;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\BetterPhpDocParser\ValueObject\Type\FullyQualifiedIdentifierTypeNode;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\Php\PhpVersionProvider;
use Rector\StaticTypeMapper\StaticTypeMapper;
Expand All @@ -33,30 +30,14 @@ public function __construct(
*/
public function updateClassMethod(ClassMethod $classMethod, string $className): void
{
$this->updatePhpDoc($classMethod, $className);
$this->removeReturnDocBlocks($classMethod);
$this->updatePhp($classMethod, $className);
}

/**
* @param class-string $className
*/
private function updatePhpDoc(ClassMethod $classMethod, string $className): void
private function removeReturnDocBlocks(ClassMethod $classMethod): void
{
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);

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

$returnStaticType = $this->staticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType(
$returnTagValueNode->type,
$classMethod
);

if ($returnStaticType instanceof ArrayType || $returnStaticType instanceof UnionType) {
$returnTagValueNode->type = new FullyQualifiedIdentifierTypeNode($className);
}
$phpDocInfo->removeByType(ReturnTagValueNode::class);

$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($classMethod);
}
Expand Down