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

Cobrado::loadNode()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 40
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 28
CRAP Score 4.0556

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 28
cts 33
cp 0.8485
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 28
nc 6
nop 2
crap 4.0556
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;
29
30
use NFe\Common\Util;
31
32
/**
33
 * Tributação pelo ICMS
34
 * 60 - ICMS cobrado anteriormente por substituição
35
 * tributária
36
 */
37
class Cobrado extends Generico
38
{
39
40
    private $valor;
41
42 10
    public function __construct($cobrado = array())
43
    {
44 10
        parent::__construct($cobrado);
45 10
        $this->setTributacao('60');
46 10
    }
47
48 9
    public function getValor($normalize = false)
49
    {
50 9
        if (!$normalize) {
51 7
            return $this->valor;
52
        }
53 9
        return Util::toCurrency($this->valor);
54
    }
55
56 10
    public function setValor($valor)
57
    {
58 10
        $this->valor = $valor;
59 10
        return $this;
60
    }
61
62 4
    public function toArray()
63
    {
64 4
        $cobrado = parent::toArray();
65 4
        $cobrado['valor'] = $this->getValor();
66 4
        return $cobrado;
67
    }
68
69 10
    public function fromArray($cobrado = array())
70
    {
71 10
        if ($cobrado instanceof Cobrado) {
72 3
            $cobrado = $cobrado->toArray();
73 10
        } elseif (!is_array($cobrado)) {
74 3
            return $this;
75
        }
76 10
        parent::fromArray($cobrado);
77 10
        if (isset($cobrado['valor'])) {
78 2
            $this->setValor($cobrado['valor']);
79 2
        } else {
80 10
            $this->setValor(null);
81
        }
82 10
        return $this;
83
    }
84
85 9
    public function getNode($name = null)
86
    {
87 9
        $element = parent::getNode(is_null($name)?'ICMS60':$name);
88 9
        $dom = $element->ownerDocument;
0 ignored issues
show
Unused Code introduced by
$dom is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
89 9
        Util::appendNode($element, 'vBCSTRet', $this->getBase(true));
90 9
        Util::appendNode($element, 'vICMSSTRet', $this->getValor(true));
91 9
        return $element;
92
    }
93
94 5
    public function loadNode($element, $name = null)
95
    {
96 5
        $name = is_null($name)?'ICMS60':$name;
97 5
        if ($element->tagName != $name) {
98
            $_fields = $element->getElementsByTagName($name);
99
            if ($_fields->length == 0) {
100
                throw new \Exception('Tag "'.$name.'" não encontrada', 404);
101
            }
102
            $element = $_fields->item(0);
103
        }
104 5
        $this->setOrigem(
105 5
            Util::loadNode(
106 5
                $element,
107 5
                'orig',
108
                'Tag "orig" do campo "Origem" não encontrada'
109 5
            )
110 5
        );
111 5
        $this->setTributacao(
112 5
            Util::loadNode(
113 5
                $element,
114 5
                'CST',
115
                'Tag "CST" do campo "Tributacao" não encontrada'
116 5
            )
117 5
        );
118 5
        $this->setBase(
119 5
            Util::loadNode(
120 5
                $element,
121 5
                'vBCSTRet',
122
                'Tag "vBCSTRet" do campo "Base" não encontrada'
123 5
            )
124 5
        );
125 5
        $this->setValor(
126 5
            Util::loadNode(
127 5
                $element,
128 5
                'vICMSSTRet',
129
                'Tag "vICMSSTRet" do campo "Valor" não encontrada'
130 5
            )
131 5
        );
132 5
        return $element;
133
    }
134
}
135