Skip to content

Commit 5bcbbab

Browse files
authored
Merge pull request #13 from smeghead/fix/issue-11
fix: fix empty scope error.
2 parents 50a37c7 + e6d808b commit 5bcbbab

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Fixed command execution to properly return error codes when failures occur
66
* Improved error handling in all command implementations
7+
* fix empty scope error. #11
78

89
## v0.0.4 (2025-03-20)
910

src/Analyze/AnalysisResult.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ public function __construct(
1717
public readonly array $scopes
1818
)
1919
{
20-
$this->maxVariableHardUsage = max(array_map(fn(Scope $scope) => $scope->getVariableHardUsage(), $scopes));
2120
if (count($scopes) === 0) {
21+
$this->maxVariableHardUsage = 0;
2222
$this->avarageVariableHardUsage = 0;
2323
} else {
24+
$this->maxVariableHardUsage = max(array_map(fn(Scope $scope) => $scope->getVariableHardUsage(), $scopes));
2425
$this->avarageVariableHardUsage = array_sum(array_map(fn(Scope $scope) => $scope->getVariableHardUsage(), $scopes)) / count($scopes);
2526
}
2627
}

test/VariableAnalizerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99

1010
class VariableAnalizerTest extends TestCase
1111
{
12+
public function testAnalyzeEmpty(): void
13+
{
14+
$sut = new VariableAnalyzer('target.php', []);
15+
$result = $sut->analyze();
16+
$this->assertSame('target.php', $result->filename);
17+
$scopes = $result->scopes;
18+
19+
$this->assertCount(0, $scopes);
20+
}
21+
1222
public function testAnalyzeFunctionSimple(): void
1323
{
1424
$func = new Func(null, 'testFunction');

0 commit comments

Comments
 (0)