NeonDirectoryResource   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 1
b 0
f 0
dl 0
loc 28
ccs 11
cts 12
cp 0.9167
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A load() 0 14 4
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