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

Sf2Yaml   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
c 1
b 0
f 1
dl 0
loc 37
ccs 11
cts 11
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parseFile() 0 3 1
A isAvailable() 0 3 1
A parseBuffer() 0 14 3
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