Total Complexity | 7 |
Total Lines | 61 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
10 | class DescendantQueryBuilder implements DescendantQueryBuilderInterface |
||
11 | { |
||
12 | private $manipulator; |
||
13 | |||
14 | private $excludeFirstNLevel = 0; |
||
15 | private $limitDepth = null; |
||
16 | private $excludeBranch = null; |
||
17 | |||
18 | /** |
||
19 | * @param ManipulatorInterface $manipulator |
||
20 | */ |
||
21 | 9 | public function __construct(ManipulatorInterface $manipulator) |
|
22 | { |
||
23 | 9 | $this->manipulator = $manipulator; |
|
24 | } |
||
25 | |||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | 9 | public function get($nodeId, bool $nested = false): array |
|
30 | { |
||
31 | 9 | $result = $this->getManipulator() |
|
32 | 9 | ->getDescendants($nodeId, $this->excludeFirstNLevel, $this->limitDepth, $this->excludeBranch); |
|
33 | |||
34 | 9 | return $nested ? |
|
35 | 9 | Utilities::flatToNested($result, $this->getManipulator()->getOptions()->getLevelColumnName()) : $result; |
|
36 | } |
||
37 | |||
38 | /** |
||
39 | * {@inheritdoc} |
||
40 | */ |
||
41 | 5 | public function excludeFirstNLevel(int $count): DescendantQueryBuilderInterface |
|
42 | { |
||
43 | 5 | $this->excludeFirstNLevel = $count; |
|
44 | |||
45 | 5 | return $this; |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | 5 | public function levelLimit(int $count): DescendantQueryBuilderInterface |
|
56 | } |
||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | 1 | public function excludeBranch($nodeId): DescendantQueryBuilderInterface |
|
62 | { |
||
63 | 1 | $this->excludeBranch = $nodeId; |
|
64 | |||
65 | 1 | return $this; |
|
66 | } |
||
67 | |||
68 | 9 | private function getManipulator(): ManipulatorInterface |
|
71 | } |
||
72 | } |
||
73 |