Passed
Push — master ( b401b3...148e23 )
by Wilmer
02:26
created

I18nProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 30
ccs 14
cts 14
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A register() 0 16 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Provider;
6
7
use App\ApplicationParameters;
8
use App\Service\MessageTranslator;
0 ignored issues
show
Bug introduced by
The type App\Service\MessageTranslator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use App\Service\Parameters;
0 ignored issues
show
Bug introduced by
The type App\Service\Parameters was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Psr\Container\ContainerInterface;
11
use Psr\EventDispatcher\EventDispatcherInterface;
12
use Yiisoft\Aliases\Aliases;
13
use Yiisoft\Di\Container;
14
use Yiisoft\Di\Support\ServiceProvider;
15
use Yiisoft\I18n\TranslatorInterface;
16
use Yiisoft\I18n\Message\PhpFile;
17
use Yiisoft\I18n\Translator\Translator;
18
19
final class I18nProvider extends ServiceProvider
20
{
21
    private string $locale;
22
    private string $translatePath;
23
24 8
    public function __construct(string $locale, string $translatePath)
25
    {
26 8
        $this->locale = $locale;
27 8
        $this->translatePath = $translatePath;
28 8
    }
29
30
    /**
31
     * @suppress PhanAccessMethodProtected
32
     */
33 8
    public function register(Container $container): void
34
    {
35 8
        $container->set(
36 8
            TranslatorInterface::class,
37
            function (ContainerInterface $container) {
38 6
                $aliases = $container->get(Aliases::class);
39
40 6
                $translator = new Translator(
41 6
                    $container->get(EventDispatcherInterface::class),
42 6
                    new PhpFile($aliases->get($this->translatePath)),
43 6
                    null
44
                );
45
46 6
                $translator->setDefaultLocale($this->locale);
47
48 6
                return $translator;
49 8
            }
50
        );
51 8
    }
52
}
53