DescendantQueryBuilder   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 17
c 1
b 0
f 1
dl 0
loc 61
rs 10
ccs 18
cts 18
cp 1
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A levelLimit() 0 5 1
A excludeFirstNLevel() 0 5 1
A __construct() 0 3 1
A getManipulator() 0 3 1
A excludeBranch() 0 5 1
A get() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace StefanoTree\NestedSet\QueryBuilder;
6
7
use StefanoTree\NestedSet\Manipulator\ManipulatorInterface;
8
use StefanoTree\NestedSet\Utilities;
9
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
52
    {
53 5
        $this->limitDepth = $count;
54
55 5
        return $this;
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
69
    {
70 9
        return $this->manipulator;
71
    }
72
}
73