| Total Complexity | 9 |
| Total Lines | 90 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php namespace Mbh\Tree\Traits; |
||
| 13 | trait Builder |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * {@inheritdoc} |
||
| 17 | */ |
||
| 18 | public function setNode(NodeInterface $node) |
||
| 19 | { |
||
| 20 | $this->emptyStack()->pushNode($node); |
||
| 21 | |||
| 22 | return $this; |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * {@inheritdoc} |
||
| 27 | */ |
||
| 28 | public function getNode() |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * {@inheritdoc} |
||
| 35 | */ |
||
| 36 | public function leaf($value = null) |
||
| 37 | { |
||
| 38 | $this->getNode()->addChild( |
||
| 39 | $this->nodeInstanceByValue($value) |
||
| 40 | ); |
||
| 41 | |||
| 42 | return $this; |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * {@inheritdoc} |
||
| 47 | */ |
||
| 48 | public function leafs($value1 /*, $value2, ... */) |
||
| 49 | { |
||
| 50 | foreach (func_get_args() as $value) { |
||
| 51 | $this->leaf($value); |
||
| 52 | } |
||
| 53 | |||
| 54 | return $this; |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * {@inheritdoc} |
||
| 59 | */ |
||
| 60 | public function tree($value) |
||
| 61 | { |
||
| 62 | $node = $this->nodeInstanceByValue($value); |
||
| 63 | $this->getNode()->addChild($node); |
||
| 64 | $this->pushNode($node); |
||
| 65 | |||
| 66 | return $this; |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * {@inheritdoc} |
||
| 71 | */ |
||
| 72 | public function end() |
||
| 73 | { |
||
| 74 | $this->popNode(); |
||
| 75 | |||
| 76 | return $this; |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * {@inheritdoc} |
||
| 81 | */ |
||
| 82 | public function nodeInstanceByValue($value = null) |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * {@inheritdoc} |
||
| 89 | */ |
||
| 90 | public function value($value = null) |
||
| 94 | } |
||
| 95 | |||
| 96 | abstract protected function peekStack(): NodeInterface; |
||
| 97 | |||
| 98 | abstract protected function emptyStack(); |
||
| 99 | |||
| 100 | abstract protected function pushNode(NodeInterface $node); |
||
| 101 | |||
| 102 | abstract protected function popNode(); |
||
| 103 | } |
||
| 104 |