Completed
Push — master ( c92705...398954 )
by Roberto
47s
created

Response::zReadInutilizacaoCT()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 43
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 43
ccs 0
cts 38
cp 0
rs 8.8571
cc 3
eloc 38
nc 3
nop 1
crap 12
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 'CteInutilizacao':
53
                return self::zReadInutilizacao($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
     * zReadInutilizacao
307
     *
308
     * @param  DOMDocument $dom
309
     * @return array
310
     */
311
    protected static function zReadInutilizacao($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'] = isset($infInut->getElementsByTagName('dhRecbto')->item(0)->nodeValue) ?
344
                $infInut->getElementsByTagName('dhRecbto')->item(0)->nodeValue : '';
345
            $aResposta['ano'] = isset($infInut->getElementsByTagName('ano')->item(0)->nodeValue) ?
346
                $infInut->getElementsByTagName('ano')->item(0)->nodeValue : '';
347
            $aResposta['CNPJ'] = isset($infInut->getElementsByTagName('CNPJ')->item(0)->nodeValue) ?
348
                $infInut->getElementsByTagName('CNPJ')->item(0)->nodeValue : '';
349
            $aResposta['mod'] = isset($infInut->getElementsByTagName('mod')->item(0)->nodeValue) ?
350
                $infInut->getElementsByTagName('mod')->item(0)->nodeValue : '';
351
            $aResposta['serie'] = isset($infInut->getElementsByTagName('serie')->item(0)->nodeValue) ?
352
                $infInut->getElementsByTagName('serie')->item(0)->nodeValue : '';
353
            $aResposta['nCTIni'] = isset($infInut->getElementsByTagName('nCTIni')->item(0)->nodeValue) ?
354
                $infInut->getElementsByTagName('nCTIni')->item(0)->nodeValue : '';
355
            $aResposta['nCTFin'] = isset($infInut->getElementsByTagName('nCTFin')->item(0)->nodeValue) ?
356
                $infInut->getElementsByTagName('nCTFin')->item(0)->nodeValue : '';
357
            $aResposta['nProt'] = isset($infInut->getElementsByTagName('nProt')->item(0)->nodeValue) ?
358
                $infInut->getElementsByTagName('nProt')->item(0)->nodeValue : '';
359
        }
360
        return $aResposta;
361
    }
362
    
363
    /**
364
     * zReadStatusServico
365
     *
366
     * @param  DOMDocument $dom
367
     * @return string|boolean
368
     */
369 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...
370
    {
371
        //retorno da funçao
372
        $aResposta = array(
373
            'bStat' => false,
374
            'versao' => '',
375
            'cStat' => '',
376
            'verAplic' => '',
377
            'xMotivo' => '',
378
            'dhRecbto' => '',
379
            'tMed' => '',
380
            'cUF' => '',
381
            'dhRetorno' => '',
382
            'xObs' => ''
383
        );
384
        $tag = $dom->getElementsByTagName('retConsStatServCte')->item(0);
385
        if (! isset($tag)) {
386
            return $aResposta;
387
        }
388
        $aResposta = array(
389
            'bStat' => true,
390
            'versao' => $tag->getAttribute('versao'),
391
            'cStat' => $tag->getElementsByTagName('cStat')->item(0)->nodeValue,
392
            'verAplic' => $tag->getElementsByTagName('verAplic')->item(0)->nodeValue,
393
            'xMotivo' => $tag->getElementsByTagName('xMotivo')->item(0)->nodeValue,
394
            'dhRecbto' => $tag->getElementsByTagName('dhRecbto')->item(0)->nodeValue,
395
            'tMed' => $tag->getElementsByTagName('tMed')->item(0)->nodeValue,
396
            'cUF' => $tag->getElementsByTagName('cUF')->item(0)->nodeValue
397
        );
398
        return $aResposta;
399
    }
400
    
401
    /**
402
     * zReadRecepcaoEvento
403
     *
404
     * @param  DOMDocument $dom
405
     * @return string
406
     */
407
    protected static function zReadRecepcaoEvento($dom)
