YamlDeserializationVisitor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
dl 0
loc 31
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2
ccs 6
cts 8
cp 0.75
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A decode() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of the Ivory Serializer package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\Serializer\Visitor\Yaml;
13
14
use Ivory\Serializer\Instantiator\InstantiatorInterface;
15
use Ivory\Serializer\Mutator\MutatorInterface;
16
use Ivory\Serializer\Visitor\AbstractDeserializationVisitor;
17
use Symfony\Component\Yaml\Yaml;
18
19
/**
20
 * @author GeLo <[email protected]>
21
 */
22
class YamlDeserializationVisitor extends AbstractDeserializationVisitor
23
{
24
    /**
25
     * @var int
26
     */
27
    private $options;
28
29
    /**
30
     * @param InstantiatorInterface $instantiator
31
     * @param MutatorInterface      $mutator
32
     * @param int                   $options
33
     */
34 1492
    public function __construct(InstantiatorInterface $instantiator, MutatorInterface $mutator, $options = 0)
35
    {
36 1492
        parent::__construct($instantiator, $mutator);
37
38 1492
        $this->options = $options;
39 1492
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 144
    protected function decode($data)
45
    {
46
        try {
47 144
            return Yaml::parse($data, $this->options);
48
        } catch (\Exception $e) {
49
            throw new \InvalidArgumentException('Unable to deserialize data.', 0, $e);
50
        }
51
    }
52
}
53