Skip to content

Commit

Permalink
[CodeQuality] Handle crash inside block statement with unreachable st…
Browse files Browse the repository at this point in the history
…atement on OptionalParametersAfterRequiredRector (#6640)
  • Loading branch information
samsonasik authored Jan 1, 2025
1 parent c20860d commit f3242bf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector\Fixture;

class SkipInsideBlockStatements
{
private function handlePlugin(Request $request)
{
{
$form = $this->createForm(ArticleFormType::class, $article);
return $this->render('Article/edit.html.twig', [
'media' => $media,
'form' => $form->createView(),
'headline' => $headline,
'article' => $article
]);

$form = $this->createForm(HeadlineType::class, $headline);
return $this->render('headline/new.html.twig', [
'headline' => $headline,
'media' => $media,
'form' => $form->createView(),
]);
}
}
}
3 changes: 2 additions & 1 deletion src/Application/NodeAttributeReIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PhpParser\Node\Expr\NullsafeMethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt\Block;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Declare_;
Expand All @@ -27,7 +28,7 @@ final class NodeAttributeReIndexer
{
public static function reIndexStmtKeyNodeAttributes(Node $node): ?Node
{
if (! $node instanceof StmtsAwareInterface && ! $node instanceof ClassLike && ! $node instanceof Declare_) {
if (! $node instanceof StmtsAwareInterface && ! $node instanceof ClassLike && ! $node instanceof Declare_ && ! $node instanceof Block) {
return null;
}

Expand Down
3 changes: 2 additions & 1 deletion src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\PHPStan\NodeVisitor;

use PhpParser\Node;
use PhpParser\Node\Stmt\Block;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\Declare_;
use PhpParser\NodeVisitorAbstract;
Expand All @@ -25,7 +26,7 @@ public function __construct(

public function enterNode(Node $node): ?Node
{
if (! $node instanceof StmtsAwareInterface && ! $node instanceof ClassLike && ! $node instanceof Declare_) {
if (! $node instanceof StmtsAwareInterface && ! $node instanceof ClassLike && ! $node instanceof Declare_ && ! $node instanceof Block) {
return null;
}

Expand Down

0 comments on commit f3242bf

Please sign in to comment.