Completed
Push — master ( 627e0e...cd277e )
by Kamil
15s
created

LocaleNameConverter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 19
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A convertToCode() 0 13 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\Locale\Converter;
13
14
use Symfony\Component\Intl\Intl;
15
16
/**
17
 * @author Arkadiusz Krakowiak <[email protected]>
18
 */
19
final class LocaleNameConverter implements LocaleNameConverterInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function convertToCode($name, $locale = 'en')
25
    {
26
        $localeNames = Intl::getLocaleBundle()->getLocaleNames($locale);
27
        $localeCode = array_search($name, $localeNames, true);
28
29
        if (false === $localeCode) {
30
            throw new \InvalidArgumentException(
31
                sprintf('Cannot find code for %s locale', $name)
32
            );
33
        }
34
35
        return $localeCode;
36
    }
37
}
38