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
|
|
|
use NFe\Entity\Imposto\Fundo\Retido; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Tributação pelo ICMS |
35
|
|
|
* 60 - ICMS cobrado anteriormente por substituição |
36
|
|
|
* tributária |
37
|
|
|
*/ |
38
|
|
|
class Cobrado extends Generico |
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
private $valor; |
42
|
|
|
|
43
|
39 |
|
public function __construct($cobrado = []) |
44
|
|
|
{ |
45
|
39 |
|
parent::__construct($cobrado); |
46
|
39 |
|
} |
47
|
|
|
|
48
|
38 |
|
public function getValor($normalize = false) |
49
|
|
|
{ |
50
|
38 |
|
if (!$normalize) { |
51
|
35 |
|
return $this->valor; |
52
|
|
|
} |
53
|
38 |
|
return Util::toCurrency($this->valor); |
54
|
|
|
} |
55
|
|
|
|
56
|
39 |
|
public function setValor($valor) |
57
|
|
|
{ |
58
|
39 |
|
$this->valor = $valor; |
59
|
39 |
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
9 |
|
public function toArray($recursive = false) |
63
|
|
|
{ |
64
|
9 |
|
$cobrado = parent::toArray($recursive); |
65
|
9 |
|
$cobrado['valor'] = $this->getValor(); |
66
|
9 |
|
return $cobrado; |
67
|
|
|
} |
68
|
|
|
|
69
|
39 |
|
public function fromArray($cobrado = []) |
70
|
|
|
{ |
71
|
39 |
|
if ($cobrado instanceof Cobrado) { |
72
|
9 |
|
$cobrado = $cobrado->toArray(); |
73
|
39 |
|
} elseif (!is_array($cobrado)) { |
74
|
8 |
|
return $this; |
75
|
|
|
} |
76
|
39 |
|
parent::fromArray($cobrado); |
77
|
39 |
|
if (isset($cobrado['valor'])) { |
78
|
3 |
|
$this->setValor($cobrado['valor']); |
79
|
|
|
} else { |
80
|
39 |
|
$this->setValor(null); |
81
|
|
|
} |
82
|
39 |
|
if (!isset($cobrado['fundo']) || !($this->getFundo() instanceof Retido)) { |
83
|
39 |
|
$this->setFundo(new Retido()); |
84
|
|
|
} |
85
|
39 |
|
if (!isset($cobrado['tributacao'])) { |
86
|
39 |
|
$this->setTributacao('60'); |
87
|
|
|
} |
88
|
39 |
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
38 |
|
public function getNode($name = null) |
92
|
|
|
{ |
93
|
38 |
|
$element = parent::getNode(is_null($name)?'ICMS60':$name); |
94
|
38 |
|
$dom = $element->ownerDocument; |
|
|
|
|
95
|
38 |
|
Util::appendNode($element, 'vBCSTRet', $this->getBase(true)); |
96
|
38 |
|
Util::appendNode($element, 'pST', $this->getAliquota(true)); |
97
|
38 |
|
Util::appendNode($element, 'vICMSSTRet', $this->getValor(true)); |
98
|
38 |
|
return $this->exportFundo($element); |
99
|
|
|
} |
100
|
|
|
|
101
|
29 |
|
public function loadNode($element, $name = null) |
102
|
|
|
{ |
103
|
29 |
|
$name = is_null($name)?'ICMS60':$name; |
104
|
29 |
|
if ($element->nodeName != $name) { |
105
|
|
|
$_fields = $element->getElementsByTagName($name); |
106
|
|
|
if ($_fields->length == 0) { |
107
|
|
|
throw new \Exception('Tag "'.$name.'" não encontrada', 404); |
108
|
|
|
} |
109
|
|
|
$element = $_fields->item(0); |
110
|
|
|
} |
111
|
29 |
|
$this->setOrigem( |
112
|
29 |
|
Util::loadNode( |
113
|
29 |
|
$element, |
114
|
29 |
|
'orig', |
115
|
29 |
|
'Tag "orig" do campo "Origem" não encontrada' |
116
|
|
|
) |
117
|
|
|
); |
118
|
29 |
|
$this->setTributacao( |
119
|
29 |
|
Util::loadNode( |
120
|
29 |
|
$element, |
121
|
29 |
|
'CST', |
122
|
29 |
|
'Tag "CST" do campo "Tributacao" não encontrada' |
123
|
|
|
) |
124
|
|
|
); |
125
|
29 |
|
$this->setBase( |
126
|
29 |
|
Util::loadNode( |
127
|
29 |
|
$element, |
128
|
29 |
|
'vBCSTRet', |
129
|
29 |
|
'Tag "vBCSTRet" do campo "Base" não encontrada' |
130
|
|
|
) |
131
|
|
|
); |
132
|
29 |
|
$this->setAliquota( |
133
|
29 |
|
Util::loadNode( |
134
|
29 |
|
$element, |
135
|
29 |
|
'pST' |
136
|
|
|
) |
137
|
|
|
); |
138
|
29 |
|
$this->setValor( |
139
|
29 |
|
Util::loadNode( |
140
|
29 |
|
$element, |
141
|
29 |
|
'vICMSSTRet', |
142
|
29 |
|
'Tag "vICMSSTRet" do campo "Valor" não encontrada' |
143
|
|
|
) |
144
|
|
|
); |
145
|
29 |
|
$this->importFundo($element); |
146
|
29 |
|
return $element; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.