-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alexander Busygin
committed
Jan 21, 2022
1 parent
c172050
commit 1218179
Showing
2 changed files
with
80 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Qossmic\Deptrac\DependencyEmitter; | ||
|
||
class FQDNIndexNode | ||
{ | ||
private bool $FQDN = false; | ||
|
||
/** | ||
* @var array<string, FQDNIndexNode> | ||
*/ | ||
private array $nodes = []; | ||
|
||
public function isFQDN(): bool | ||
{ | ||
return $this->FQDN; | ||
} | ||
|
||
/** | ||
* @param string[] $keys | ||
*/ | ||
public function getNestedNode(array $keys): ?self | ||
{ | ||
$index = $this; | ||
foreach ($keys as $key) { | ||
$node = $index->nodes[$key] ?? null; | ||
if (null === $node) { | ||
return null; | ||
} | ||
|
||
$index = $node; | ||
} | ||
|
||
return $index; | ||
} | ||
|
||
/** | ||
* @param string[] $keys | ||
*/ | ||
public function setNestedNode(array $keys): void | ||
{ | ||
if (0 === count($keys)) { | ||
$this->FQDN = true; | ||
|
||
return; | ||
} | ||
|
||
$key = array_shift($keys); | ||
$node = $this->nodes[$key] ?? null; | ||
if (null === $node) { | ||
$node = new self(); | ||
$this->nodes[$key] = $node; | ||
} | ||
|
||
$node->setNestedNode($keys); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters