Completed
Push — master ( 76163c...0c83ff )
by Nashwan
03:43
created

Xml   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 5
Bugs 2 Features 0
Metric Value
wmc 4
c 5
b 2
f 0
lcom 0
cbo 2
dl 0
loc 39
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 21 3
A getSupportedFileExtensions() 0 4 1
1
<?php
2
/**
3
 * Konfig
4
 *
5
 * Yet another simple configuration file loader library.
6
 *
7
 * @author  Xeriab Nabil (aka KodeBurner) <[email protected]>
8
 * @license https://raw.github.com/xeriab/konfig/master/LICENSE MIT
9
 * @link    https://xeriab.github.io/projects/konfig
10
 */
11
namespace Exen\Konfig\FileParser;
12
13
use Exen\Konfig\Exception\ParseException;
14
15
class Xml extends AbstractFileParser
16
{
17
    /**
18
     * {@inheritDoc}
19
     * Loads a XML file as an array
20
     *
21
     * @throws ParseException If there is an error parsing XML file
22
     * @since 0.1
23
     */
24
    public function parse($path)
25
    {
26
        $data = simplexml_load_file($path, 'SimpleXMLElement', LIBXML_NOWARNING | LIBXML_NOERROR);
27
28
        if ($data === false) {
29
            $lastError = libxml_get_last_error();
30
            if ($lastError !== false) {
31
                throw new ParseException([
32
                    'message' => $lastError->message,
33
                    'type'    => $lastError->level,
34
                    'code'    => $lastError->code,
35
                    'file'    => $lastError->file,
36
                    'line'    => $lastError->line,
37
                ]);
38
            }
39
        }
40
41
        $data = json_decode(json_encode($data), true);
42
43
        return $data;
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49
    public function getSupportedFileExtensions()
50
    {
51
        return ['xml'];
52
    }
53
}
54
55
#: END OF ./src/FileParser/Xml.php FILE
56