Skip to content

Commit 2a72504

Browse files
committed
Improve property hook checks and enhance node handling in PropertyHookInjector
1 parent 437d369 commit 2a72504

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

src/Internal/Visitor/PropertyHookInjector.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class PropertyHookInjector
1616
{
1717
public static function process(Node\Stmt\Property $node): void
1818
{
19-
if ($node->hooks === []) {
19+
if (! isset($node->hooks) || ! \is_array($node->hooks) || $node->hooks === []) {
2020
return;
2121
}
2222

@@ -76,15 +76,15 @@ public function __construct(private string $propertyName)
7676
{
7777
}
7878

79-
public function enterNode(Node $n): int|null
79+
public function enterNode(Node $node): int|null
8080
{
81-
if ($n instanceof Node\Expr\Closure || $n instanceof Node\Expr\ArrowFunction || $n instanceof Node\Stmt\Function_ || $n instanceof Node\Stmt\ClassMethod) {
81+
if ($node instanceof Node\Expr\Closure || $node instanceof Node\Expr\ArrowFunction || $node instanceof Node\Stmt\Function_ || $node instanceof Node\Stmt\ClassMethod) {
8282
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
8383
}
8484

85-
if ($n instanceof Node\Stmt\Return_ && $n->expr !== null) {
86-
$checkCall = NodeBuilder::createPropertyCheckCall($n->expr, new Node\Expr\Variable('this'), $this->propertyName);
87-
$n->expr = NodeBuilder::createTernaryThrowExpr($checkCall);
85+
if ($node instanceof Node\Stmt\Return_ && $node->expr !== null) {
86+
$checkCall = NodeBuilder::createPropertyCheckCall($node->expr, new Node\Expr\Variable('this'), $this->propertyName);
87+
$node->expr = NodeBuilder::createTernaryThrowExpr($checkCall);
8888
}
8989

9090
return null;
@@ -96,4 +96,4 @@ public function enterNode(Node $n): int|null
9696

9797
return $newStmts;
9898
}
99-
}
99+
}

0 commit comments

Comments
 (0)