StatementSerializer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\XApi\Serializer\Symfony;
13
14
use Symfony\Component\Serializer\SerializerInterface;
15
use Xabbuh\XApi\Model\Statement;
16
use Xabbuh\XApi\Serializer\StatementSerializerInterface;
17
18
/**
19
 * Serializes and deserializes {@link Statement statements} using the Symfony Serializer component.
20
 *
21
 * @author Christian Flothmann <[email protected]>
22
 */
23
final class StatementSerializer implements StatementSerializerInterface
24
{
25
    /**
26
     * @var SerializerInterface The underlying serializer
27
     */
28
    private $serializer;
29
30
    public function __construct(SerializerInterface $serializer)
31
    {
32
        $this->serializer = $serializer;
33
    }
34
35
    /**
36
     * {@inheritDoc}
37
     */
38
    public function serializeStatement(Statement $statement)
39
    {
40
        return $this->serializer->serialize($statement, 'json');
41
    }
42
43
    /**
44
     * {@inheritDoc}
45
     */
46
    public function serializeStatements(array $statements)
47
    {
48
        return $this->serializer->serialize($statements, 'json');
49
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54
    public function deserializeStatement($data, array $attachments = array())
55
    {
56
        return $this->serializer->deserialize(
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->serializer->deser...nts' => $attachments)); of type object|array adds the type array to the return on line 56 which is incompatible with the return type declared by the interface Xabbuh\XApi\Serializer\S...e::deserializeStatement of type Xabbuh\XApi\Model\Statement.
Loading history...
57
            $data,
58
            'Xabbuh\XApi\Model\Statement',
59
            'json',
60
            array(
61
                'xapi_attachments' => $attachments,
62
            )
63
        );
64
    }
65
66
    /**
67
     * {@inheritDoc}
68
     */
69
    public function deserializeStatements($data, array $attachments = array())
70
    {
71
        return $this->serializer->deserialize(
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->serializer->deser...nts' => $attachments)); of type object|array adds the type object to the return on line 71 which is incompatible with the return type declared by the interface Xabbuh\XApi\Serializer\S...::deserializeStatements of type Xabbuh\XApi\Model\Statement[].
Loading history...
72
            $data,
73
            'Xabbuh\XApi\Model\Statement[]',
74
            'json',
75
            array(
76
                'xapi_attachments' => $attachments,
77
            )
78
        );
79
    }
80
}
81