Completed
Push — master ( 4017f5...fe0117 )
by Roberto
16:07
created

Response::readReturnSefaz()   D

Complexity

Conditions 9
Paths 9

Size

Total Lines 35
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 5
Bugs 0 Features 0
Metric Value
c 5
b 0
f 0
dl 0
loc 35
ccs 0
cts 22
cp 0
rs 4.909
cc 9
eloc 31
nc 9
nop 2
crap 90
1
<?php
2
3
namespace NFePHP\CTe\Auxiliar;
4
5
/**
6
 * Classe auxiliar com funções de DOM extendidas
7
 *
8
 * @category  NFePHP
9
 * @package   NFePHP\CTe\Response
10
 * @copyright Copyright (c) 2008-2015
11
 * @license   http://www.gnu.org/licenses/lesser.html LGPL v3
12
 * @author    Roberto L. Machado <linux.rlm at gmail dot com>
13
 * @link      http://github.com/nfephp-org/nfephp for the canonical source repository
14
 */
15
16
use \DOMDocument;
17
18
class Response
19
{
20
    /**
21
     * readReturnSefaz
22
     * Trata o retorno da SEFAZ devolvendo o resultado em um array
23
     *
24
     * @param  string $method
25
     * @param  string $xmlResp
26
     * @param  mixed  $parametro
0 ignored issues
show
Bug introduced by
There is no parameter named $parametro. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
27
     * @return array
28
     */
29
    public static function readReturnSefaz($method, $xmlResp)
30
    {
31
        $dom = new DOMDocument('1.0', 'utf-8');
32
        $dom->formatOutput = false;
33
        $dom->preserveWhiteSpace = false;
34
        $dom->loadXML($xmlResp);
35
        //para cada $method tem um formato de retorno especifico
36
        switch ($method) {
37
            case 'CteRecepcao':
38
                return self::zReadRecepcaoLote($dom);
39
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
40
            case 'CteRetRecepcao':
41
                return self::zReadRetRecepcao($dom);
42
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
43
            case 'CteConsultaProtocolo':
44
                return self::zReadConsultaProtocolo($dom);
45
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
46
            case 'consultaCadastro2':
47
                return self::zReadConsultaCadastro2($dom);
48
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
49
            case 'CteConsultaCT':
50
                return self::zReadConsultaCT($dom);
51
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
52
            case 'CteInutilizacaoCT':
53
                return self::zReadInutilizacaoCT($dom);
54
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
55
            case 'CteStatusServico':
56
                return self::zReadStatusServico($dom);
57
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
58
            case 'CteRecepcaoEvento':
59
                return self::zReadRecepcaoEvento($dom);
60
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
61
        }
62
        return array();
63
    }
64
65
    /**
66
     * zReadConsultaCadastro2
67
     *
68
     * @param  DOMDocument $dom
69
     * @return array
70
     */
71
    protected static function zReadConsultaCadastro2($dom)
72
    {
73
        $aResposta = array(
74
            'bStat' => false,
75
            'version' => '',
76
            'cStat' => '',
77
            'verAplic' => '',
78
            'xMotivo' => '',
79
            'UF' => '',
80
            'IE' => '',
81
            'CNPJ' => '',
82
            'CPF' => '',
83
            'dhCons' => '',
84
            'cUF' => '',
85
            'aCad' => array()
86
        );
87
        $tag = $dom->getElementsByTagName('retConsCad')->item(0);
88
        if (! isset($tag)) {
89
            return $aResposta;
90
        }
91
        $infCons = $tag->getElementsByTagName('infCons')->item(0);
92
        $aResposta = array(
93
            'bStat' => true,
94
            'version' => $tag->getAttribute('versao'),
95
            'cStat' => $infCons->getElementsByTagName('cStat')->item(0)->nodeValue,
96
            'verAplic' => $infCons->getElementsByTagName('verAplic')->item(0)->nodeValue,
97
            'xMotivo' => $infCons->getElementsByTagName('xMotivo')->item(0)->nodeValue,
98
            'UF' => $infCons->getElementsByTagName('UF')->item(0)->nodeValue,
99
            'IE' => $infCons->getElementsByTagName('IE')->item(0)->nodeValue,
100
            'CNPJ' => $infCons->getElementsByTagName('CNPJ')->item(0)->nodeValue,
101
            'CPF' => $infCons->getElementsByTagName('CPF')->item(0)->nodeValue,
102
            'dhCons' => $infCons->getElementsByTagName('dhCons')->item(0)->nodeValue,
103
            'cUF' => $infCons->getElementsByTagName('cUF')->item(0)->nodeValue,
104
            'aCad' => array()
105
        );
106
        $infCad = $tag->getElementsByTagName('infCad');
107
        if (isset($infCad)) {
108
            foreach ($infCad as $cad) {
109
                $ender = $cad->getElementsByTagName('ender')->item(0);
110
                $aCad[] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$aCad was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aCad = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
111
                    'IE' => $cad->getElementsByTagName('IE')->item(0)->nodeValue,
112
                    'CNPJ' => $cad->getElementsByTagName('CNPJ')->item(0)->nodeValue,
113
                    'UF' => $cad->getElementsByTagName('UF')->item(0)->nodeValue,
114
                    'cSit' => $cad->getElementsByTagName('cSit')->item(0)->nodeValue,
115
                    'indCredNFe' => $cad->getElementsByTagName('indCredNFe')->item(0)->nodeValue,
116
                    'indCredCTe' => $cad->getElementsByTagName('indCredCTe')->item(0)->nodeValue,
117
                    'xNome' => $cad->getElementsByTagName('xNome')->item(0)->nodeValue,
118
                    'xRegApur' => $cad->getElementsByTagName('xRegApur')->item(0)->nodeValue,
119
                    'CNAE' => $cad->getElementsByTagName('CNAE')->item(0)->nodeValue,
120
                    'dIniAtiv' => $cad->getElementsByTagName('dIniAtiv')->item(0)->nodeValue,
121
                    'dUltSit' => $cad->getElementsByTagName('dUltSit')->item(0)->nodeValue,
122
                    'xLgr' => $ender->getElementsByTagName('xLgr')->item(0)->nodeValue,
123
                    'nro' => $ender->getElementsByTagName('nro')->item(0)->nodeValue,
124
                    'xCpl' => $ender->getElementsByTagName('xCpl')->item(0)->nodeValue,
125
                    'xBairro' => $ender->getElementsByTagName('xBairro')->item(0)->nodeValue,
126
                    'cMun' => $ender->getElementsByTagName('cMun')->item(0)->nodeValue,
127
                    'xMun' => $ender->getElementsByTagName('xMun')->item(0)->nodeValue,
128
                    'CEP' => $ender->getElementsByTagName('CEP')->item(0)->nodeValue
129
                );
130
            }
131
            $aResposta['aCad'] = $aCad;
0 ignored issues
show
Bug introduced by
The variable $aCad does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
132
        }
133
        return $aResposta;
134
    }
