ASources::setOrdering()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
namespace kalanis\kw_tree\DataSources;
4
5
6
use kalanis\kw_tree\Essentials\FileNode;
7
use kalanis\kw_tree\Interfaces\ITree;
8
9
10
abstract class ASources implements ITree
11
{
12
    /** @var string[] */
13
    protected array $startPath = [];
14
    protected string $ordering = ITree::ORDER_NONE;
15
    /** @var callable|null */
16
    protected $filterCallback = null;
17
    protected bool $recursive = false;
18
    protected ?FileNode $startNode = null;
19
20 5
    public function setStartPath(array $path): ITree
21
    {
22 5
        $this->startPath = $path;
23 5
        return $this;
24
    }
25
26 9
    public function setOrdering(string $order, ?string $by = null): ITree
27
    {
28 9
        $order = strtoupper($order);
29 9
        $this->ordering = in_array($order, [ITree::ORDER_NONE, ITree::ORDER_DESC, ITree::ORDER_ASC]) ? $order : $this->ordering;
30 9
        return $this;
31
    }
32
33 5
    public function setFilterCallback($callback): ITree
34
    {
35 5
        $this->filterCallback = $callback;
36 5
        return $this;
37
    }
38
39 7
    public function wantDeep(bool $want): ITree
40
    {
41 7
        $this->recursive = $want;
42 7
        return $this;
43
    }
44
45 11
    public function getRoot(): ?FileNode
46
    {
47 11
        return $this->startNode;
48
    }
49
}
50