Sf2Yaml   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 16
dl 0
loc 69
ccs 18
cts 18
cp 1
rs 10
c 1
b 0
f 1
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A isAvailable() 0 3 1
A parseFile() 0 3 1
A tryParseBuffer() 0 9 2
A parseBuffer() 0 14 3
A tryParseFile() 0 3 1
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\Yaml;
6
7
use Ktomk\Symfony\Component\Yaml\Exception\ParseException as SymfonyParseException;
8
use Ktomk\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 $path
22
     *
23
     * @throws ParseException
24
     *
25
     * @return null|array
26
     */
27 4
    public function parseFile($path)
28
    {
29 4
        return Yaml::fileDelegate($path, array($this, 'parseBuffer'));
30
    }
31
32
    /**
33
     * @param string $path
34
     *
35
     * @return null|array
36
     */
37 5
    public function tryParseFile($path)
38
    {
39 5
        return Yaml::fileDelegate($path, array($this, 'tryParseBuffer'));
40
    }
41
42
    /**
43
     * @param $buffer
44
     *
45
     * @throws ParseException
46
     *
47
     * @return array
48
     */
49 5
    public function parseBuffer($buffer)
50
    {
51
        try {
52 5
            $result = SymfonyYaml::parse($buffer);
53 3
        } catch (SymfonyParseException $ex) {
54 3
            throw new ParseException($ex->getMessage(), 0, $ex);
55
        }
56
57
        # catch sf2 invalid yaml parsing
58 3
        if (array(':') === $result) {
59 1
            throw new ParseException('Sf2Yaml invalid YAML parsing', 0);
60
        }
61
62 2
        return $result;
63
    }
64
65
    /**
66
     * @param string $buffer
67
     *
68
     * @return null|array
69
     */
70 5
    public function tryParseBuffer($buffer)
71
    {
72
        try {
73 5
            $result = $this->parseBuffer($buffer);
74 4
        } catch (ParseException $ex) {
75 4
            return null;
76
        }
77
78 2
        return $result;
79
    }
80
}
81