Skip to content

Commit

Permalink
Update code style.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Dec 14, 2019
1 parent 7ffd252 commit 8ba6d21
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 40 deletions.
64 changes: 32 additions & 32 deletions spec/drupol/phptree/Node/NodeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,38 @@ public function it_can_get_the_size(): void
->shouldReturn(30);
}

public function it_can_get_the_tree_levels(): void
{
$nodeLevel3_1 = new Node();
$nodeLevel3_2 = new Node();
$nodeLevel2 = new Node();
$nodeLevel1 = new Node();

$nodeLevel2->add($nodeLevel3_1, $nodeLevel3_2);
$nodeLevel1->add($nodeLevel2);
$this->add($nodeLevel1);

$this
->level(0)
->shouldYield([$this]);

$this
->level(1)
->shouldYield([$nodeLevel1]);

$this
->level(2)
->shouldYield([$nodeLevel2]);

$this
->level(3)
->shouldYield([$nodeLevel3_1, $nodeLevel3_2]);

$this
->level(4)
->shouldYield([]);
}

public function it_can_remove(): void
{
$node1 = new Node();
Expand Down Expand Up @@ -308,38 +340,6 @@ public function it_can_use_withChildren(): void
->shouldYield(new ArrayIterator([]));
}

public function it_can_get_the_tree_levels(): void
{
$nodeLevel3_1 = new Node();
$nodeLevel3_2 = new Node();
$nodeLevel2 = new Node();
$nodeLevel1 = new Node();

$nodeLevel2->add($nodeLevel3_1, $nodeLevel3_2);
$nodeLevel1->add($nodeLevel2);
$this->add($nodeLevel1);

$this
->level(0)
->shouldYield([$this]);

$this
->level(1)
->shouldYield([$nodeLevel1]);

$this
->level(2)
->shouldYield([$nodeLevel2]);

$this
->level(3)
->shouldYield([$nodeLevel3_1, $nodeLevel3_2]);

$this
->level(4)
->shouldYield([]);
}

public function it_has_a_degree(): void
{
$this
Expand Down
1 change: 1 addition & 0 deletions src/Builder/Random.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace drupol\phptree\Builder;

use drupol\phptree\Node\NodeInterface;

use function is_callable;

/**
Expand Down
16 changes: 8 additions & 8 deletions src/Node/MerkleNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use drupol\phpmerkle\Hasher\DoubleSha256;
use drupol\phpmerkle\Hasher\HasherInterface;
use drupol\phptree\Modifier\FulfillCapacity;
use drupol\phptree\Modifier\ModifierInterface;
use drupol\phptree\Modifier\RemoveNullNode;

/**
Expand Down Expand Up @@ -62,14 +63,13 @@ public function getValue()
*/
public function normalize(): MerkleNodeInterface
{
$tree = $this->clone();

foreach ($this->modifiers as $modifier) {
$tree = $modifier->modify($tree);
}

/** @var \drupol\phptree\Node\MerkleNodeInterface $tree */
return $tree;
return array_reduce(
$this->modifiers,
static function (NodeInterface $tree, ModifierInterface $modifier): NodeInterface {
return $modifier->modify($tree);
},
$this->clone()
);
}

/**
Expand Down

0 comments on commit 8ba6d21

Please sign in to comment.