Passed
Push — master ( 43458c...ac6f10 )
by Francimar
03:09
created

Retorno   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 125
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 24
lcom 2
cbo 2
dl 0
loc 125
ccs 52
cts 52
cp 1
rs 10
c 0
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getDataRecebimento() 0 7 3
A isAutorizado() 0 4 1
A isCancelado() 0 4 1
A isProcessado() 0 4 1
A isRecebido() 0 4 1
A isDenegada() 0 4 1
A isInexistente() 0 4 1
A setDataRecebimento() 0 8 3
A isParalisado() 0 4 1
A toArray() 0 6 1
A fromArray() 0 15 4
A getNode() 0 10 3
A loadNode() 0 7 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\Task;
29
30
use NFe\Common\Util;
31
32
class Retorno extends Status
33
{
34
35
    private $data_recebimento;
36
37 42
    public function __construct($retorno = [])
38
    {
39 42
        parent::__construct($retorno);
40 42
    }
41
42 16
    public function getDataRecebimento($normalize = false)
43
    {
44 16
        if (!$normalize || is_null($this->data_recebimento)) {
45 15
            return $this->data_recebimento;
46
        }
47 7
        return Util::toDateTime($this->data_recebimento);
48
    }
49
50 42
    public function setDataRecebimento($data_recebimento)
51
    {
52 42
        if (!is_null($data_recebimento) && !is_numeric($data_recebimento)) {
53 19
            $data_recebimento = strtotime($data_recebimento);
54
        }
55 42
        $this->data_recebimento = $data_recebimento;
56 42
        return $this;
57
    }
58
59
    /**
60
     * Informa se a nota foi autorizada no prazo ou fora do prazo
61
     */
62 11
    public function isAutorizado()
63
    {
64 11
        return in_array($this->getStatus(), ['100', '150']);
65
    }
66
67
    /**
68
     * Informa se a nota está cancelada
69
     */
70 6
    public function isCancelado()
71
    {
72 6
        return in_array($this->getStatus(), ['101', '151']);
73
    }
74
75
    /**
76
     * Informa se o lote já foi processado e já tem um protocolo
77
     */
78 8
    public function isProcessado()
79
    {
80 8
        return $this->getStatus() == '104';
81
    }
82
83
    /**
84
     * Informa se o lote foi recebido com sucesso
85
     */
86 3
    public function isRecebido()
87
    {
88 3
        return in_array($this->getStatus(), ['103', '105']);
89
    }
90
91
    /**
92
     * Informa se a nota foi denegada
93
     */
94 1
    public function isDenegada()
95
    {
96 1
        return in_array($this->getStatus(), ['110', '301', '302', '303']);
97
    }
98
99
    /**
100
     * Informa se a nota da consulta não foi autorizada ou se não existe
101
     */
102 1
    public function isInexistente()
103
    {
104 1
        return $this->getStatus() == '217';
105
    }
106
107
    /**
108
     * Informa se os serviços da SEFAZ estão paralisados ou em manutenção
109
     */
110 1
    public function isParalisado()
111
    {
112 1
        return in_array($this->getStatus(), ['108', '109']);
113
    }
114
115 11
    public function toArray($recursive = false)
116
    {
117 11
        $retorno = parent::toArray($recursive);
118 11
        $retorno['data_recebimento'] = $this->getDataRecebimento($recursive);
119 11
        return $retorno;
120
    }
121
122 42
    public function fromArray($retorno = [])
123
    {
124 42
        if ($retorno instanceof Retorno) {
125 1
            $retorno = $retorno->toArray();
126 42
        } elseif (!is_array($retorno)) {
127 1
            return $this;
128
        }
129 42
        parent::fromArray($retorno);
130 42
        if (isset($retorno['data_recebimento'])) {
131 8
            $this->setDataRecebimento($retorno['data_recebimento']);
132
        } else {
133 42
            $this->setDataRecebimento(null);
134
        }
135 42
        return $this;
136
    }
137
138 9
    public function getNode($name = null)
139
    {
140 9
        $element = parent::getNode(is_null($name)?'':$name);
141 9
        $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...
142 9
        $status = $element->getElementsByTagName('cStat')->item(0);
143 9
        if (!is_null($this->getDataRecebimento())) {
144 6
            Util::appendNode($element, 'dhRecbto', $this->getDataRecebimento(true), $status);
145
        }
146 9
        return $element;
147
    }
148
149 21
    public function loadNode($element, $name = null)
150
    {
151 21
        $name = is_null($name)?'Retorno':$name;
152 21
        $retorno = parent::loadNode($element, $name);
153 21
        $this->setDataRecebimento(Util::loadNode($retorno, 'dhRecbto'));
154 21
        return $retorno;
155
    }
156
}
157