ListGroupResponseDataTransformer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A transform() 14 14 3
A reverseTransform() 4 4 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
namespace OmnideskBundle\DataTransformer\Response\Group;
3
4
use OmnideskBundle\DataTransformer\DataTransformerInterface;
5
use OmnideskBundle\DataTransformer\Model\GroupDataTransformer;
6
use OmnideskBundle\Response\Group\GetGroupResponse;
7
8
/**
9
 * Class ListGroupResponseDataTransformer
10
 * @package OmnideskBundle\DataTransformer\Response\Group
11
 */
12 View Code Duplication
class ListGroupResponseDataTransformer implements DataTransformerInterface
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...
13
{
14
    /**
15
     * @var GroupDataTransformer
16
     */
17
    protected $groupDataTransformer;
18
19
    /**
20
     * ListGroupResponseDataTransformer constructor.
21
     * @param GroupDataTransformer $groupDataTransformer
22
     */
23
    public function __construct(GroupDataTransformer $groupDataTransformer)
24
    {
25
        $this->groupDataTransformer = $groupDataTransformer;
26
    }
27
28
    /**
29
     * @param array $value
30
     * @return GetGroupResponse
31
     */
32
    public function transform($value)
33
    {
34
        $response = new GetGroupResponse();
35
36
        foreach ($value as $item) {
37
            if (isset($item['group'])) {
38
                $response->addGroup($this->groupDataTransformer->transform($item['group']));
39
            }
40
        }
41
42
        $response->setTotalCount($value['total_count'] ?? 0);
43
44
        return $response;
45
    }
46
47
    /**
48
     * @param GetGroupResponse $value
49
     * @return array
50
     */
51
    public function reverseTransform($value)
52
    {
53
        throw new \LogicException('Method not implemented.');
54
    }
55
}
56