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

TranslationLocaleProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
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