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

Yaml::buffer()   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 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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