Tree::getFiles()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 4
nop 1
dl 0
loc 10
ccs 9
cts 9
cp 1
crap 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace kalanis\kw_menu\EntriesSource;
4
5
6
use kalanis\kw_menu\Interfaces\IEntriesSource;
7
use kalanis\kw_menu\Traits\TFilterHtml;
8
use kalanis\kw_paths\ArrayPath;
9
use kalanis\kw_paths\Stuff;
10
use kalanis\kw_tree\Interfaces\ITree;
11
use Traversable;
12
13
14
/**
15
 * Class Tree
16
 * @package kalanis\kw_menu\EntriesSource
17
 * Entries source is in passed tree
18
 */
19
class Tree implements IEntriesSource
20
{
21
    use TFilterHtml;
22
23
    protected ITree $tree;
24
    protected ArrayPath $arrPath;
25
26 2
    public function __construct(ITree $tree)
27
    {
28 2
        $this->tree = $tree;
29 2
        $this->arrPath = new ArrayPath();
30 2
    }
31
32 1
    public function getFiles(array $path): Traversable
33
    {
34 1
        $this->tree->setStartPath($path);
35 1
        $this->tree->wantDeep(false);
36 1
        $this->tree->process();
37 1
        if ($root = $this->tree->getRoot()) {
38 1
            foreach ($root->getSubNodes() as $item) {
39 1
                $this->arrPath->setArray($item->getPath());
40 1
                if ($this->filterExt(Stuff::fileExt($this->arrPath->getFileName()))) {
41 1
                    yield $this->arrPath->getFileName();
42
                }
43
            }
44
        }
45 1
    }
46
}
47