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

Normal::getNode()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 1
nop 1
crap 2
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\ICMS\Simples;
29
30
use NFe\Common\Util;
31
32
/**
33
 * Tributada pelo Simples Nacional com permissão de crédito
34
 */
35
class Normal extends \NFe\Entity\Imposto\ICMS\Normal
36
{
37
38 11
    public function __construct($normal = array())
39
    {
40 11
        parent::__construct($normal);
41 11
        $this->setTributacao('101');
42 11
    }
43
44 1
    public function toArray()
45
    {
46 1
        $normal = parent::toArray();
47 1
        return $normal;
48
    }
49
50 11
    public function fromArray($normal = array())
51
    {
52 11
        if ($normal instanceof Normal) {
53 1
            $normal = $normal->toArray();
54 11
        } elseif (!is_array($normal)) {
55 1
            return $this;
56
        }
57 11
        parent::fromArray($normal);
58 11
        return $this;
59
    }
60
61 4
    public function getNode($name = null)
62
    {
63 4
        $dom = new \DOMDocument('1.0', 'UTF-8');
64 4
        $element = $dom->createElement(is_null($name)?'ICMSSN101':$name);
65 4
        Util::appendNode($element, 'orig', $this->getOrigem(true));
66 4
        Util::appendNode($element, 'CSOSN', $this->getTributacao(true));
67 4
        Util::appendNode($element, 'pCredSN', $this->getAliquota(true));
68 4
        Util::appendNode($element, 'vCredICMSSN', $this->getValor(true));
69 4
        return $element;
70
    }
71
72 2
    public function loadNode($element, $name = null)
73
    {
74 2
        $name = is_null($name)?'ICMSSN101':$name;
75 2
        if ($element->tagName != $name) {
76
            $_fields = $element->getElementsByTagName($name);
77
            if ($_fields->length == 0) {
78
                throw new \Exception('Tag "'.$name.'" não encontrada', 404);
79
            }
80
            $element = $_fields->item(0);
81
        }
82 2
        $this->setOrigem(
83 2
            Util::loadNode(
84 2
                $element,
85 2
                'orig',
86
                'Tag "orig" do campo "Origem" não encontrada'
87 2
            )
88 2
        );
89 2
        $this->setTributacao(
90 2
            Util::loadNode(
91 2
                $element,
92 2
                'CSOSN',
93
                'Tag "CSOSN" do campo "Tributacao" não encontrada'
94 2
            )
95 2
        );
96 2
        $this->setAliquota(
97 2
            Util::loadNode(
98 2
                $element,
99 2
                'pCredSN',
100
                'Tag "pCredSN" do campo "Aliquota" não encontrada'
101 2
            )
102 2
        );
103 2
        $_fields = $element->getElementsByTagName('vCredICMSSN');
104 2
        if ($_fields->length == 0) {
105
            throw new \Exception('Tag "vCredICMSSN" do campo "Valor" não encontrada', 404);
106
        }
107 2
        $valor = $_fields->item(0)->nodeValue;
108 2
        $this->setBase($valor * 100.0 / $this->getAliquota());
109 2
        return $element;
110
    }
111
}
112