135
    
136
    /**
137
     * zReadRecepcaoLote
138
     *
139
     * @param  DOMDocument $dom
140
     * @return boolean
141
     */
142
    protected static function zReadRecepcaoLote($dom)
143
    {
144
        //retorno da funçao
145
        $aResposta = array(
146
            'bStat' => false,
147
            'versao' => '',
148
            'tpAmb' => '',
149
            'cUF' => '',
150
            'cStat' => '',
151
            'verAplic' => '',
152
            'xMotivo' => '',
153
            'dhRecbto' => '',
154
            'tMed' => '',
155
            'nRec' => ''
156
        );
157
        $tag = $dom->getElementsByTagName('retEnviCte')->item(0);
158
        if (! isset($tag)) {
159
            return $aResposta;
160
        }
161
        $dhRecbto = '';
162
        $nRec = '';
163
        $tMed = '';
164
        $infRec = $tag->getElementsByTagName('infRec')->item(0);
165
        if (!empty($infRec)) {
166
            $dhRecbto = $infRec->getElementsByTagName('dhRecbto')->item(0)->nodeValue;
167
            $nRec = $infRec->getElementsByTagName('nRec')->item(0)->nodeValue;
168
            $tMed = $infRec->getElementsByTagName('tMed')->item(0)->nodeValue;
169
        }
170
        $aResposta = array(
171
            'bStat' => true,
172
            'versao' => $tag->getAttribute('versao'),
173
            'tpAmb' => $tag->getElementsByTagName('tpAmb')->item(0)->nodeValue,
174
            'cUF' => $tag->getElementsByTagName('cUF')->item(0)->nodeValue,
175
            'cStat' => $tag->getElementsByTagName('cStat')->item(0)->nodeValue,
176
            'verAplic' => $tag->getElementsByTagName('verAplic')->item(0)->nodeValue,
177
            'xMotivo' => $tag->getElementsByTagName('xMotivo')->item(0)->nodeValue,
178
            'dhRecbto' => $dhRecbto,
179
            'tMed' => $tMed,
180
            'nRec' => $nRec
181
        );
182
        return $aResposta;
183
    }
