Completed
Push — master ( b06bec...8d39d6 )
by Xeriab
03:49
created

Yaml::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 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * Konfig
5
 *
6
 * Yet another simple configuration loader library.
7
 *
8
 * @author  Xeriab Nabil (aka KodeBurner) <[email protected]>
9
 * @license https://raw.github.com/xeriab/konfig/master/LICENSE MIT
10
 * @link    https://xeriab.github.io/projects/konfig
11
 */
12
13
namespace Exen\Konfig\FileParser;
14
15
use Exen\Konfig\Exception\ParseException;
16
17
use Symfony\Component\Yaml\Yaml as YamlParser;
18
19
class Yaml extends AbstractFileParser
20
{
21
    /**
22
     * {@inheritDoc}
23
     * Loads a YAML/YML file as an array
24
     *
25
     * @throws ParseException If there is an error parsing YAML/YML file
26
     * @since 0.1.0
27
     */
28 6
    public function parse($path)
29
    {
30 6
        $data = null;
31
32
        try {
33
            // Check if the PHP native's YAML extension is exist
34 6
            if (!extension_loaded('yaml')) {
35 6
                $data = YamlParser::parse(file_get_contents(realpath($path)));
36 2
            } else {
37 1
                $data = yaml_parse_file($path);
38
            }
39 5
        } catch (\Exception $ex) {
40 3
            throw new ParseException([
41 3
                'message' => 'Error parsing YAML file',
42 3
                'file' => $path,
43 3
                'exception' => $ex,
44 2
            ]);
45
        }
46
47 3
        return $data;
48
    }
49
50
    /**
51
     * {@inheritDoc}
52
     */
53 3
    public function getSupportedFileExtensions()
54
    {
55 3
        return ['yaml', 'yml'];
56
    }
57
}
58
59
// END OF ./src/FileParser/Yaml.php FILE
60