Passed
Push — master ( 6466f2...326f15 )
by Antônio
01:59
created

DebugMode::filtrarDados()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 4
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace OBRSDK;
10
11
/**
12
 * Description of DevMode
13
 *
14
 * @author Antonio
15
 */
16
abstract class DebugMode {
17
18
    protected static $debugModeStatus = false;
19
20
    /**
21
     *
22
     * @var \OBRSDK\IDebugModeCallback
23
     */
24
    protected static $debugObject;
25
26
    public static function setDebugObject(\OBRSDK\IDebugModeCallback $callback) {
27
        self::$debugModeStatus = true;
28
        self::$debugObject = $callback;
29
    }
30
31
    protected function debugDadosEnviado($uri, $type, $dados) {
32
        try {
33
            if (self::$debugModeStatus) {
34
                self::$debugObject->dadosEnviado($uri, $type, $dados);
35
            }
36
        } catch (\Exception $ex) {
37
            return;
38
        }
39
    }
40
41
    protected function debugDadosRecebido($uri, $type, $dados, $headers, $statusCode) {
42
        try {
43
            if (!self::$debugModeStatus) {
44
                return;
45
            }
46
47
            $json_decode = null;
48
            $this->filtrarDados($dados, $json_decode);
49
50
            self::$debugObject->dadosRecebido($uri, $type, $json_decode, $headers == null ? [] : $headers, $statusCode);
0 ignored issues
show
Bug introduced by
$json_decode of type null is incompatible with the type array expected by parameter $corpoRecebido of OBRSDK\IDebugModeCallback::dadosRecebido(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
            self::$debugObject->dadosRecebido($uri, $type, /** @scrutinizer ignore-type */ $json_decode, $headers == null ? [] : $headers, $statusCode);
Loading history...
51
        } catch (\Exception $ex) {
52
            return;
53
        }
54
    }
55
56
    private function filtrarDados(&$dados, &$json_decode) {
57
        if (is_null($dados)) {
58
            $dados = '{}';
59
        }
60
61
        $json_decode = json_decode($dados, true);
62
        if ($json_decode == null) {
63
            $json_decode = ['json_decode_falha' => $dados];
64
        }
65
    }
66
67
}
68