Passed
Push — master ( e850ef...69529f )
by Roberto
02:10
created

FakePretty   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 62
ccs 0
cts 58
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B prettyPrint() 0 59 5
1
<?php
2
3
namespace NFePHP\EFDReinf\Common;
4
5
/**
6
 * Class FakePretty shows event and fake comunication data for analises and debugging
7
 *
8
 * @category  API
9
 * @package   NFePHP\EFDReinf
10
 * @copyright NFePHP Copyright (c) 2017
11
 * @license   http://www.gnu.org/licenses/lgpl.txt LGPLv3+
12
 * @license   https://opensource.org/licenses/MIT MIT
13
 * @license   http://www.gnu.org/licenses/gpl.txt GPLv3+
14
 * @author    Roberto L. Machado <linux.rlm at gmail dot com>
15
 * @link      http://github.com/nfephp-org/sped-efdreinf for the canonical source repository
16
 */
17
18
class FakePretty
19
{
20
    public static function prettyPrint($response, $save = '')
21
    {
22
        if (empty($response)) {
23
            $html = "Sem resposta";
24
            return $html;
25
        }
26
        $std = json_decode($response);
27
        if (!empty($save)) {
28
            file_put_contents(
29
                "/var/www/sped/sped-efdreinf/tests/fixtures/xml/$save.xml",
30
                $std->body
31
            );
32
        }
33
        $doc = new \DOMDocument('1.0', 'UTF-8');
34
        $doc->preserveWhiteSpace = false;
35
        $doc->formatOutput = true;
36
        $doc->loadXML($std->body);
37
38
        $html = "<pre>";
39
        $html .= '<h2>url</h2>';
40
        $html .= $std->url;
41
        $html .= "<br>";
42
        $html .= '<h2>operation</h2>';
43
        $html .= "<br>";
44
        $html .= $std->operation;
45
        $html .= "<br>";
46
        $html .= '<h2>action</h2>';
47
        $html .= $std->action;
48
        $html .= "<br>";
49
        $html .= '<h2>soapver</h2>';
50
        $html .= $std->soapver;
51
        $html .= "<br>";
52
        $html .= '<h2>parameters</h2>';
53
        foreach ($std->parameters as $key => $param) {
54
            $html .= "[$key] => $param <br>";
55
        }
56
        $html .= "<br>";
57
        $html .= '<h2>header</h2>';
58
        $html .= $std->header;
59
        $html .= "<br>";
60
        $html .= '<h2>namespaces</h2>';
61
        $an = json_decode(json_encode($std->namespaces), true);
62
        foreach ($an as $key => $nam) {
63
            $html .= "[$key] => $nam <br>";
64
        }
65
        $html .= "<br>";
66
        $html .= '<h2>body</h2>';
67
        $html .= str_replace(
68
            ['<', '>'],
69
            ['&lt;','&gt;'],
70
            str_replace(
71
                '<?xml version="1.0"?>',
72
                '<?xml version="1.0" encoding="UTF-8"?>',
73
                $doc->saveXML()
74
            )
75
        );
76
        $html .= "</pre>";
77
        return $html;
78
    }
79
}
80