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

Sf2Yaml::parseFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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