Passed
Push — master ( 463105...84cd59 )
by Roberto
04:47
created

UFList   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 87
ccs 16
cts 16
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getUFByCode() 0 9 2
A getCodeByUF() 0 11 2
A getListByUF() 0 4 1
A getListByCode() 0 4 1
1
<?php
2
3
namespace NFePHP\Common;
4
5
/**
6
 * Returns IBGE code or State abbreviation
7
 * @category   NFePHP
8
 * @package    NFePHP\Common
9
 * @copyright  Copyright (c) 2008-2017
10
 * @license    http://www.gnu.org/licenses/lesser.html LGPL v3
11
 * @license    https://opensource.org/licenses/MIT MIT
12
 * @license    http://www.gnu.org/licenses/gpl.txt GPLv3+
13
 * @author     Roberto L. Machado <linux.rlm at gmail dot com>
14
 * @link       http://github.com/nfephp-org/sped-common for the canonical source repository
15
 */
16
17
use NFePHP\Common\Exception\InvalidArgumentException;
18
19
class UFList
20
{
21
    protected static $uflist = [
22
        12=>'AC',
23
        27=>'AL',
24
        13=>'AM',
25
        91=>'AN',
26
        16=>'AP',
27
        29=>'BA',
28
        23=>'CE',
29
        53=>'DF',
30
        32=>'ES',
31
        52=>'GO',
32
        21=>'MA',
33
        31=>'MG',
34
        50=>'MS',
35
        51=>'MT',
36
        15=>'PA',
37
        25=>'PB',
38
        26=>'PE',
39
        22=>'PI',
40
        41=>'PR',
41
        33=>'RJ',
42
        24=>'RN',
43
        11=>'RO',
44
        14=>'RR',
45
        43=>'RS',
46
        42=>'SC',
47
        28=>'SE',
48
        35=>'SP',
49
        17=>'TO',
50
        92=>'SVCAN',
51
        93=>'SVCRS'
52
    ];
53
    
54
    /**
55
     * Returns abbreviation of state from your IBGE code
56
     * @param int $code
57
     * @return string
58
     * @throws InvalidArgumentException
59
     */
60 3
    public static function getUFByCode($code)
61
    {
62 3
        if (!key_exists($code, self::$uflist)) {
63 1
            throw new InvalidArgumentException(
64 1
                "cUF incorreto! [$code] não existe."
65
            );
66
        }
67 2
        return self::$uflist[$code];
68
    }
69
    
70
    /**
71
     * Returns IBGE code from abbreviation of state
72
     * @param string $uf
73
     * @return int
74
     * @throws InvalidArgumentException
75
     */
76 4
    public static function getCodeByUF($uf)
77
    {
78 4
        $uf = strtoupper($uf);
79 4
        $codelist = array_flip(self::$uflist);
80 4
        if (!key_exists($uf, $codelist)) {
81 1
            throw new InvalidArgumentException(
82 1
                "UF incorreto! [$uf] não existe."
83
            );
84
        }
85 3
        return $codelist[$uf];
86
    }
87
    
88
    /**
89
     * Returns UF list with UF as keys
90
     * @return array
91
     */
92 1
    public static function getListByUF()
93
    {
94 1
        return array_flip(self::$uflist);
95
    }
96
    
97
    /**
98
     * Returns UF list with Code as keys
99
     * @return array
100
     */
101 1
    public static function getListByCode()
102
    {
103 1
        return self::$uflist;
104
    }
105
}
106