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
|
|
|
* 90 - Outras, estende de Normal |
35
|
|
|
*/ |
36
|
|
|
class Generico extends Mista |
37
|
|
|
{ |
38
|
|
|
|
39
|
46 |
|
public function __construct($generico = array()) |
40
|
|
|
{ |
41
|
46 |
|
parent::__construct($generico); |
42
|
46 |
|
$this->setTributacao('90'); |
43
|
46 |
|
$this->getNormal()->setTributacao('90'); |
44
|
46 |
|
} |
45
|
|
|
|
46
|
13 |
|
public function toArray($recursive = false) |
47
|
|
|
{ |
48
|
13 |
|
$generico = parent::toArray($recursive); |
49
|
13 |
|
return $generico; |
50
|
|
|
} |
51
|
|
|
|
52
|
46 |
|
public function fromArray($generico = array()) |
53
|
|
|
{ |
54
|
46 |
|
if ($generico instanceof Generico) { |
55
|
4 |
|
$generico = $generico->toArray(); |
56
|
46 |
|
} elseif (!is_array($generico)) { |
57
|
4 |
|
return $this; |
58
|
|
|
} |
59
|
46 |
|
parent::fromArray($generico); |
60
|
46 |
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
45 |
|
public function getNode($name = null) |
64
|
|
|
{ |
65
|
45 |
|
if (is_null($this->getModalidade()) && is_null($this->getNormal()->getModalidade())) { |
66
|
39 |
|
$dom = new \DOMDocument('1.0', 'UTF-8'); |
67
|
39 |
|
$element = $dom->createElement(is_null($name)?'ICMS90':$name); |
68
|
39 |
|
Util::appendNode($element, 'orig', $this->getOrigem(true)); |
69
|
39 |
|
Util::appendNode($element, 'CST', $this->getTributacao(true)); |
70
|
39 |
|
return $element; |
71
|
|
|
} |
72
|
6 |
|
$element = parent::getNode(is_null($name)?'ICMS90':$name); |
73
|
6 |
|
$dom = $element->ownerDocument; |
|
|
|
|
74
|
6 |
|
return $element; |
75
|
|
|
} |
76
|
|
|
|
77
|
8 |
|
public function loadNode($element, $name = null) |
78
|
|
|
{ |
79
|
8 |
|
$name = is_null($name)?'ICMS90':$name; |
80
|
8 |
|
if ($element->nodeName != $name) { |
81
|
|
|
$_fields = $element->getElementsByTagName($name); |
82
|
|
|
if ($_fields->length == 0) { |
83
|
|
|
throw new \Exception('Tag "'.$name.'" não encontrada', 404); |
84
|
|
|
} |
85
|
|
|
$element = $_fields->item(0); |
86
|
|
|
} |
87
|
8 |
|
$_mod = $element->getElementsByTagName('modBC'); |
88
|
8 |
|
$_mod_st = $element->getElementsByTagName('modBCST'); |
89
|
8 |
|
if ($_mod->length > 0 || $_mod_st->length > 0) { |
90
|
3 |
|
$element = parent::loadNode($element, $name); |
91
|
3 |
|
return $element; |
92
|
|
|
} |
93
|
5 |
|
$this->setOrigem( |
94
|
5 |
|
Util::loadNode( |
95
|
5 |
|
$element, |
96
|
5 |
|
'orig', |
97
|
|
|
'Tag "orig" do campo "Origem" não encontrada' |
98
|
5 |
|
) |
99
|
5 |
|
); |
100
|
5 |
|
$this->setTributacao( |
101
|
5 |
|
Util::loadNode( |
102
|
5 |
|
$element, |
103
|
5 |
|
'CST', |
104
|
|
|
'Tag "CST" do campo "Tributacao" não encontrada' |
105
|
5 |
|
) |
106
|
5 |
|
); |
107
|
5 |
|
return $element; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
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.