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

LocaleProvider::getDefinedLocalesCodes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
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\Locale\Provider;
13
14
use Sylius\Component\Locale\Model\LocaleInterface;
15
use Sylius\Component\Resource\Repository\RepositoryInterface;
16
17
/**
18
 * @author Paweł Jędrzejewski <[email protected]>
19
 * @author Gonzalo Vilaseca <[email protected]>
20
 * @author Kamil Kokot <[email protected]>
21
 */
22
final class LocaleProvider implements LocaleProviderInterface
23
{
24
    /**
25
     * @var RepositoryInterface
26
     */
27
    private $localeRepository;
28
29
    /**
30
     * @var string
31
     */
32
    private $defaultLocaleCode;
33
34
    /**
35
     * @param RepositoryInterface $localeRepository
36
     * @param string $defaultLocaleCode
37
     */
38
    public function __construct(RepositoryInterface $localeRepository, $defaultLocaleCode)
39
    {
40
        $this->localeRepository = $localeRepository;
41
        $this->defaultLocaleCode = $defaultLocaleCode;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function getAvailableLocalesCodes()
48
    {
49
        $locales = $this->localeRepository->findBy(['enabled' => true]);
50
51
        return array_map(
52
            function (LocaleInterface $locale) { return $locale->getCode(); },
53
            $locales
54
        );
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function getDefaultLocaleCode()
61
    {
62
        return $this->defaultLocaleCode;
63
    }
64
}
65