Storage   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 22
ccs 10
cts 10
cp 1
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFiles() 0 11 4
A __construct() 0 3 1
1
<?php
2
3
namespace kalanis\kw_menu\EntriesSource;
4
5
6
use kalanis\kw_menu\Interfaces\IEntriesSource;
7
use kalanis\kw_menu\MenuException;
8
use kalanis\kw_menu\Traits\TFilterHtml;
9
use kalanis\kw_paths\Stuff;
10
use kalanis\kw_storage\Interfaces\IStorage;
11
use kalanis\kw_storage\StorageException;
12
use Traversable;
13
14
15
/**
16
 * Class Storage
17
 * @package kalanis\kw_menu\EntriesSource
18
 * Entries source is in passed storage
19
 */
20
class Storage implements IEntriesSource
21
{
22
    use TFilterHtml;
23
24
    protected IStorage $storage;
25
26 4
    public function __construct(IStorage $storage)
27
    {
28 4
        $this->storage = $storage;
29 4
    }
30
31 2
    public function getFiles(array $path): Traversable
32
    {
33 2
        $dir = Stuff::arrayToPath($path);
34
        try {
35 2
            foreach ($this->storage->lookup($dir) as $item) {
36 1
                if ($this->filterExt(Stuff::fileExt($item))) {
37 1
                    yield Stuff::sanitize($item);
38
                }
39
            }
40 1
        } catch (StorageException $ex) {
41 1
            throw new MenuException($ex->getMessage(), $ex->getCode(), $ex);
42
        }
43 1
    }
44
}
45