408
    {
409
        //retorno da funçao
410
        $aResposta = array(
411
            'bStat' => false,
412
            'versao' => '',
413
            'verAplic' => '',
414
            'tpAmb' => '',
415
            'id' => '',
416
            'cOrgao' => '',
417
            'cStat' => '',
418
            'xMotivo' => '',
419
            'evento' => array()
420
        );
421
        $tag = $dom->getElementsByTagName('retEventoCTe')->item(0);
422
        if (! isset($tag)) {
423
            return $aResposta;
424
        }
425
        $aResposta = array(
426
            'bStat' => true,
427
            'versao' => $tag->getAttribute('versao'),
428
            //'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...
429
            'tpAmb' => $tag->getElementsByTagName('tpAmb')->item(0)->nodeValue,
430
            'verAplic' => $tag->getElementsByTagName('verAplic')->item(0)->nodeValue,
431
            'cOrgao' => $tag->getElementsByTagName('cOrgao')->item(0)->nodeValue,
432
            'cStat' => $tag->getElementsByTagName('cStat')->item(0)->nodeValue,
433
            'xMotivo' => $tag->getElementsByTagName('xMotivo')->item(0)->nodeValue
434
        //,
435
          //  '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...
436
        );
437
        return $aResposta;
438
    }
439
    
440
    /**
441
     * zGetProt
442
     *
443
     * @param  DOMDocument $tag
444
     * @return type
445
     */
446
    private static function zGetProt($tag)
447
    {
448
        $aProt = array();
449
        $infProt = $tag->getElementsByTagName('infProt')->item(0);
450
        if (isset($infProt)) {
451
            $aProt['tpAmb'] = $infProt->getElementsByTagName('tpAmb')->item(0)->nodeValue;
452
            $aProt['verAplic'] = $infProt->getElementsByTagName('verAplic')->item(0)->nodeValue;
453
            $aProt['chCTe'] = $infProt->getElementsByTagName('chCTe')->item(0)->nodeValue;
454
            $aProt['dhRecbto'] = $infProt->getElementsByTagName('dhRecbto')->item(0)->nodeValue;
455
            $aProt['nProt'] = isset($infProt->getElementsByTagName('nProt')->item(0)->nodeValue) ?
456
                $infProt->getElementsByTagName('nProt')->item(0)->nodeValue : '';
457
            $aProt['digVal'] = $infProt->getElementsByTagName('digVal')->item(0)->nodeValue;
458
            $aProt['cStat'] = $infProt->getElementsByTagName('cStat')->item(0)->nodeValue;
459
            $aProt['xMotivo'] = $infProt->getElementsByTagName('xMotivo')->item(0)->nodeValue;
460
        }
461
        return $aProt;
462
    }
463
    
464
    /**
465
     * zGetEvent
466
     *
467
     * @param  DOMDocument $tag
468
     * @return array
469
     */
470
    private static function zGetEvent($tag)
471
    {
472
        $aEvent = array();
473
        $infEvento = $tag->getElementsByTagName('infEvento')->item(0);
474
        if (isset($infEvento)) {
475
            $aEvent = array(
476
                'chCTe' => $infEvento->getElementsByTagName('chCTe')->item(0)->nodeValue,
477
                'tpEvento' => $infEvento->getElementsByTagName('tpEvento')->item(0)->nodeValue,
478
                'xEvento' => $infEvento->getElementsByTagName('xEvento')->item(0)->nodeValue,
479
                'nSeqEvento' => $infEvento->getElementsByTagName('nSeqEvento')->item(0)->nodeValue,
480
                'dhRegEvento' => $infEvento->getElementsByTagName('dhRegEvento')->item(0)->nodeValue,
481
                'nProt' => $infEvento->getElementsByTagName('nProt')->item(0)->nodeValue
482
            );
483
        }
484
        return $aEvent;
485
    }
486
487
    /**
488
     * zGetCanc
489
     *
490
     * @param  DOMDocument $tag
491
     * @return type
492
     */
493
    private static function zGetCanc($tag)
494
    {
495
        $aCanc = array();
496
        $infCanc = $tag->getElementsByTagName('infCanc');
497
        if (! empty($infCanc)) {
498
            $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...
499
            $aProt['verAplic'] = $infCanc->getElementsByTagName('verAplic')->item(0)->nodeValue;
500
            $aProt['cStat'] = $infCanc->getElementsByTagName('cStat')->item(0)->nodeValue;
501
            $aProt['xMotivo'] = $infCanc->getElementsByTagName('xMotivo')->item(0)->nodeValue;
502
            $aProt['cUF'] = $infCanc->getElementsByTagName('cUF')->item(0)->nodeValue;
503
            $aProt['chCTe'] = $infCanc->getElementsByTagName('chCTe')->item(0)->nodeValue;
504
            $aProt['dhRecbto'] = $infCanc->getElementsByTagName('dhRecbto')->item(0)->nodeValue;
505
            $aProt['nProt'] = $infCanc->getElementsByTagName('nProt')->item(0)->nodeValue;
506
        }
507
        return $aCanc;
508
    }
509
}
510