XmlService::xmlToStdClass()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
namespace Ipag\Classes\Services;
4
5
final class XmlService
6
{
7
    public function validate($message)
8
    {
9
        libxml_use_internal_errors(true);
10
        $response = simplexml_load_string($message, 'SimpleXMLElement', LIBXML_NOCDATA);
11
12
        if ($response === false) {
13
            $unvalidatedMessage = is_string($message) ? $message : '';
14
            throw new \Exception('Não foi possível identificar o XML de retorno.'.$unvalidatedMessage);
15
        }
16
17
        return $response;
18
    }
19
20
    public function xmlToStdClass($xml)
21
    {
22
        return json_decode(json_encode((array) $xml));
23
    }
24
}
25