Completed
Push — master ( 5c0ad8...d30cdc )
by Filip
08:38 queued 07:33
created

Yaml::getSupportedExtensions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

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
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Noodlehaus\Parser;
4
5
use Exception;
6
use Symfony\Component\Yaml\Yaml as YamlParser;
7
use Noodlehaus\Exception\ParseException;
8
9
/**
10
 * YAML parser
11
 *
12
 * @package    Config
13
 * @author     Jesus A. Domingo <[email protected]>
14
 * @author     Hassan Khan <[email protected]>
15
 * @author     Filip Š <[email protected]>
16
 * @link       https://github.com/noodlehaus/config
17
 * @license    MIT
18
 */
19
class Yaml implements ParserInterface
20
{
21
    /**
22
     * {@inheritDoc}
23
     * Loads a YAML/YML file as an array
24
     *
25
     * @throws ParseException If there is an error parsing the YAML file
26
     */
27 6
    public function parseFile($filename)
28
    {
29
        try {
30 6
            $data = YamlParser::parseFile($filename, YamlParser::PARSE_CONSTANT);
31 3
        } catch (Exception $exception) {
32 3
            throw new ParseException(
33
                [
34 3
                    'message'   => 'Error parsing YAML file',
35 3
                    'exception' => $exception,
36
                ]
37
            );
38
        }
39
40 3
        return (array)$this->parse($data);
41
    }
42
43
    /**
44
     * {@inheritDoc}
45
     * Loads a YAML/YML string as an array
46
     *
47
     * @throws ParseException If If there is an error parsing the YAML string
48
     */
49 6
    public function parseString($config)
50
    {
51
        try {
52 6
            $data = YamlParser::parse($config, YamlParser::PARSE_CONSTANT);
53 3
        } catch (Exception $exception) {
54 3
            throw new ParseException(
55
                [
56 3
                    'message'   => 'Error parsing YAML string',
57 3
                    'exception' => $exception,
58
                ]
59
            );
60
        }
61
62 3
        return (array)$this->parse($data);
63
    }
64
65
    /**
66
     * Completes parsing of YAML/YML data
67
     *
68
     * @param  array $data
69
     *
70
     * @return array|null
71
     */
72 6
    protected function parse($data = null)
73
    {
74 6
        return $data;
75
    }
76
77
    /**
78
     * {@inheritDoc}
79
     */
80 3
    public static function getSupportedExtensions()
81
    {
82 3
        return ['yaml', 'yml'];
83
    }
84
}
85