TranslationFileNameProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFromValues() 0 3 1
A getFileName() 0 11 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Locastic\SymfonyTranslationBundle\Provider;
6
7
use Locastic\SymfonyTranslationBundle\Exception\GenerateTranslationFileNameException;
8
use Locastic\SymfonyTranslationBundle\Exception\TranslationNotFoundException;
9
use Locastic\SymfonyTranslationBundle\Model\TranslationValueInterface;
10
11
use function sprintf;
12
13
final class TranslationFileNameProvider implements TranslationFileNameProviderInterface
14
{
15
    public function getFileName(TranslationValueInterface $translationValue): string
16
    {
17
        if (null === $translationValue->getTranslation()) {
18
            throw new TranslationNotFoundException();
19
        }
20
21
        if (null === $translationValue->getTranslation()->getDomainName() || null === $translationValue->getLocaleCode()) {
22
            throw new GenerateTranslationFileNameException();
23
        }
24
25
        return sprintf('%s.%s.yaml', $translationValue->getTranslation()->getDomainName(), $translationValue->getLocaleCode());
26
    }
27
28
    public function getFromValues(string $directory, string $domain, string $locale, string $format): string
29
    {
30
        return sprintf('%s%s.%s.%s', $directory, $domain, $locale, $format);
31
    }
32
}
33