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

AncestorQueryBuilder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 5 1
A excludeFistNLevel() 0 6 1
A getAdapter() 0 4 1
A excludeLastNLevel() 0 6 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 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