Passed
Push — master ( af3dcf...3709c1 )
by Petr
02:16
created

Files   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 32
ccs 14
cts 14
cp 1
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFiles() 0 17 5
A __construct() 0 4 1
1
<?php
2
3
namespace kalanis\kw_menu\EntriesSource;
4
5
6
use kalanis\kw_files\Access\CompositeAdapter;
7
use kalanis\kw_files\FilesException;
8
use kalanis\kw_files\Node;
9
use kalanis\kw_menu\Interfaces\IEntriesSource;
10
use kalanis\kw_menu\MenuException;
11
use kalanis\kw_menu\Traits\TFilterHtml;
12
use kalanis\kw_paths\ArrayPath;
13
use kalanis\kw_paths\Stuff;
14
use Traversable;
15
16
17
/**
18
 * Class Files
19
 * @package kalanis\kw_menu\EntriesSource
20
 * Entries source is in passed files adapter
21
 */
22
class Files implements IEntriesSource
23
{
24
    use TFilterHtml;
25
26
    /** @var CompositeAdapter */
27
    protected $files = null;
28
    /** @var ArrayPath */
29
    protected $arrPath = null;
30
31 4
    public function __construct(CompositeAdapter $files)
32
    {
33 4
        $this->files = $files;
34 4
        $this->arrPath = new ArrayPath();
35 4
    }
36
37 3
    public function getFiles(array $path): Traversable
38
    {
39
        try {
40 3
            $list = $this->files->readDir($path);
41 2
            foreach ($list as $item) {
42
                /** @var Node $item */
43 2
                if (empty($item->getPath())) {
44
                    // root - skip
45 2
                    continue;
46
                }
47 2
                $this->arrPath->setArray($item->getPath());
48 2
                if ($this->filterExt(Stuff::fileExt($this->arrPath->getFileName()))) {
49 2
                    yield $this->arrPath->getFileName();
50
                }
51
            }
52 1
        } catch (FilesException $ex) {
53 1
            throw new MenuException($ex->getMessage(), $ex->getCode(), $ex);
54
        }
55 2
    }
56
}
57