DataArraySerializer   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 62
Duplicated Lines 25.81 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 1
dl 16
loc 62
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A collection() 8 8 3
A item() 8 8 3
A null() 0 6 1
A meta() 0 8 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
2
3
namespace NavJobs\Transmit\Serializers;
4
5
use League\Fractal\Resource\ResourceInterface;
6
use League\Fractal\Serializer\ArraySerializer as BaseArraySerializer;
7
8
class DataArraySerializer extends BaseArraySerializer
9
{
10
    /**
11
     * Serialize a collection.
12
     *
13
     * @param string $resourceKey
14
     * @param array  $data
15
     *
16
     * @return array
17
     */
18 View Code Duplication
    public function collection($resourceKey, array $data)
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...
19
    {
20
        if ($resourceKey === false) {
21
            return $data;
22
        }
23
24
        return $resourceKey ? [$resourceKey => $data] : ['data' => $data];
25
    }
26
27
    /**
28
     * Serialize an item.
29
     *
30
     * @param string $resourceKey
31
     * @param array  $data
32
     *
33
     * @return array
34
     */
35 View Code Duplication
    public function item($resourceKey, array $data)
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...
36
    {
37
        if ($resourceKey === false) {
38
            return $data;
39
        }
40
41
        return $resourceKey ? [$resourceKey => $data] : ['data' => $data];
42
    }
43
44
    /**
45
     * @return array
46
     */
47
    public function null()
48
    {
49
        return [
50
            null
51
        ];
52
    }
53
54
    /**
55
     * Serialize the meta.
56
     *
57
     * @param array $meta
58
     *
59
     * @return array
60
     */
61
    public function meta(array $meta)
62
    {
63
        if (empty($meta)) {
64
            return [];
65
        }
66
67
        return $meta;
68
    }
69
}
70