Completed
Branch master (36e7ce)
by Xeriab
01:56
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 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 Exception;
15
use Exen\Konfig\Exception\ParseException;
16
use Symfony\Component\Yaml\Yaml as YamlParser;
17
18
class Yaml extends AbstractFileParser
19
{
20
    /**
21
     * {@inheritDoc}
22
     * Loads a YAML/YML file as an array
23
     *
24
     * @throws ParseException If there is an error parsing YAML/YML file
25
     * @since 0.1
26
     */
27 6
    public function parse($path)
28
    {
29
        try {
30 6
            $data = null;
31
32
            // Check if the PHP native's YAML extension is exist
33 6
            if (!extension_loaded('yaml')) {
34 6
                $data = YamlParser::parse(file_get_contents($path));
35 2
            } else {
36 1
                $data = yaml_parse_file($path);
37
            }
38 5
        } catch (Exception $ex) {
39 3
            throw new ParseException(
40
                [
41 3
                    'message'   => 'Error parsing YAML file',
42 3
                    'exception' => $ex,
43
                ]
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