Passed
Push — test ( c83959...71d777 )
by Tom
04:01
created

Sf2Yaml::parseBuffer()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 7
c 1
b 0
f 1
nc 3
nop 1
dl 0
loc 14
ccs 7
cts 7
cp 1
crap 3
rs 10
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\Yaml;
6
7
use Symfony\Component\Yaml\Exception\ParseException;
8
use Symfony\Component\Yaml\Yaml as SymfonyYaml;
9
10
class Sf2Yaml implements ParserInterface
11
{
12
    /**
13
     * @return bool
14
     */
15 1
    public static function isAvailable()
16
    {
17 1
        return true;
18
    }
19
20
    /**
21
     * @param string $path
22
     * @return null|array
23
     */
24 3
    public function parseFile($path)
25
    {
26 3
        return $this->parseBuffer(@file_get_contents($path));
27
    }
28
29
    /**
30
     * @param string $buffer
31
     * @return null|array
32
     */
33 3
    public function parseBuffer($buffer)
34
    {
35
        try {
36 3
            $result = SymfonyYaml::parse($buffer);
37 1
        } catch (ParseException $ex) {
38 1
            return null;
39
        }
40
41
        # catch sf2 invalid yaml parsing
42 3
        if (array(':') === $result) {
43 1
            return null;
44
        }
45
46 2
        return $result;
47
    }
48
}
49