184
    
185
    /**
186
     * zReadRetRecepcao
187
     *
188
     * @param  DOMDocument $dom
189
     * @return array
190
     */
191 View Code Duplication
    protected static function zReadRetRecepcao($dom)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

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

Loading history...
192
    {
193
        //retorno da funçao
194
        $aResposta = array(
195
            'bStat'=>false,
196
            'versao' => '',
197
            'tpAmb' => '',
198
            'verAplic' => '',
199
            'cStat' => '',
200
            'xMotivo' => '',
201
            'cUF' => '',
202
            'nRec' => '',
203
            'aProt' => array()
204
        );
205
        $tag = $dom->getElementsByTagName('retConsReciCTe')->item(0);
206
        if (! isset($tag)) {
207
            return $aResposta;
208
        }
209
        $aResposta = array(
210
            'bStat'=>true,
211
            'versao' => $tag->getAttribute('versao'),
212
            'tpAmb' => $tag->getElementsByTagName('tpAmb')->item(0)->nodeValue,
213
            'verAplic' => $tag->getElementsByTagName('verAplic')->item(0)->nodeValue,
214
            'cStat' => $tag->getElementsByTagName('cStat')->item(0)->nodeValue,
215
            'xMotivo' => $tag->getElementsByTagName('xMotivo')->item(0)->nodeValue,
216
            'nRec' => $tag->getElementsByTagName('nRec')->item(0)->nodeValue,
217
            'cUF' => $tag->getElementsByTagName('tpAmb')->item(0)->nodeValue,
218
            'aProt' => self::zGetProt($tag)
0 ignored issues
show
Compatibility introduced by
$tag of type object<DOMNode> is not a sub-type of object<DOMDocument>. It seems like you assume a child class of the class DOMNode to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
219
        );
220
        return $aResposta;
221
    }
222
223
    /**
224
     * zReadRetRecepcao
225
     *
226
     * @param  DOMDocument $dom
227
     * @return array
228
     */
229
    protected static function zReadConsultaProtocolo($dom)
230
    {
231
        //retorno da funçao
232
        $aResposta = array(
233
            'bStat'=>false,
234
            'versao' => '',
235
            'tpAmb' => '',
236
            'verAplic' => '',
237
            'cStat' => '',
238
            'xMotivo' => '',
239
            'cUF' => ''
240
        );
241
        $tag = $dom->getElementsByTagName('retConsSitCTe')->item(0);
242
        if (! isset($tag)) {
243
            return $aResposta;
244
        }
245
        $aResposta = array(
246
            'bStat'=>true,
247
            'versao' => $tag->getAttribute('versao'),
248
            'tpAmb' => $tag->getElementsByTagName('tpAmb')->item(0)->nodeValue,
249
            'verAplic' => $tag->getElementsByTagName('verAplic')->item(0)->nodeValue,
250
            'cStat' => $tag->getElementsByTagName('cStat')->item(0)->nodeValue,
251
            'xMotivo' => $tag->getElementsByTagName('xMotivo')->item(0)->nodeValue,
252
            'cUF' => $tag->getElementsByTagName('tpAmb')->item(0)->nodeValue
253
        );
254
        return $aResposta;
255
    }
