Volume::getFiles()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 2
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\Stuff;
9
use Traversable;
10
11
12
/**
13
 * Class Volume
14
 * @package kalanis\kw_menu\EntriesSource
15
 * Entries source is processed directly over volume
16
 */
17
class Volume implements IEntriesSource
18
{
19
    use TFilterHtml;
20
21
    /** @var string path to menu dir */
22
    protected string $rootPath = '';
23
24 5
    public function __construct(string $rootPath)
25
    {
26 5
        $this->rootPath = Stuff::removeEndingSlash($rootPath) . DIRECTORY_SEPARATOR;
27 5
    }
28
29 3
    public function getFiles(array $path): Traversable
30
    {
31 3
        $dir = Stuff::arrayToPath($path);
32 3
        $list = scandir($this->rootPath . $dir);
33 3
        if (false !== $list) {
34 3
            yield from array_filter(array_filter($list, [Stuff::class, 'notDots']), [$this, 'filterHtml']);
35
        }
36 3
    }
37
38 3
    public function filterHtml(string $fileName): bool
39
    {
40 3
        return $this->filterExt(Stuff::fileExt($fileName));
41
    }
42
}
43