Skip to content

Commit 19a4c03

Browse files
committed
add is in try block attribute
1 parent 1b0dcb2 commit 19a4c03

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/NodeTypeResolver/Node/AttributeKey.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,6 @@ final class AttributeKey
284284
public const PHP_VERSION_CONDITIONED = 'php_version_conditioned';
285285

286286
public const HAS_CLOSURE_WITH_VARIADIC_ARGS = 'has_closure_with_variadic_args';
287+
288+
public const IS_IN_TRY_BLOCK = 'is_in_try_block';
287289
}

src/PhpParser/NodeVisitor/ContextNodeVisitor.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@
3131
use PhpParser\Node\Stmt\Function_;
3232
use PhpParser\Node\Stmt\If_;
3333
use PhpParser\Node\Stmt\Switch_;
34+
use PhpParser\Node\Stmt\TryCatch;
3435
use PhpParser\Node\Stmt\Unset_;
3536
use PhpParser\Node\Stmt\While_;
3637
use PhpParser\NodeVisitor;
3738
use PhpParser\NodeVisitorAbstract;
3839
use Rector\Contract\PhpParser\DecoratingNodeVisitorInterface;
3940
use Rector\NodeTypeResolver\Node\AttributeKey;
4041
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
42+
use Rector\PhpParser\NodeTraverser\SimpleNodeTraverser;
4143

4244
final class ContextNodeVisitor extends NodeVisitorAbstract implements DecoratingNodeVisitorInterface
4345
{
@@ -66,6 +68,12 @@ public function enterNode(Node $node): ?Node
6668
return null;
6769
}
6870

71+
if ($node instanceof TryCatch) {
72+
SimpleNodeTraverser::decorateWithAttributeValue($node->stmts, AttributeKey::IS_IN_TRY_BLOCK, true);
73+
74+
return null;
75+
}
76+
6977
if ($node instanceof Isset_) {
7078
foreach ($node->vars as $var) {
7179
$var->setAttribute(AttributeKey::IS_ISSET_VAR, true);

0 commit comments

Comments
 (0)