256
257
258
    /**
259
     * zReadConsultaCT
260
     *
261
     * @param  DOMDocument $dom
262
     * @return string
263
     */
264
    protected static function zReadConsultaCT($dom)
265
    {
266
        //retorno da funçao
267
        $aResposta = array(
268
            'bStat' => false,
269
            'versao' => '',
270
            'tpAmb' => '',
271
            'verAplic' => '',
272
            'cStat' => '',
273
            'xMotivo' => '',
274
            'cUF' => '',
275
            'aProt' => array(),
276
            'aCanc' => array(),
277
            'aEvent' => array()
278
        );
279
        $tag = $dom->getElementsByTagName('retConsSitCTe')->item(0);
280
        if (! isset($tag)) {
281
            return $aResposta;
282
        }
283
        $aEvent = array();
284
        $procEventoCTe = $tag->getElementsByTagName('procEventoCTe');
285
        if (isset($procEventoCTe)) {
286
            foreach ($procEventoCTe as $evento) {
287
                $aEvent[] = self::zGetEvent($evento);
288
            }
289
        }
290
        $aResposta = array(
291
            'bStat' => true,
292
            'versao' => $tag->getAttribute('versao'),
293
            'tpAmb' => $tag->getElementsByTagName('tpAmb')->item(0)->nodeValue,
294
            'verAplic' => $tag->getElementsByTagName('verAplic')->item(0)->nodeValue,
295
            'cStat' => $tag->getElementsByTagName('cStat')->item(0)->nodeValue,
296
            'xMotivo' => $tag->getElementsByTagName('xMotivo')->item(0)->nodeValue,
297
            'cUF' => $tag->getElementsByTagName('cUF')->item(0)->nodeValue,
298
            'aProt' => self::zGetProt($tag),
0 ignored issues
show
Compatibility introduced by
$tag of type object<DOMNode> is not a sub-type of object<DOMDocument>. It seems like you assume a child class of the class DOMNode to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
299
            'aCanc' => self::zGetCanc($tag),
0 ignored issues
show
Compatibility introduced by
$tag of type object<DOMNode> is not a sub-type of object<DOMDocument>. It seems like you assume a child class of the class DOMNode to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
300
            'evento' => $aEvent
301
        );
302
        return $aResposta;
303
    }
304
    
305
    /**
306
     * zReadInutilizacaoCT
307
     *
308
     * @param  DOMDocument $dom
309
     * @return array
310
     */
311
    protected static function zReadInutilizacaoCT($dom)
312
    {
313
        $aResposta = array(
314
            'bStat' => false,
315
            'versao' => '',
316
            'tpAmb' => '',
317
            'verAplic' => '',
318
            'cStat' => '',
319
            'xMotivo' => '',
320
            'cUF' => '',
321
            'ano' => '',
322
            'CNPJ' => '',
323
            'mod' => '',
324
            'serie' => '',
325
            'nCTIni' => '',
326
            'nCTFin' => '',
327
            'dhRecbto' => '',
328
            'nProt' => ''
329
        );
330
        $tag = $dom->getElementsByTagName('retInutCTe')->item(0);
331
        if (! isset($tag)) {
332
            return $aResposta;
333
        }
334
        $aResposta['bStat'] = true;
335
        $aResposta['versao'] = $tag->getAttribute('versao');
336
        $aResposta['tpAmb'] = $tag->getElementsByTagName('tpAmb')->item(0)->nodeValue;
337
        $aResposta['verAplic'] = $tag->getElementsByTagName('verAplic')->item(0)->nodeValue;
338
        $aResposta['cStat'] = $tag->getElementsByTagName('cStat')->item(0)->nodeValue;
339
        $aResposta['xMotivo'] = $tag->getElementsByTagName('xMotivo')->item(0)->nodeValue;
340
        $aResposta['cUF'] = $tag->getElementsByTagName('cUF')->item(0)->nodeValue;
341
        $infInut = $tag->getElementsByTagName('infInut')->item(0);
342
        if (! empty($infInut)) {
343
            $aResposta['dhRecbto'] = $infInut->getElementsByTagName('dhRecbto')->item(0)->nodeValue;
344
            $aResposta['ano'] = $infInut->getElementsByTagName('ano')->item(0)->nodeValue;
345
            $aResposta['CNPJ'] = $infInut->getElementsByTagName('CNPJ')->item(0)->nodeValue;
346
            $aResposta['mod'] = $infInut->getElementsByTagName('mod')->item(0)->nodeValue;
347
            $aResposta['serie'] = $infInut->getElementsByTagName('serie')->item(0)->nodeValue;
348
            $aResposta['nCTIni'] = $infInut->getElementsByTagName('nCTIni')->item(0)->nodeValue;
349
            $aResposta['nCTFin'] = $infInut->getElementsByTagName('nCTFin')->item(0)->nodeValue;
350
            $aResposta['nProt'] = $infInut->getElementsByTagName('nProt')->item(0)->nodeValue;
351
        }
352
        return $aResposta;
353
    }
