StatementResultSerializer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 35
loc 35
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A serializeStatementResult() 4 4 1
A deserializeStatementResult() 11 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\StatementResult;
16
use Xabbuh\XApi\Serializer\StatementResultSerializerInterface;
17
18
/**
19
 * Serializes and deserializes {@link StatementResult statement results} using the Symfony Serializer component.
20
 *
21
 * @author Christian Flothmann <[email protected]>
22
 */
23 View Code Duplication
final class StatementResultSerializer implements StatementResultSerializerInterface
0 ignored issues
show
Duplication introduced by
This class 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...
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 serializeStatementResult(StatementResult $statementResult)
39
    {
40
        return $this->serializer->serialize($statementResult, 'json');
41
    }
42
43
    /**
44
     * {@inheritDoc}
45
     */
46
    public function deserializeStatementResult($data, array $attachments = array())
47
    {
48
        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 48 which is incompatible with the return type declared by the interface Xabbuh\XApi\Serializer\S...erializeStatementResult of type Xabbuh\XApi\Model\StatementResult.
Loading history...
49
            $data,
50
            'Xabbuh\XApi\Model\StatementResult',
51
            'json',
52
            array(
53
                'xapi_attachments' => $attachments,
54
            )
55
        );
56
    }
57
}
58