Passed
Push — master ( 86bb06...22a4bb )
by Francimar
08:25
created

Configuracao::getBanco()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 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\Common;
29
30
use NFe\Entity\Emitente;
31
use NFe\Database\Estatico;
32
33
/**
34
 * Fornece informações importante para a geração e envio das notas fiscais
35
 */
36
class Configuracao
0 ignored issues
show
Complexity introduced by
This class has a complexity of 55 which exceeds the configured maximum of 50.

The class complexity is the sum of the complexity of all methods. A very high value is usually an indication that your class does not follow the single reponsibility principle and does more than one job.

Some resources for further reading:

You can also find more detailed suggestions for refactoring in the “Code” section of your repository.

Loading history...
37
{
38
39
    private $banco;
40
    private $emitente;
41
    private $evento;
42
    private $chave_publica;
43
    private $chave_privada;
44
    private $arquivo_chave_publica;
45
    private $arquivo_chave_privada;
46
    private $token;
47
    private $csc;
48
    private $token_ibpt;
49
    private $tempo_limite;
50
    private $sincrono;
51
    private $offline;
52
53 7
    public function __construct($configuracao = array())
54
    {
55 7
        $this->fromArray($configuracao);
56 7
    }
57
58
    /**
59
     * Banco que fornece informações sobre items da nota como: Códigos e Taxas
60
     */
61 32
    public function getBanco()
62
    {
63 32
        return $this->banco;
64
    }
65
66 7
    public function setBanco($banco)
67
    {
68 7
        $this->banco = $banco;
69 7
        return $this;
70
    }
71
72
    /**
73
     * Emitente da nota fiscal
74
     */
75 8
    public function getEmitente()
76
    {
77 8
        return $this->emitente;
78
    }
79
80 9
    public function setEmitente($emitente)
81
    {
82 9
        $this->emitente = $emitente;
83 9
        return $this;
84
    }
85
86
    /**
87
     * Informa a instancia que receberá os eventos do processamento das notas
88
     */
89 4
    public function getEvento()
90
    {
91 4
        return $this->evento;
92
    }
93
94 7
    public function setEvento($evento)
95
    {
96 7
        $this->evento = $evento;
97 7
        return $this;
98
    }
99
100
    /**
101
     * Conteúdo da chave pública ou certificado no formato PEM
102
     */
103 3
    public function getChavePublica()
104
    {
105 3
        return $this->chave_publica;
106
    }
107
108 12
    public function setChavePublica($chave_publica)
109
    {
110 12
        $this->chave_publica = $chave_publica;
111 12
        return $this;
112
    }
113
114
    /**
115
     * Conteúdo da chave privada do certificado no formato PEM
116
     */
117 3
    public function getChavePrivada()
118
    {
119 3
        return $this->chave_privada;
120
    }
121
122 12
    public function setChavePrivada($chave_privada)
123
    {
124 12
        $this->chave_privada = $chave_privada;
125 12
        return $this;
126
    }
127
128
    /**
129
     * Informa o caminho do arquivo da chave pública ou certificado no formato
130
     * PEM
131
     */
132 1
    public function getArquivoChavePublica()
133
    {
134 1
        return $this->arquivo_chave_publica;
135
    }
136
137 12
    public function setArquivoChavePublica($arquivo_chave_publica)
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $arquivo_chave_publica exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
138
    {
139 12
        $this->arquivo_chave_publica = $arquivo_chave_publica;
140 12
        if (file_exists($arquivo_chave_publica)) {
141 5
            $this->setChavePublica(file_get_contents($arquivo_chave_publica));
142 5
        }
143 12
        return $this;
144
    }
145
146
    /**
147
     * Caminho do arquivo da chave privada do certificado no formato PEM
148
     */
149 1
    public function getArquivoChavePrivada()
150
    {
151 1
        return $this->arquivo_chave_privada;
152
    }
153
154 12
    public function setArquivoChavePrivada($arquivo_chave_privada)
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $arquivo_chave_privada exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
155
    {
156 12
        $this->arquivo_chave_privada = $arquivo_chave_privada;
157 12
        if (file_exists($arquivo_chave_privada)) {
158 5
            $this->setChavePrivada(file_get_contents($arquivo_chave_privada));
159 5
        }
160 12
        return $this;
161
    }
162
163
    /**
164
     * Token do CSC
165
     */
166 4
    public function getToken()
167
    {
168 4
        return $this->token;
169
    }
170
171 7
    public function setToken($token)
172
    {
173 7
        $this->token = $token;
174 7
        return $this;
175
    }
176
177
    /**
178
     * Código do contribuinte para emissão de nota fiscal
179
     */
180 4
    public function getCSC()
181
    {
182 4
        return $this->csc;
183
    }
184
185 7
    public function setCSC($csc)
186
    {
187 7
        $this->csc = $csc;
188 7
        return $this;
189
    }
190
191
    /**
192
     * Token IBPT para consulta de impostos online
193
     */
194 8
    public function getTokenIBPT()
195
    {
196 8
        return $this->token_ibpt;
197
    }
198
199 7
    public function setTokenIBPT($token_ibpt)
200
    {
201 7
        $this->token_ibpt = $token_ibpt;
202 7
        return $this;
203
    }
204
205
    /**
206
     * Tempo limite em segundos nas conexões com os Web services, 0 para sem tempo limite
207
     */
208 1
    public function getTempoLimite()
209
    {
210 1
        return $this->tempo_limite;
211
    }
212
213 7
    public function setTempoLimite($tempo_limite)
214
    {
215 7
        $this->tempo_limite = intval($tempo_limite);
216 7
        return $this;
217
    }
218
219
    /**
220
     * Informa se o processo de autorização da nota é síncrono ou assíncrono
221
     */
222 1
    public function getSincrono($normalize = false)
223
    {
224 1
        if (!$normalize) {
225 1
            return $this->sincrono;
226
        }
227
        return $this->isSincrono()?'1':'0';
228
    }
229
230
    /**
231
     * Informa se o processo de autorização da nota é síncrono ou assíncrono
232
     */
233
    public function isSincrono()
234
    {
235
        return $this->sincrono == 'Y';
236
    }
237
238 7
    public function setSincrono($sincrono)
239
    {
240 7
        if (!in_array($sincrono, array('N', 'Y'))) {
241
            $sincrono = $sincrono?'Y':'N';
242
        }
243 7
        $this->sincrono = $sincrono;
244 7
        return $this;
245
    }
246
247
    /**
248
     * Informa se está operando offline
249
     * @return mixed offline da Configuracao
250
     */
251
    public function getOffline()
252
    {
253
        return $this->offline;
254
    }
255
256
    /**
257
     * Informa se está operando offline
258
     */
259
    public function isOffline()
260
    {
261
        return $this->offline + 180 > time();
262
    }
263
264
    /**
265
     * Entra no modo offline e sai automaticamente após 3 minutos
266
     */
267
    public function setOffline($offline)
268
    {
269
        $this->offline = $offline;
270
        return $this;
271
    }
272
273 1
    public function toArray()
274
    {
275 1
        $configuracao = array();
276 1
        $configuracao['banco'] = $this->getBanco();
277 1
        $configuracao['emitente'] = $this->getEmitente();
278 1
        $configuracao['evento'] = $this->getEvento();
279 1
        $configuracao['arquivo_chave_publica'] = $this->getArquivoChavePublica();
280 1
        $configuracao['arquivo_chave_privada'] = $this->getArquivoChavePrivada();
281 1
        $configuracao['token'] = $this->getToken();
282 1
        $configuracao['csc'] = $this->getCSC();
283 1
        $configuracao['token_ibpt'] = $this->getTokenIBPT();
284 1
        $configuracao['tempo_limite'] = $this->getTempoLimite();
285 1
        $configuracao['sincrono'] = $this->getSincrono();
286 1
        return $configuracao;
287
    }
288
289 7
    public function fromArray($configuracao = array())
0 ignored issues
show
Complexity introduced by
This operation has 62208 execution paths which exceeds the configured maximum of 200.

A high number of execution paths generally suggests many nested conditional statements and make the code less readible. This can usually be fixed by splitting the method into several smaller methods.

You can also find more information in the “Code” section of your repository.

Loading history...
290
    {
291 7
        if ($configuracao instanceof Configuracao) {
292
            $configuracao = $configuracao->toArray();
293 7
        } elseif (!is_array($configuracao)) {
294
            return $this;
295
        }
296 7
        if (!isset($configuracao['banco']) || is_null($configuracao['banco'])) {
297 7
            $this->setBanco(new Estatico());
298 7
        } else {
299 1
            $this->setBanco($configuracao['banco']);
300
        }
301 7
        if (!isset($configuracao['emitente']) || is_null($configuracao['emitente'])) {
302 7
            $this->setEmitente(new Emitente());
303 7
        } else {
304 1
            $this->setEmitente($configuracao['emitente']);
305
        }
306 7
        if (isset($configuracao['evento'])) {
307 1
            $this->setEvento($configuracao['evento']);
308 1
        } else {
309 7
            $this->setEvento(null);
310
        }
311 7
        if (isset($configuracao['chave_publica'])) {
312
            $this->setChavePublica($configuracao['chave_publica']);
313
        } else {
314 7
            $this->setChavePublica(null);
315
        }
316 7
        if (isset($configuracao['chave_privada'])) {
317
            $this->setChavePrivada($configuracao['chave_privada']);
318
        } else {
319 7
            $this->setChavePrivada(null);
320
        }
321 7
        if (isset($configuracao['arquivo_chave_publica'])) {
322 1
            $this->setArquivoChavePublica($configuracao['arquivo_chave_publica']);
323 1
        } else {
324 7
            $this->setArquivoChavePublica(null);
325
        }
326 7
        if (isset($configuracao['arquivo_chave_privada'])) {
327 1
            $this->setArquivoChavePrivada($configuracao['arquivo_chave_privada']);
328 1
        } else {
329 7
            $this->setArquivoChavePrivada(null);
330
        }
331 7
        if (isset($configuracao['token'])) {
332
            $this->setToken($configuracao['token']);
333
        } else {
334 7
            $this->setToken(null);
335
        }
336 7
        if (isset($configuracao['csc'])) {
337
            $this->setCSC($configuracao['csc']);
338
        } else {
339 7
            $this->setCSC(null);
340
        }
341 7
        if (isset($configuracao['token_ibpt'])) {
342
            $this->setTokenIBPT($configuracao['token_ibpt']);
343
        } else {
344 7
            $this->setTokenIBPT(null);
345
        }
346 7
        if (!isset($configuracao['tempo_limite']) || is_null($configuracao['tempo_limite'])) {
347 7
            $this->setTempoLimite(4);
348 7
        } else {
349 1
            $this->setTempoLimite($configuracao['tempo_limite']);
350
        }
351 7
        if (!isset($configuracao['sincrono']) || is_null($configuracao['sincrono'])) {
352 7
            $this->setSincrono('Y');
353 7
        } else {
354 1
            $this->setSincrono($configuracao['sincrono']);
355
        }
356 7
        return $this;
357
    }
358
}
359