354
    
355
    /**
356
     * zReadStatusServico
357
     *
358
     * @param  DOMDocument $dom
359
     * @return string|boolean
360
     */
361 View Code Duplication
    protected static function zReadStatusServico($dom)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

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

Loading history...
362
    {
363
        //retorno da funçao
364
        $aResposta = array(
365
            'bStat' => false,
366
            'versao' => '',
367
            'cStat' => '',
368
            'verAplic' => '',
369
            'xMotivo' => '',
370
            'dhRecbto' => '',
371
            'tMed' => '',
372
            'cUF' => '',
373
            'dhRetorno' => '',
374
            'xObs' => ''
375
        );
376
        $tag = $dom->getElementsByTagName('retConsStatServCte')->item(0);
377
        if (! isset($tag)) {
378
            return $aResposta;
379
        }
380
        $aResposta = array(
381
            'bStat' => true,
382
            'versao' => $tag->getAttribute('versao'),
383
            'cStat' => $tag->getElementsByTagName('cStat')->item(0)->nodeValue,
384
            'verAplic' => $tag->getElementsByTagName('verAplic')->item(0)->nodeValue,
385
            'xMotivo' => $tag->getElementsByTagName('xMotivo')->item(0)->nodeValue,
386
            'dhRecbto' => $tag->getElementsByTagName('dhRecbto')->item(0)->nodeValue,
387
            'tMed' => $tag->getElementsByTagName('tMed')->item(0)->nodeValue,
388
            'cUF' => $tag->getElementsByTagName('cUF')->item(0)->nodeValue
389
        );
390
        return $aResposta;
391
    }
392
    
393
    /**
394
     * zReadRecepcaoEvento
395
     *
396
     * @param  DOMDocument $dom
397
     * @return string
398
     */
399
    protected static function zReadRecepcaoEvento($dom)
400
    {
401
        //retorno da funçao
402
        $aResposta = array(
403
            'bStat' => false,
404
            'versao' => '',
405
            'verAplic' => '',
406
            'tpAmb' => '',
407
            'id' => '',
408
            'cOrgao' => '',
409
            'cStat' => '',
410
            'xMotivo' => '',
411
            'evento' => array()
412
        );
413
        $tag = $dom->getElementsByTagName('retEventoCTe')->item(0);
414
        if (! isset($tag)) {
415
            return $aResposta;
416
        }
417
        $aResposta = array(
418
            'bStat' => true,
419
            'versao' => $tag->getAttribute('versao'),
420
            //'id' => $tag->getElementsByTagName('id')->item(0)->nodeValue,
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
421
            'tpAmb' => $tag->getElementsByTagName('tpAmb')->item(0)->nodeValue,
422
            'verAplic' => $tag->getElementsByTagName('verAplic')->item(0)->nodeValue,
423
            'cOrgao' => $tag->getElementsByTagName('cOrgao')->item(0)->nodeValue,
424
            'cStat' => $tag->getElementsByTagName('cStat')->item(0)->nodeValue,
425
            'xMotivo' => $tag->getElementsByTagName('xMotivo')->item(0)->nodeValue
426
        //,
427
          //  'evento' => self::zGetEvent($tag)
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
428
        );
429
        return $aResposta;
430
    }
