Completed
Push — master ( 2b8886...d0ff07 )
by Xeriab
04:16
created

Yaml   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 36
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 18 3
A getSupportedFileExtensions() 0 4 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 Exception;
16
use Exen\Konfig\Exception\ParseException;
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
27
     */
28 6
    public function parse($path)
29
    {
30
        try {
31
            // Check if the PHP native's YAML extension is exist
32 6
            if (!extension_loaded('yaml')) {
33 6
                $data = YamlParser::parse(file_get_contents($path));
34 2
            } else {
35 1
                $data = yaml_parse_file($path);
36
            }
37 5
        } catch (Exception $ex) {
38 3
            throw new ParseException([
39 3
                'message'   => 'Error parsing YAML file',
40 3
                'exception' => $ex,
41 2
            ]);
42
        }
43
44 3
        return $data;
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50 3
    public function getSupportedFileExtensions()
51
    {
52 3
        return ['yaml', 'yml'];
53
    }
54
}
55
56
#: END OF ./src/FileParser/Yaml.php FILE
57