Completed
Pull Request — master (#80)
by John
02:58
created

ArraySerializer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 32.26 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 4 1
A deserialize() 10 10 2

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 declare(strict_types = 1);
2
/*
3
 * This file is part of the KleijnWeb\SwaggerBundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\SwaggerBundle\Serialize\Serializer;
10
11
use KleijnWeb\SwaggerBundle\Document\Specification;
12
use KleijnWeb\SwaggerBundle\Serialize\Serializer;
13
14
/**
15
 * Simply utilizes json_encode/json_decode
16
 *
17
 * @author John Kleijn <[email protected]>
18
 */
19
class ArraySerializer implements Serializer
20
{
21
    /**
22
     * @param mixed         $data
23
     * @param Specification $specification
24
     *
25
     * @return string
26
     */
27
    public function serialize($data, Specification $specification): string
28
    {
29
        return json_encode($data);
30
    }
31
32
    /**
33
     * @param mixed         $data
34
     * @param Specification $specification
35
     * @param string|null   $type
36
     *
37
     * @return mixed
38
     */
39 View Code Duplication
    public function deserialize($data, string $type, Specification $specification)
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...
40
    {
41
        $array = json_decode($data, true);
42
43
        if (!is_array($array)) {
44
            throw new \UnexpectedValueException("Expected result to be an array");
45
        }
46
47
        return $array;
48
    }
49
}
50