Completed
Push — master ( a7a790...5c4323 )
by Eric
03:39
created

AbstractSerializationVisitor::createResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 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 738
    public function __construct(AccessorInterface $accessor)
32
    {
33 738
        $this->accessor = $accessor;
34 738
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 294
    public function getResult()
40
    {
41 294
        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 240 View Code Duplication
    protected function doVisitObjectProperty(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
        $data,
56
        $name,
57
        PropertyMetadataInterface $property,
58
        ContextInterface $context
59
    ) {
60 240
        if (!$property->isReadable()) {
61 12
            return false;
62
        }
63
64
        // FIXME - Detect errors
65 240
        $result = $this->navigator->navigate(
66 240
            $this->accessor->getValue(
67 160
                $data,
68 240
                $property->hasAccessor() ? $property->getAccessor() : $property->getName()
69 160
            ),
70 160
            $context,
71 240
            $property->getType()
72 160
        );
73
74 240
        if ($result === null && $context->isNullIgnored()) {
75 12
            return false;
76
        }
77
78 234
        $this->result[$name] = $result;
79
80 234
        return true;
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86 240
    protected function createResult($class)
87
    {
88 240
        return [];
89
    }
90
}
91