Completed
Branch master (36e7ce)
by Xeriab
01:56
created

Xml::getSupportedFileExtensions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Konfig
4
 *
5
 * Yet another simple configuration 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
12
namespace Exen\Konfig\FileParser;
13
14
use Exen\Konfig\Exception\ParseException;
15
16
class Xml extends AbstractFileParser
17
{
18
    /**
19
     * {@inheritDoc}
20
     * Loads a XML file as an array
21
     *
22
     * @throws ParseException If there is an error parsing XML file
23
     * @since 0.1
24
     */
25 6
    public function parse($path)
26
    {
27 6
        $data = simplexml_load_file($path, 'SimpleXMLElement', LIBXML_NOWARNING | LIBXML_NOERROR);
28
29 6
        if ($data === false) {
30 3
            $lastError = libxml_get_last_error();
31 3
            if ($lastError !== false) {
32 3
                throw new ParseException([
33 3
                    'message' => $lastError->message,
34 3
                    'type'    => $lastError->level,
35 3
                    'code'    => $lastError->code,
36 3
                    'file'    => $lastError->file,
37 3
                    'line'    => $lastError->line,
38 2
                ]);
39
            }
40
        }
41
42 3
        $data = json_decode(json_encode($data), true);
43
44 3
        return $data;
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50 3
    public function getSupportedFileExtensions()
51
    {
52 3
        return ['xml'];
53
    }
54
}
55
56
#: END OF ./src/FileParser/Xml.php FILE
57