Completed
Push — master ( c523cc...f6da78 )
by Francimar
05:08
created

Mista::fromArray()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
crap 3
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
 * 70 - Com redução de base de cálculo e cobrança do
35
 * ICMS por substituição tributária, estende de Cobranca
36
 */
37
class Mista extends Cobranca
38
{
39
40 30
    public function __construct($mista = array())
41
    {
42 30
        parent::__construct($mista);
43 30
        $this->setTributacao('70');
44 30
        $this->setNormal(new Reducao());
45 30
    }
46
47 14
    public function toArray()
48
    {
49 14
        $mista = parent::toArray();
50 14
        return $mista;
51
    }
52
53 30
    public function fromArray($mista = array())
54
    {
55 30
        if ($mista instanceof Mista) {
56 1
            $mista = $mista->toArray();
57 30
        } elseif (!is_array($mista)) {
58 1
            return $this;
59
        }
60 30
        parent::fromArray($mista);
61 30
        return $this;
62
    }
63
64 10
    public function getNode($name = null)
65
    {
66 10
        $element = parent::getNode(is_null($name)?'ICMS70':$name);
67 10
        $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...
68 10
        return $element;
69
    }
70
71 5
    public function loadNode($element, $name = null)
72
    {
73 5
        $normal = new Reducao();
74 5
        $this->setNormal($normal);
75 5
        $name = is_null($name)?'ICMS70':$name;
76 5
        $element = parent::loadNode($element, $name);
77 5
        if (is_null($this->getNormal()->getReducao())) {
78 1
            $this->getNormal()->setReducao($this->getReducao());
79 1
        }
80 5
        if (is_null($this->getNormal()->getAliquota())) {
81 1
            $this->getNormal()->setAliquota($this->getAliquota());
82 1
        }
83 5
        if (!is_null($this->getNormal()->getBase())) {
84 4
            return $element;
85
        }
86 1
        $_fields = $element->getElementsByTagName('vICMSST');
87 1
        if ($_fields->length == 0) {
88
            throw new \Exception('Tag "vICMSST" do campo "Normal.Valor" não encontrada na Mista', 404);
89
        }
90 1
        $valor = floatval($_fields->item(0)->nodeValue);
91 1
        $diferenca = $this->getValor() - $valor;
92 1
        $base = $diferenca * 100.0 / $this->getNormal()->getAliquota();
93 1
        $this->getNormal()->setBase($base);
94 1
        return $element;
95 1
    }
96
}
97