YamlHandler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Majora\Framework\Serializer\Handler\Yaml;
4
5
use Majora\Framework\Normalizer\MajoraNormalizer;
6
use Majora\Framework\Serializer\Handler\AbstractFormatHandler;
7
use Symfony\Component\Yaml\Yaml;
8
9
/**
10
 * Handler implementation creating and using yaml.
11
 */
12
class YamlHandler extends AbstractFormatHandler
13
{
14
    /**
15
     * @var Yaml
16
     */
17
    protected $yamlParser;
18
19
    /**
20
     * construct.
21
     *
22
     * @param Yaml             $yamlParser
23
     * @param MajoraNormalizer $normalizer
24
     */
25 12
    public function __construct(Yaml $yamlParser, MajoraNormalizer $normalizer)
26
    {
27 12
        $this->yamlParser = $yamlParser;
28
29 12
        parent::__construct($normalizer);
30 12
    }
31
32
    /**
33
     * @see FormatHandlerInterface::serialize()
34
     */
35 6
    public function serialize($data, $scope)
36
    {
37 6
        return $this->yamlParser->dump(
38 6
            $this->normalizer->normalize($data, $scope)
39 3
        );
40
    }
41
42
    /**
43
     * @see FormatHandlerInterface::deserialize()
44
     */
45 6
    public function deserialize($data, $output)
46
    {
47 6
        return $this->normalizer->denormalize(
48 6
            $this->yamlParser->parse($data),
49
            $output
50 3
        );
51
    }
52
}
53