ParserXML   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 36
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A parseXML() 0 10 2
A isValid() 0 10 3
A getErrors() 0 4 1
A xml16To8Utf() 0 4 1
1
<?php
2
namespace Dwr\GlobalWeatherBundle\Utility;
3
4
class ParserXML
5
{
6
    private $errors = array();
7
8
    public function parseXML($xmlString)
9
    {
10
        libxml_use_internal_errors(true);
11
        $xml = simplexml_load_string($this->xml16To8Utf($xmlString));
12
13
        if ($this->isValid($xml)) {
14
            return $xml;
15
        }
16
        return false;
17
    }
18
19
    public function isValid($xml)
20
    {
21
        if (false === $xml) {
22
            foreach (libxml_get_errors() as $error) {
23
                $this->errors[] = $error->message;
24
            }
25
            return false;
26
        }
27
        return true;
28
    }
29
30
    public function getErrors()
31
    {
32
        return $this->errors;
33
    }
34
35
    private function xml16To8Utf($xml)
36
    {
37
        return preg_replace('/(<\?xml[^?]+?)utf-16/i', '$1utf-8', $xml);
38
    }
39
}
40