| Total Complexity | 6 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 10 | class AncestorQueryBuilder implements AncestorQueryBuilderInterface |
||
| 11 | { |
||
| 12 | private $manipulator; |
||
| 13 | |||
| 14 | private $excludeFirstNLevel = 0; |
||
| 15 | private $excludeLastNLevel = 0; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @param ManipulatorInterface $manipulator |
||
| 19 | */ |
||
| 20 | 5 | public function __construct(ManipulatorInterface $manipulator) |
|
| 21 | { |
||
| 22 | 5 | $this->manipulator = $manipulator; |
|
| 23 | } |
||
| 24 | |||
| 25 | 5 | public function get($nodeId, bool $nested = false): array |
|
| 26 | { |
||
| 27 | 5 | $result = $this->getManipulator() |
|
| 28 | 5 | ->getAncestors($nodeId, $this->excludeFirstNLevel, $this->excludeLastNLevel); |
|
| 29 | |||
| 30 | 5 | return $nested ? |
|
| 31 | 5 | Utilities::flatToNested($result, $this->getManipulator()->getOptions()->getLevelColumnName()) : $result; |
|
| 32 | } |
||
| 33 | |||
| 34 | 1 | public function excludeFirstNLevel(int $count): AncestorQueryBuilderInterface |
|
| 35 | { |
||
| 36 | 1 | $this->excludeFirstNLevel = $count; |
|
| 37 | |||
| 38 | 1 | return $this; |
|
| 39 | } |
||
| 40 | |||
| 41 | 2 | public function excludeLastNLevel(int $count): AncestorQueryBuilderInterface |
|
| 42 | { |
||
| 43 | 2 | $this->excludeLastNLevel = $count; |
|
| 44 | |||
| 45 | 2 | return $this; |
|
| 46 | } |
||
| 47 | |||
| 48 | 5 | private function getManipulator(): ManipulatorInterface |
|
| 51 | } |
||
| 52 | } |
||
| 53 |