Passed
Push — master ( 22a4bb...4eeb09 )
by Francimar
05:29
created

Isento::setTributacao()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 21
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 9.7518

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 9
cts 17
cp 0.5294
rs 8.7624
c 0
b 0
f 0
cc 6
eloc 18
nc 6
nop 1
crap 9.7518
1
<?php
2
/**
3
 * MIT License
4
 *
5
 * Copyright (c) 2016 MZ Desenvolvimento de Sistemas LTDA
6
 *
7
 * @author Francimar Alves <[email protected]>
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a copy
10
 * of this software and associated documentation files (the "Software"), to deal
11
 * in the Software without restriction, including without limitation the rights
12
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
 * copies of the Software, and to permit persons to whom the Software is
14
 * furnished to do so, subject to the following conditions:
15
 *
16
 * The above copyright notice and this permission notice shall be included in all
17
 * copies or substantial portions of the Software.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
 * SOFTWARE.
26
 *
27
 */
28
namespace NFe\Entity\Imposto\PIS;
29
30
use NFe\Common\Util;
31
use NFe\Entity\Imposto;
32
33
class Isento extends Imposto
34
{
35
36
    /**
37
     * Código de Situação Tributária do PIS.
38
     * 04 - Operação Tributável -
39
     * Tributação Monofásica - (Alíquota Zero);
40
     * 06 - Operação Tributável -
41
     * Alíquota Zero;
42
     * 07 - Operação Isenta da contribuição;
43
     * 08 - Operação Sem
44
     * Incidência da contribuição;
45
     * 09 - Operação com suspensão da contribuição;
46
     */
47
    const TRIBUTACAO_MONOFASICA = 'monofasica';
48
    const TRIBUTACAO_ZERO = 'zero';
49
    const TRIBUTACAO_ISENTA = 'isenta';
50
    const TRIBUTACAO_INCIDENCIA = 'incidencia';
51
    const TRIBUTACAO_SUSPENSAO = 'suspensao';
52
53 3
    public function __construct($pis = array())
54
    {
55 3
        parent::__construct($pis);
56 3
        $this->setGrupo(self::GRUPO_PIS);
57 3
        $this->setBase(0.00);
58 3
        $this->setAliquota(0.0);
59 3
    }
60
61
    /**
62
     * Código de Situação Tributária do PIS.
63
     * 04 - Operação Tributável -
64
     * Tributação Monofásica - (Alíquota Zero);
65
     * 06 - Operação Tributável -
66
     * Alíquota Zero;
67
     * 07 - Operação Isenta da contribuição;
68
     * 08 - Operação Sem
69
     * Incidência da contribuição;
70
     * 09 - Operação com suspensão da contribuição;
71
     */
72 2
    public function getTributacao($normalize = false)
73
    {
74 2
        if (!$normalize) {
75 1
            return parent::getTributacao();
76
        }
77 2
        switch (parent::getTributacao()) {
78 2
            case self::TRIBUTACAO_MONOFASICA:
79 2
                return '04';
80
            case self::TRIBUTACAO_ZERO:
81
                return '06';
82
            case self::TRIBUTACAO_ISENTA:
83
                return '07';
84
            case self::TRIBUTACAO_INCIDENCIA:
85
                return '08';
86
            case self::TRIBUTACAO_SUSPENSAO:
87
                return '09';
88
        }
89
        return parent::getTributacao($normalize);
90
    }
91
    
92
    /**
93
     * Altera o valor da Tributacao para o informado no parâmetro
94
     * @param mixed $tributacao novo valor para Tributacao
95
     * @return Isento A própria instância da classe
96
     */
97 3
    public function setTributacao($tributacao)
98
    {
99
        switch ($tributacao) {
100 3
            case '04':
101 1
                $tributacao = self::TRIBUTACAO_MONOFASICA;
102 1
                break;
103 3
            case '06':
104
                $tributacao = self::TRIBUTACAO_ZERO;
105
                break;
106 3
            case '07':
107
                $tributacao = self::TRIBUTACAO_ISENTA;
108
                break;
109 3
            case '08':
110
                $tributacao = self::TRIBUTACAO_INCIDENCIA;
111
                break;
112 3
            case '09':
113
                $tributacao = self::TRIBUTACAO_SUSPENSAO;
114
                break;
115
        }
116 3
        return parent::setTributacao($tributacao);
117
    }
118
119 1
    public function toArray($recursive = false)
120
    {
121 1
        $pis = parent::toArray($recursive);
122 1
        return $pis;
123
    }
124
125 3
    public function fromArray($pis = array())
126
    {
127 3
        if ($pis instanceof Isento) {
128 1
            $pis = $pis->toArray();
129 3
        } elseif (!is_array($pis)) {
130 1
            return $this;
131
        }
132 3
        parent::fromArray($pis);
133 3
        return $this;
134
    }
135
136 2
    public function getNode($name = null)
137
    {
138 2
        $dom = new \DOMDocument('1.0', 'UTF-8');
139 2
        $element = $dom->createElement(is_null($name)?'PISNT':$name);
140 2
        Util::appendNode($element, 'CST', $this->getTributacao(true));
141 2
        return $element;
142
    }
143
144 1
    public function loadNode($element, $name = null)
145
    {
146 1
        $name = is_null($name)?'PISNT':$name;
147 1
        if ($element->tagName != $name) {
148
            $_fields = $element->getElementsByTagName($name);
149
            if ($_fields->length == 0) {
150
                throw new \Exception('Tag "'.$name.'" não encontrada', 404);
151
            }
152
            $element = $_fields->item(0);
153
        }
154 1
        $this->setTributacao(
155 1
            Util::loadNode(
156
                $element,
157 1
                'CST',
158 1
                'Tag "CST" do campo "Tributacao" não encontrada'
159
            )
160
        );
161 1
        return $element;
162
    }
163
}
164