XmlService::validate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 3
nc 3
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