AbstractSerializationVisitor   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 5
dl 0
loc 69
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getResult() 0 4 1
encode() 0 1 ?
B doVisitObjectProperty() 0 27 5
A createResult() 0 4 1
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;
13
14
use Ivory\Serializer\Accessor\AccessorInterface;
15
use Ivory\Serializer\Context\ContextInterface;
16
use Ivory\Serializer\Mapping\PropertyMetadataInterface;
17
18
/**
19
 * @author GeLo <[email protected]>
20
 */
21
abstract class AbstractSerializationVisitor extends AbstractGenericVisitor
22
{
23
    /**
24
     * @var AccessorInterface
25
     */
26
    private $accessor;
27
28
    /**
29
     * @param AccessorInterface $accessor
30
     */
31 1492
    public function __construct(AccessorInterface $accessor)
32
    {
33 1492
        $this->accessor = $accessor;
34 1492
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 668
    public function getResult()
40
    {
41 668
        return $this->encode($this->result);
42
    }
43
44
    /**
45
     * @param mixed $data
46
     *
47
     * @return mixed
48
     */
49
    abstract protected function encode($data);
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 504
    protected function doVisitObjectProperty(
55
        $data,
56
        $name,
57
        PropertyMetadataInterface $property,
58
        ContextInterface $context
59
    ) {
60 504
        if (!$property->isReadable()) {
61 24
            return false;
62
        }
63
64 504
        $result = $this->navigator->navigate(
65 504
            $this->accessor->getValue(
66 252
                $data,
67 504
                $property->hasAccessor() ? $property->getAccessor() : $property->getName()
68 252
            ),
69 252
            $context,
70 504
            $property->getType()
71 252
        );
72
73 504
        if ($result === null && $context->isNullIgnored()) {
74 24
            return false;
75
        }
76
77 492
        $this->result[$name] = $result;
78
79 492
        return true;
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85 504
    protected function createResult($class)
86
    {
87 504
        return [];
88
    }
89
}
90