Skip to content

Commit

Permalink
refactor: コードのリズムを整える
Browse files Browse the repository at this point in the history
  • Loading branch information
hirokinoue committed Mar 5, 2024
1 parent eed4759 commit 5a846e7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/DiagramUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function subClasses(): array {

public function shouldStopTraverse(): bool
{
return $this->isEndOfAnalysis() || $this->layer === Config::maxDepth();
return $this->isEndOfAnalysis() || $this->hasReachedMaxDepth() || $this->hasBeenVisited();
}

private function isEndOfAnalysis(): bool
Expand All @@ -85,6 +85,11 @@ private function isEndOfAnalysis(): bool
return false;
}

private function hasReachedMaxDepth(): bool
{
return $this->layer === Config::maxDepth();
}

private function hasBeenPushed(DiagramUnit $other): bool
{
foreach ($this->classesDirectlyDependsOn as $diagramUnit) {
Expand All @@ -95,7 +100,7 @@ private function hasBeenPushed(DiagramUnit $other): bool
return false;
}

public function hasBeenVisited(): bool
private function hasBeenVisited(): bool
{
if (in_array($this->fullyQualifiedClassName, self::$visitedClasses)) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/Visitor/ClassVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function enterNode(Node $node) {
);
$this->diagramUnit->push($subClass);

if ($stmts === [] || $classFile->notLoaded() || $subClass->hasBeenVisited() || $subClass->shouldStopTraverse()) {
if ($stmts === [] || $classFile->notLoaded() || $subClass->shouldStopTraverse()) {
return $node;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/DiagramUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ public function test解析したことのあるクラスを再び解析しない
);

// when1
$shouldStop = $sut->hasBeenVisited();
$shouldStop = $sut->shouldStopTraverse();

// then1
$this->assertFalse($shouldStop);

// when2
$sut->registerVisitedClass();
$shouldStop = $sut->hasBeenVisited();
$shouldStop = $sut->shouldStopTraverse();

// then2
$this->assertTrue($shouldStop);
Expand Down

0 comments on commit 5a846e7

Please sign in to comment.