NeonDirectoryResource::load()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.0312

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 14
ccs 7
cts 8
cp 0.875
rs 10
cc 4
nc 3
nop 1
crap 4.0312
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Efabrica\Translatte\Resource;
6
7
use Nette\Utils\Finder;
8
9
class NeonDirectoryResource implements IResource
10
{
11
    /** @var array */
12
    private $directories;
13
14
    /** @var array */
15
    private $ignoredPrefixes;
16
17 15
    public function __construct(array $directories, array $ignoredPrefixes = ['messages'])
18
    {
19 15
        $this->directories = $directories;
20 15
        $this->ignoredPrefixes = $ignoredPrefixes;
21 15
    }
22
23 15
    public function load(string $lang): array
24
    {
25 15
        $directories = [];
26
27 15
        foreach (Finder::find('*.*.neon')->from($this->directories) as $file) {
0 ignored issues
show
Bug introduced by
$this->directories of type array is incompatible with the type string expected by parameter $paths of Nette\Utils\Finder::from(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
        foreach (Finder::find('*.*.neon')->from(/** @scrutinizer ignore-type */ $this->directories) as $file) {
Loading history...
28 15
            if (!preg_match('~^(?P<prefix>.*?)\.(?P<lang>[^\.]+)\.(?P<format>[^\.]+)$~', $file->getFilename(), $matches)) {
29
                continue;
30
            }
31
32 15
            $resource = new NeonResource($file->getPathname(), $matches['lang'], in_array($matches['prefix'], $this->ignoredPrefixes) ? '' : $matches['prefix'] . '.');
33 15
            $directories = array_merge($directories, $resource->load($lang));
34
        }
35
36 15
        return $directories;
37
    }
38
}
39