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

Reducao   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 97.92%

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 2
dl 0
loc 84
ccs 47
cts 48
cp 0.9792
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getReducao() 0 7 2
A toArray() 0 6 1
A getNode() 0 7 2
A setReducao() 0 8 2
A getReduzido() 0 7 2
A fromArray() 0 15 4
A loadNode() 0 13 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;
29
30
use NFe\Common\Util;
31
32
/**
33
 * Tributção pelo ICMS
34
 * 20 - Com redução de base de cálculo, estende de
35
 * Normal
36
 */
37
class Reducao extends Normal
38
{
39
40
    private $reducao;
41
42 38
    public function __construct($reducao = array())
43
    {
44 38
        parent::__construct($reducao);
45 38
        $this->setTributacao('20');
46 38
    }
47
48 17
    public function getReducao($normalize = false)
49
    {
50 17
        if (!$normalize) {
51 11
            return $this->reducao;
52
        }
53 16
        return Util::toFloat($this->reducao);
54
    }
55
56 38
    public function setReducao($reducao)
57
    {
58 38
        if (trim($reducao) != '') {
59 15
            $reducao = floatval($reducao);
60 15
        }
61 38
        $this->reducao = $reducao;
62 38
        return $this;
63
    }
64
65
    /**
66
     * Calcula o valor do reduzido da base de cálculo
67
     */
68 5
    public function getReduzido($normalize = false)
69
    {
70 5
        if ($normalize) {
71
            return Util::toCurrency($this->getReduzido());
72
        }
73 5
        return ($this->getBase() * (100.0 - $this->getReducao())) / 100.0;
74
    }
75
76 4
    public function toArray()
77
    {
78 4
        $reducao = parent::toArray();
79 4
        $reducao['reducao'] = $this->getReducao();
80 4
        return $reducao;
81
    }
82
83 38
    public function fromArray($reducao = array())
84
    {
85 38
        if ($reducao instanceof Reducao) {
86 1
            $reducao = $reducao->toArray();
87 38
        } elseif (!is_array($reducao)) {
88 1
            return $this;
89
        }
90 38
        parent::fromArray($reducao);
91 38
        if (isset($reducao['reducao'])) {
92 2
            $this->setReducao($reducao['reducao']);
93 2
        } else {
94 38
            $this->setReducao(null);
95
        }
96 38
        return $this;
97
    }
98
99 16
    public function getNode($name = null)
100
    {
101 16
        $element = parent::getNode(is_null($name)?'ICMS20':$name);
102 16
        $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...
103 16
        Util::appendNode($element, 'pRedBC', $this->getReducao(true));
104 16
        return $element;
105
    }
106
107 7
    public function loadNode($element, $name = null)
108
    {
109 7
        $name = is_null($name)?'ICMS20':$name;
110 7
        $element = parent::loadNode($element, $name);
111 7
        $this->setReducao(
112 7
            Util::loadNode(
113 7
                $element,
114 7
                'pRedBC',
115
                'Tag "pRedBC" do campo "Reducao" não encontrada na Reducao'
116 7
            )
117 7
        );
118 7
        return $element;
119
    }
120
}
121