Completed
Push — develop ( 3a0a6f...e67729 )
by Bartko
02:36
created

AncestorQueryBuilder::excludeLastNLevel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
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 $excludeLastNLevel = 0;
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->excludeLastNLevel);
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 excludeLastNLevel(int $count): AncestorQueryBuilderInterface
38
    {
39 2
        $this->excludeLastNLevel = $count;
40
41 2
        return $this;
42
    }
43
44 4
    private function getAdapter(): AdapterInterface
45
    {
46 4
        return $this->adapter;
47
    }
48
}
49