Completed
Push — master ( 02e991...6c3ee0 )
by Matthew
15:05 queued 12:47
created

FractalUtility   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 38.89 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 14
loc 36
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createItem() 7 7 1
A createCollection() 7 7 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
namespace Ps2alerts\Api\Utility;
4
5
use League\Fractal\Resource\Item;
6
use League\Fractal\Resource\Collection;
7
use League\Fractal\TransformerAbstract;
8
use Ps2alerts\Api\Contract\FractalAwareInterface;
9
use Ps2alerts\Api\Contract\FractalAwareTrait;
10
11
class FractalUtility implements FractalAwareInterface
12
{
13
    use FractalAwareTrait;
14
15
    /**
16
     * Creates the item array and returns it hence it came.
17
     *
18
     * @param  array               $item        The data to parse
19
     * @param  TransformerAbstract $transformer The transformer to be used
20
     *
21
     * @return array
22
     */
23 View Code Duplication
    public function createItem($item, TransformerAbstract $transformer)
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...
24
    {
25
        $resource = new Item($item, $transformer);
26
        $data = $this->getFractalManager()->createData($resource);
27
28
        return $data->toArray();
29
    }
30
31
    /**
32
     * Creates a collection array and sends it back to hence it came.
33
     *
34
     * @param  array               $collection
35
     * @param  TransformerAbstract $transformer
36
     *
37
     * @return array
38
     */
39 View Code Duplication
    public function createCollection(array $collection, TransformerAbstract $transformer)
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
        $resource = new Collection($collection, $transformer);
42
        $data = $this->getFractalManager()->createData($resource);
43
44
        return $data->toArray();
45
    }
46
}