Completed
Push — master ( f3cf07...ead026 )
by Paweł
237:27 queued 221:30
created

ProviderBasedLocaleContext::getLocaleCode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
rs 9.4285
cc 2
eloc 6
nc 2
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\Context;
13
14
use Sylius\Component\Locale\Provider\LocaleProviderInterface;
15
16
/**
17
 * @author Kamil Kokot <[email protected]>
18
 */
19
final class ProviderBasedLocaleContext implements LocaleContextInterface
20
{
21
    /**
22
     * @var LocaleProviderInterface
23
     */
24
    private $localeProvider;
25
26
    /**
27
     * @param LocaleProviderInterface $localeProvider
28
     */
29
    public function __construct(LocaleProviderInterface $localeProvider)
30
    {
31
        $this->localeProvider = $localeProvider;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function getLocaleCode()
38
    {
39
        $availableLocalesCodes = $this->localeProvider->getAvailableLocalesCodes();
40
        $localeCode = $this->localeProvider->getDefaultLocaleCode();
41
42
        if (!in_array($localeCode, $availableLocalesCodes, true)) {
43
            throw LocaleNotFoundException::notAvailable($localeCode, $availableLocalesCodes);
44
        }
45
46
        return $localeCode;
47
    }
48
}
49