TranslationDomainsProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 20
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 18 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Locastic\SymfonyTranslationBundle\Provider;
6
7
use Symfony\Component\Finder\Finder;
8
9
use function array_key_exists;
10
use function explode;
11
use function in_array;
12
13
final class TranslationDomainsProvider implements TranslationDomainsProviderInterface
14
{
15
    public function toArray(string $translationsDirectory): array
16
    {
17
        $domains = [];
18
        $finder = new Finder();
19
        foreach ($finder->in($translationsDirectory) as $item) {
20
            $itemName = $item->getFilename();
21
            $explodedName = explode('.', $itemName);
22
            if (!array_key_exists(0, $explodedName) || $explodedName[0] === $itemName) {
23
                continue;
24
            }
25
26
            $domainName = $explodedName[0];
27
            if (!in_array($domainName, $domains)) {
28
                $domains[] = $domainName;
29
            }
30
        }
31
32
        return $domains;
33
    }
34
}
35