YamlSerializationVisitor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 44
ccs 8
cts 10
cp 0.8
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A encode() 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\Accessor\AccessorInterface;
15
use Ivory\Serializer\Visitor\AbstractSerializationVisitor;
16
use Symfony\Component\Yaml\Yaml;
17
18
/**
19
 * @author GeLo <[email protected]>
20
 */
21
class YamlSerializationVisitor extends AbstractSerializationVisitor
22
{
23
    /**
24
     * @var int
25
     */
26
    private $inline;
27
28
    /**
29
     * @var int
30
     */
31
    private $indent;
32
33
    /**
34
     * @var int
35
     */
36
    private $options;
37
38
    /**
39
     * @param AccessorInterface $accessor
40
     * @param int               $inline
41
     * @param int               $indent
42
     * @param int               $options
43
     */
44 1492
    public function __construct(AccessorInterface $accessor, $inline = 2, $indent = 4, $options = 0)
45
    {
46 1492
        parent::__construct($accessor);
47
48 1492
        $this->inline = $inline;
49 1492
        $this->indent = $indent;
50 1492
        $this->options = $options;
51 1492
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 220
    protected function encode($data)
57
    {
58
        try {
59 220
            return Yaml::dump($data, $this->inline, $this->indent, $this->options);
60
        } catch (\Exception $e) {
61
            throw new \InvalidArgumentException('Unable to serialize data.', 0, $e);
62
        }
63
    }
64
}
65