Completed
Push — develop ( f20a8e...81b85b )
by Bartko
01:51
created

DescendantQueryBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace StefanoTree\NestedSet\QueryBuilder;
6
7
use StefanoTree\NestedSet\Adapter\AdapterInterface;
8
9
class DescendantQueryBuilder implements DescendantQueryBuilderInterface
10
{
11
    private $adapter;
12
13
    private $excludeFirstNLevel = 0;
14
    private $limitDepth = null;
15
    private $excludeBranch = null;
16
17
    /**
18
     * @param AdapterInterface $adapter
19
     */
20 7
    public function __construct(AdapterInterface $adapter)
21
    {
22 7
        $this->adapter = $adapter;
23 7
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 7
    public function get($nodeId): array
29
    {
30 7
        return $this->getAdapter()
31 7
            ->getDescendants($nodeId, $this->excludeFirstNLevel, $this->limitDepth, $this->excludeBranch);
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 5
    public function excludeFirstNLevel(int $count): DescendantQueryBuilderInterface
38
    {
39 5
        $this->excludeFirstNLevel = $count;
40
41 5
        return $this;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 4
    public function limitDepth(int $count): DescendantQueryBuilderInterface
48
    {
49 4
        $this->limitDepth = $count;
50
51 4
        return $this;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 1
    public function excludeBranch($nodeId): DescendantQueryBuilderInterface
58
    {
59 1
        $this->excludeBranch = $nodeId;
60
61 1
        return $this;
62
    }
63
64 7
    private function getAdapter(): AdapterInterface
65
    {
66 7
        return $this->adapter;
67
    }
68
}
69