Completed
Push — master ( f6da78...86bb06 )
by Francimar
03:45
created

Aliquota::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
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\COFINS\ST;
29
30
use NFe\Common\Util;
31
32
/**
33
 * Este grupo só deve ser informado se o produto for sujeito a COFINS por
34
 * ST, CST = 05, a informação deste grupo não desobriga a informação do
35
 * grupo COFINS.
36
 */
37
class Aliquota extends \NFe\Entity\Imposto\COFINS\Aliquota
38
{
39
40 3
    public function __construct($aliquota = array())
41
    {
42 3
        parent::__construct($aliquota);
43 3
        $this->setGrupo(self::GRUPO_COFINSST);
44 3
    }
45
46 1
    public function toArray()
47
    {
48 1
        $aliquota = parent::toArray();
49 1
        return $aliquota;
50
    }
51
52 3
    public function fromArray($aliquota = array())
53
    {
54 3
        if ($aliquota instanceof Aliquota) {
55 1
            $aliquota = $aliquota->toArray();
56 3
        } elseif (!is_array($aliquota)) {
57 1
            return $this;
58
        }
59 3
        parent::fromArray($aliquota);
60 3
        return $this;
61
    }
62
63 2
    public function getNode($name = null)
64
    {
65 2
        $element = parent::getNode(is_null($name)?'COFINSST':$name);
66 2
        $item = $element->getElementsByTagName('CST')->item(0);
67 2
        $element->removeChild($item);
68 2
        return $element;
69
    }
70
71 1
    public function loadNode($element, $name = null)
72
    {
73 1
        $name = is_null($name)?'COFINSST':$name;
74 1
        if ($element->tagName != $name) {
75
            $_fields = $element->getElementsByTagName($name);
76
            if ($_fields->length == 0) {
77
                throw new \Exception('Tag "'.$name.'" não encontrada', 404);
78
            }
79
            $element = $_fields->item(0);
80
        }
81 1
        $this->setBase(
82 1
            Util::loadNode(
83 1
                $element,
84 1
                'vBC',
85
                'Tag "vBC" do campo "Base" não encontrada'
86 1
            )
87 1
        );
88 1
        $this->setAliquota(
89 1
            Util::loadNode(
90 1
                $element,
91 1
                'pCOFINS',
92
                'Tag "pCOFINS" do campo "Aliquota" não encontrada'
93 1
            )
94 1
        );
95 1
        return $element;
96
    }
97
}
98