Passed
Push — master ( c85748...2fd0ab )
by Petr
08:11
created

Yaml::pack()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace kalanis\kw_mapper\Storage\Shared\FormatFiles;
4
5
6
use kalanis\kw_mapper\Interfaces\IFileFormat;
7
use kalanis\kw_mapper\MapperException;
8
9
10
/**
11
 * Class Yaml
12
 * @package kalanis\kw_mapper\Storage\Shared\FormatFiles
13
 */
14
class Yaml implements IFileFormat
15
{
16
    public function unpack(string $content): array
17
    {
18
        $result = @yaml_parse($content);
19
        if (false === $result) {
20
            throw new MapperException('Cannot parse YAML input');
21
        }
22
        return $result;
23
    }
24
25
    public function pack(array $records): string
26
    {
27
        return yaml_emit($records);
28
    }
29
}
30