Passed
Pull Request — master (#1)
by João Felipe Magro
01:22
created

XmlService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 17
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 10 2
A xmlToStdClass() 0 3 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
            throw new \Exception('Não foi possível identificar o XML de retorno.');
14
        }
15
16
        return $response;
17
    }
18
19
    public function xmlToStdClass($xml)
20
    {
21
        return json_decode(json_encode((array) $xml));
22
    }
23
}
24