From cb2b3def03545cf07083168dfe1e92d6b65cc68a Mon Sep 17 00:00:00 2001 From: hirokinoue <70567194+hirokinoue@users.noreply.github.com> Date: Fri, 21 Mar 2025 22:01:24 +0900 Subject: [PATCH 1/2] Add test case --- test/VariableParserTest.php | 5 ++++- test/fixtures/assign_operator.php | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/test/VariableParserTest.php b/test/VariableParserTest.php index 056e1f3..834a7a4 100644 --- a/test/VariableParserTest.php +++ b/test/VariableParserTest.php @@ -107,7 +107,7 @@ public function testParseAssignOperator(): void $functions = $result->functions; $this->assertCount(1, $functions); $this->assertSame('assignFunction', $functions[0]->name); - $this->assertCount(14, $functions[0]->getVariables()); + $this->assertCount(15, $functions[0]->getVariables()); $vars = $functions[0]->getVariables(); $this->assertSame('num', $vars[0]->name); @@ -152,6 +152,9 @@ public function testParseAssignOperator(): void $this->assertSame('num', $vars[13]->name); $this->assertSame(18, $vars[13]->lineNumber); $this->assertSame(true, $vars[13]->assigned); + $this->assertSame('num', $vars[14]->name); + $this->assertSame(19, $vars[14]->lineNumber); + $this->assertSame(true, $vars[14]->assigned); } public function testInterpolatedStringFunction(): void diff --git a/test/fixtures/assign_operator.php b/test/fixtures/assign_operator.php index dea25bc..74464ff 100644 --- a/test/fixtures/assign_operator.php +++ b/test/fixtures/assign_operator.php @@ -16,4 +16,5 @@ function assignFunction(): void $num >>= 1; // 16行目 $num .= 1; // 17行目 $num ??= 1; // 18行目 + $num =& f(); // 19行目 } \ No newline at end of file From 02a03995175b3ac327f9128bf07e5b7ed948237c Mon Sep 17 00:00:00 2001 From: hirokinoue <70567194+hirokinoue@users.noreply.github.com> Date: Fri, 21 Mar 2025 22:15:17 +0900 Subject: [PATCH 2/2] feat: Consider AssignRef as assignment --- src/Parse/Visitor/FunctionLikeFindingVisitor.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Parse/Visitor/FunctionLikeFindingVisitor.php b/src/Parse/Visitor/FunctionLikeFindingVisitor.php index fa36717..310051f 100644 --- a/src/Parse/Visitor/FunctionLikeFindingVisitor.php +++ b/src/Parse/Visitor/FunctionLikeFindingVisitor.php @@ -7,6 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\AssignOp; +use PhpParser\Node\Expr\AssignRef; use PhpParser\Node\FunctionLike; use PhpParser\NodeVisitor\FindingVisitor; use PhpParser\Node\Stmt\Class_; @@ -31,8 +32,10 @@ public function enterNode(Node $node) { // Record class name $this->currentNamespace = $node->name ? $node->name->name : null; } - - if ($node instanceof Assign || $node instanceof AssignOp) { + if ($node instanceof Assign || + $node instanceof AssignOp || + $node instanceof AssignRef + ) { $node->var->setAttribute('assigned', true); // Mark as assigned } if ($node instanceof FunctionLike) {