Completed
Push — final-forms ( 80b973...cafa21 )
by Kamil
35:41 queued 17:05
created

TranslationLocaleProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 43
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getDefinedLocalesCodes() 0 9 1
A getDefaultLocaleCode() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Component\Core\Provider;
13
14
use Sylius\Component\Locale\Model\LocaleInterface;
15
use Sylius\Component\Resource\Provider\TranslationLocaleProviderInterface;
16
use Sylius\Component\Resource\Repository\RepositoryInterface;
17
18
/**
19
 * @author Michał Marcinkowski <[email protected]>
20
 */
21
final class TranslationLocaleProvider implements TranslationLocaleProviderInterface
22
{
23
    /**
24
     * @var RepositoryInterface
25
     */
26
    private $localeRepository;
27
28
    /**
29
     * @var string
30
     */
31
    private $defaultLocaleCode;
32
33
    /**
34
     * @param RepositoryInterface $localeRepository
35
     * @param string $defaultLocaleCode
36
     */
37
    public function __construct(RepositoryInterface $localeRepository, $defaultLocaleCode)
38
    {
39
        $this->localeRepository = $localeRepository;
40
        $this->defaultLocaleCode = $defaultLocaleCode;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function getDefinedLocalesCodes()
47
    {
48
        $locales = $this->localeRepository->findAll();
49
50
        return array_map(
51
            function (LocaleInterface $locale) { return $locale->getCode(); },
52
            $locales
53
        );
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function getDefaultLocaleCode()
60
    {
61
        return $this->defaultLocaleCode;
62
    }
63
}
64