431
    
432
    /**
433
     * zGetProt
434
     *
435
     * @param  DOMDocument $tag
436
     * @return type
437
     */
438 View Code Duplication
    private static function zGetProt($tag)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

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

Loading history...
439
    {
440
        $aProt = array();
441
        $infProt = $tag->getElementsByTagName('infProt')->item(0);
442
        if (isset($infProt)) {
443
            $aProt['tpAmb'] = $infProt->getElementsByTagName('tpAmb')->item(0)->nodeValue;
444
            $aProt['verAplic'] = $infProt->getElementsByTagName('verAplic')->item(0)->nodeValue;
445
            $aProt['chCTe'] = $infProt->getElementsByTagName('chCTe')->item(0)->nodeValue;
446
            $aProt['dhRecbto'] = $infProt->getElementsByTagName('dhRecbto')->item(0)->nodeValue;
447
            $aProt['nProt'] = $infProt->getElementsByTagName('nProt')->item(0)->nodeValue;
448
            $aProt['digVal'] = $infProt->getElementsByTagName('digVal')->item(0)->nodeValue;
449
            $aProt['cStat'] = $infProt->getElementsByTagName('cStat')->item(0)->nodeValue;
450
            $aProt['xMotivo'] = $infProt->getElementsByTagName('xMotivo')->item(0)->nodeValue;
451
        }
452
        return $aProt;
453
    }
454
    
455
    /**
456
     * zGetEvent
457
     *
458
     * @param  DOMDocument $tag
459
     * @return array
460
     */
461
    private static function zGetEvent($tag)
462
    {
463
        $aEvent = array();
464
        $infEvento = $tag->getElementsByTagName('infEvento')->item(0);
465
        if (isset($infEvento)) {
466
            $aEvent = array(
467
                'chCTe' => $infEvento->getElementsByTagName('chCTe')->item(0)->nodeValue,
468
                'tpEvento' => $infEvento->getElementsByTagName('tpEvento')->item(0)->nodeValue,
469
                'xEvento' => $infEvento->getElementsByTagName('xEvento')->item(0)->nodeValue,
470
                'nSeqEvento' => $infEvento->getElementsByTagName('nSeqEvento')->item(0)->nodeValue,
471
                'dhRegEvento' => $infEvento->getElementsByTagName('dhRegEvento')->item(0)->nodeValue,
472
                'nProt' => $infEvento->getElementsByTagName('nProt')->item(0)->nodeValue
473
            );
474
        }
475
        return $aEvent;
476
    }
477
478
    /**
479
     * zGetCanc
480
     *
481
     * @param  DOMDocument $tag
482
     * @return type
483
     */
484 View Code Duplication
    private static function zGetCanc($tag)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

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

Loading history...
485
    {
486
        $aCanc = array();
487
        $infCanc = $tag->getElementsByTagName('infCanc');
488
        if (! empty($infCanc)) {
489
            $aProt['tpAmb'] = $infCanc->getElementsByTagName('tpAmb')->item(0)->nodeValue;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$aProt was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aProt = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
490
            $aProt['verAplic'] = $infCanc->getElementsByTagName('verAplic')->item(0)->nodeValue;
491
            $aProt['cStat'] = $infCanc->getElementsByTagName('cStat')->item(0)->nodeValue;
492
            $aProt['xMotivo'] = $infCanc->getElementsByTagName('xMotivo')->item(0)->nodeValue;
493
            $aProt['cUF'] = $infCanc->getElementsByTagName('cUF')->item(0)->nodeValue;
494
            $aProt['chCTe'] = $infCanc->getElementsByTagName('chCTe')->item(0)->nodeValue;
495
            $aProt['dhRecbto'] = $infCanc->getElementsByTagName('dhRecbto')->item(0)->nodeValue;
496
            $aProt['nProt'] = $infCanc->getElementsByTagName('nProt')->item(0)->nodeValue;
497
        }
498
        return $aCanc;
499
    }
500
}
501