Skip to content

Commit

Permalink
[CodeQuality] skip array + non native response return on ResponseRetu…
Browse files Browse the repository at this point in the history
…rnTypeControllerActionRector (#661)
  • Loading branch information
samsonasik committed Aug 12, 2024
1 parent 54b6049 commit d11e7da
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Rector\Symfony\Tests\CodeQuality\Rector\ClassMethod\ResponseReturnTypeControllerActionRector\Fixture;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Routing\Annotation\Route;

final class SkipPossibleReturnArrayOrResponseNonNative extends AbstractController
{
/**
* @Route("/new", name="some_new")
*
* @Template(template="Foo:Bar:edit.html.twig")
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse|array{x: xy, form: \Symfony\Component\Form\FormView}
*/
public function newAction()
{
$form = $this->createForm(Some::class, $type);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
return $this->someRedirect();
}

return [
'x' => 'xy',
'form' => $form->createView(),
];
}

private function someRedirect()
{
return $this->redirect($this->generateUrl('some'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class TemplateController extends AbstractController
{
#[Route]
#[Template]
public function testDetail(): ?array
public function testDetail(): array
{
return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@ public function refactor(Node $node): ?Node
}
}

$node->returnType = new NullableType(new Identifier('array'));
return $node;
if ($returnType->isArray()->yes()) {
$node->returnType = new Identifier('array');
return $node;
}

return null;
}

return $this->refactorResponse($node);
Expand Down

0 comments on commit d11e7da

Please sign in to comment.