Skip to content

Commit

Permalink
almost there
Browse files Browse the repository at this point in the history
  • Loading branch information
dakujem committed Jan 15, 2024
1 parent 5165395 commit 9c61b53
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
use Dakujem\Oliva\TreeNodeContract;

/**
* A tree built from flat data.
* A wrapper structure containing a tree built from flat data as well as its shadow tree.
*
* This structure allows for data inspection, data correction or debugging
* and is not directly intended to be used in applications.
*
* @author Andrej Rypak <xrypak@gmail.com>
*/
class Tree
class AlmostThere
{
public function __construct(
private ?TreeNodeContract $root,
Expand Down
10 changes: 5 additions & 5 deletions src/MaterializedPath/TreeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Dakujem\Oliva\MaterializedPath\Support\Register;
use Dakujem\Oliva\MaterializedPath\Support\ShadowNode;
use Dakujem\Oliva\MaterializedPath\Support\Tree;
use Dakujem\Oliva\MaterializedPath\Support\AlmostThere;
use Dakujem\Oliva\MovableNodeContract;
use Dakujem\Oliva\TreeNodeContract;
use LogicException;
Expand Down Expand Up @@ -87,18 +87,18 @@ public function build(
callable $node,
callable $vector,
): TreeNodeContract {
$root = $this->buildTree($input, $node, $vector)->root();
$root = $this->processInput($input, $node, $vector)->root();
if (null === $root) {
throw new RuntimeException('Corrupted input, no tree created.');
}
return $root;
}

public function buildTree(
public function processInput(
iterable $input,
callable $node,
callable $vector,
): Tree {
): AlmostThere {
$shadowRoot = $this->buildShadowTree(
$input,
$node,
Expand All @@ -110,7 +110,7 @@ public function buildTree(
$root = $shadowRoot->reconstructRealTree();

// For edge case handling, return a structure containing the shadow root as well as the actual tree root.
return new Tree(
return new AlmostThere(
root: $root,
shadowRoot: $shadowRoot,
);
Expand Down
6 changes: 3 additions & 3 deletions tests/mptree.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ declare(strict_types=1);

use Dakujem\Oliva\Iterator\Filter;
use Dakujem\Oliva\Iterator\PreOrderTraversal;
use Dakujem\Oliva\MaterializedPath\Support\Tree;
use Dakujem\Oliva\MaterializedPath\Support\AlmostThere;
use Dakujem\Oliva\MaterializedPath\TreeBuilder;
use Dakujem\Oliva\Node;
use Dakujem\Oliva\Seed;
Expand Down Expand Up @@ -36,7 +36,7 @@ $data = [
];

$builder = new TreeBuilder();
$tree = $builder->buildTree(
$tree = $builder->processInput(
input: Seed::nullFirst($data),
node: fn(?Item $item) => new Node($item),
vector: TreeBuilder::fixed(
Expand Down Expand Up @@ -68,7 +68,7 @@ new Filter($it, Seed::omitRoot());

$item = $tree->root()?->data();

Assert::type(Tree::class, $tree);
Assert::type(AlmostThere::class, $tree);
Assert::type(Node::class, $tree->root());
Assert::null($tree->root()?->data());
Assert::type(Item::class, Seed::first($tree->root()?->children())?->data());
Expand Down

0 comments on commit 9c61b53

Please sign in to comment.