Skip to content

Commit f3242bf

Browse files
authored
[CodeQuality] Handle crash inside block statement with unreachable statement on OptionalParametersAfterRequiredRector (#6640)
1 parent c20860d commit f3242bf

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector\Fixture;
6+
7+
class SkipInsideBlockStatements
8+
{
9+
private function handlePlugin(Request $request)
10+
{
11+
{
12+
$form = $this->createForm(ArticleFormType::class, $article);
13+
return $this->render('Article/edit.html.twig', [
14+
'media' => $media,
15+
'form' => $form->createView(),
16+
'headline' => $headline,
17+
'article' => $article
18+
]);
19+
20+
$form = $this->createForm(HeadlineType::class, $headline);
21+
return $this->render('headline/new.html.twig', [
22+
'headline' => $headline,
23+
'media' => $media,
24+
'form' => $form->createView(),
25+
]);
26+
}
27+
}
28+
}

src/Application/NodeAttributeReIndexer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use PhpParser\Node\Expr\NullsafeMethodCall;
1414
use PhpParser\Node\Expr\StaticCall;
1515
use PhpParser\Node\FunctionLike;
16+
use PhpParser\Node\Stmt\Block;
1617
use PhpParser\Node\Stmt\ClassLike;
1718
use PhpParser\Node\Stmt\ClassMethod;
1819
use PhpParser\Node\Stmt\Declare_;
@@ -27,7 +28,7 @@ final class NodeAttributeReIndexer
2728
{
2829
public static function reIndexStmtKeyNodeAttributes(Node $node): ?Node
2930
{
30-
if (! $node instanceof StmtsAwareInterface && ! $node instanceof ClassLike && ! $node instanceof Declare_) {
31+
if (! $node instanceof StmtsAwareInterface && ! $node instanceof ClassLike && ! $node instanceof Declare_ && ! $node instanceof Block) {
3132
return null;
3233
}
3334

src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Rector\PHPStan\NodeVisitor;
66

77
use PhpParser\Node;
8+
use PhpParser\Node\Stmt\Block;
89
use PhpParser\Node\Stmt\ClassLike;
910
use PhpParser\Node\Stmt\Declare_;
1011
use PhpParser\NodeVisitorAbstract;
@@ -25,7 +26,7 @@ public function __construct(
2526

2627
public function enterNode(Node $node): ?Node
2728
{
28-
if (! $node instanceof StmtsAwareInterface && ! $node instanceof ClassLike && ! $node instanceof Declare_) {
29+
if (! $node instanceof StmtsAwareInterface && ! $node instanceof ClassLike && ! $node instanceof Declare_ && ! $node instanceof Block) {
2930
return null;
3031
}
3132

0 commit comments

Comments
 (0)