Yaml::unpack()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 0
cts 5
cp 0
crap 6
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