Passed
Push — test ( 3544e7...181b61 )
by Tom
02:31
created

Yaml   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 46
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parser() 0 16 3
A buffer() 0 3 1
A file() 0 9 2
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\Yaml;
6
7
use Ktomk\Pipelines\LibFs;
8
9
class Yaml
10
{
11
    /**
12
     * @param $path
13
     * @throws \InvalidArgumentException
14
     * @return null|array on error
15
     */
16 3
    public static function file($path)
17
    {
18 3
        if (!LibFs::isReadableFile($path)) {
19 1
            throw new \InvalidArgumentException(
20 1
                sprintf("not a readable file: '%s'", $path)
21
            );
22
        }
23
24 2
        return self::parser()->parseFile($path);
25
    }
26
27
    /**
28
     * @param string $buffer
29
     * @return null|array
30
     */
31 1
    public static function buffer($buffer)
32
    {
33 1
        return self::parser()->parseBuffer($buffer);
34
    }
35
36
    /**
37
     * @return ParserInterface
38
     */
39 3
    private static function parser()
40
    {
41
        $classes = array(
42 3
            'Ktomk\Pipelines\Yaml\LibYaml',
43
            'Ktomk\Pipelines\Yaml\Spyc',
44
        );
45
46 3
        $class = null;
47
48 3
        foreach ($classes as $class) {
49 3
            if ($class::isAvailable()) {
50 3
                break;
51
            }
52
        }
53
54 3
        return new $class;
55
    }
56
}
57