Completed
Push — master ( 251d07...973a55 )
by Oleksandr
10s
created

Iso3166ConverterService   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A iso2ToNumeric() 0 9 2
A numericToIso2() 0 9 2
A searchArrayIndex() 0 4 1
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Service\ArvatoRss;
9
10
use Spryker\Service\Kernel\AbstractService;
11
use SprykerEco\Shared\ArvatoRss\ArvatoRssCountryConfig;
12
13
class Iso3166ConverterService extends AbstractService implements Iso3166ConverterServiceInterface
14
{
15
    const ISO2_KEY = 'alpha2';
16
    const ISO3166_KEY = 'numeric';
17
18
    /**
19
     * {@inheritdoc}
20
     *
21
     * @api
22
     *
23
     * @param string $iso2CountryCode
24
     *
25
     * @return string|null
26
     */
27
    public function iso2ToNumeric($iso2CountryCode)
28
    {
29
        $key = $this->searchArrayIndex($iso2CountryCode, static::ISO2_KEY);
30
        if ($key !== false) {
31
            return ArvatoRssCountryConfig::ISO3166[$key][static::ISO3166_KEY];
32
        }
33
34
        return null;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     *
40
     * @api
41
     *
42
     * @param string $iso3166CountryCode
43
     *
44
     * @return string|null
45
     */
46
    public function numericToIso2($iso3166CountryCode)
47
    {
48
        $key = $this->searchArrayIndex($iso3166CountryCode, static::ISO3166_KEY);
49
        if ($key !== false) {
50
            return ArvatoRssCountryConfig::ISO3166[$key][static::ISO2_KEY];
51
        }
52
53
        return null;
54
    }
55
56
    /**
57
     * @param string $value
58
     * @param string $columnName
59
     *
60
     * @return string
61
     */
62
    protected function searchArrayIndex($value, $columnName)
63
    {
64
        return array_search($value, array_column(ArvatoRssCountryConfig::ISO3166, $columnName));
65
    }
66
}
67