Completed
Push — master ( dc5f67...84520a )
by Francimar
11:49 queued 07:55
created

Total   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 82.14%

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 1
dl 0
loc 47
ccs 23
cts 28
cp 0.8214
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fromArray() 0 10 3
A getNode() 0 6 2
A loadNode() 0 14 4
A toArray() 0 5 1
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;
29
30
use NFe\Entity\Imposto;
31
32
class Total extends Imposto
33
{
34
35 33
    public function __construct($total = array())
36
    {
37 33
        parent::__construct($total);
38 33
    }
39
40 1
    public function toArray($recursive = false)
41
    {
42 1
        $total = parent::toArray($recursive);
43 1
        return $total;
44
    }
45
46 33
    public function fromArray($total = array())
47
    {
48 33
        if ($total instanceof Total) {
49 1
            $total = $total->toArray();
50 33
        } elseif (!is_array($total)) {
51 1
            return $this;
52
        }
53 33
        parent::fromArray($total);
54 33
        return $this;
55
    }
56
57 2
    public function getNode($name = null)
58
    {
59 2
        $dom = new \DOMDocument('1.0', 'UTF-8');
60 2
        $element = $dom->createElement(is_null($name)?'vTotTrib':$name, $this->getTotal(true));
61 2
        return $element;
62
    }
63
64 1
    public function loadNode($element, $name = null)
65
    {
66 1
        $name = is_null($name)?'vTotTrib':$name;
67 1
        if ($element->nodeName != $name) {
68
            $_fields = $element->getElementsByTagName($name);
69
            if ($_fields->length == 0) {
70
                throw new \Exception('Tag "'.$name.'" não encontrada', 404);
71
            }
72
            $element = $_fields->item(0);
73
        }
74 1
        $this->setBase($element->nodeValue);
75 1
        $this->setAliquota(100);
76 1
        return $element;
77
    }
78
}
79