Completed
Push — develop ( ec49e5...a553c2 )
by Bartko
01:59
created

AncestorQueryBuilder::getAdapter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace StefanoTree\NestedSet\QueryBuilder;
6
7
use StefanoTree\NestedSet\Adapter\AdapterInterface;
8
9
class AncestorQueryBuilder implements AncestorQueryBuilderInterface
10
{
11
    private $adapter;
12
13
    private $excludeFirstNLevel = 0;
14
    private $excludeLastLevel = false;
15
16
    /**
17
     * @param AdapterInterface $adapter
18
     */
19 4
    public function __construct(AdapterInterface $adapter)
20
    {
21 4
        $this->adapter = $adapter;
22 4
    }
23
24 4
    public function get($nodeId): array
25
    {
26 4
        return $this->getAdapter()
27 4
            ->getAncestors($nodeId, $this->excludeFirstNLevel, $this->excludeLastLevel);
28
    }
29
30 1
    public function excludeFistNLevel(int $count): AncestorQueryBuilderInterface
31
    {
32 1
        $this->excludeFirstNLevel = $count;
33
34 1
        return $this;
35
    }
36
37 2
    public function excludeLastLevel(): AncestorQueryBuilderInterface
38
    {
39 2
        $this->excludeLastLevel = true;
40
41 2
        return $this;
42
    }
43
44 4
    private function getAdapter(): AdapterInterface
45
    {
46 4
        return $this->adapter;
47
    }
48
}
49