ObjectToResult   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 66
Duplicated Lines 12.12 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 7
Bugs 0 Features 0
Metric Value
wmc 11
c 7
b 0
f 0
lcom 0
cbo 1
dl 8
loc 66
ccs 0
cts 50
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C transform() 8 62 11

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 ApaiIO\ResponseTransformer;
4
5
class ObjectToResult extends ObjectToArray implements ResponseTransformerInterface {
6
7
    public function transform($response)
8
    {
9
        $data = array();
10
        $response = $this->buildArray( $response );
0 ignored issues
show
Bug introduced by
The method buildArray() does not seem to exist on object<ApaiIO\ResponseTransformer\ObjectToResult>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
11
12
        if( !isset( $response['Items']['Item'] ) )
13
        {
14
            return $data;
15
        }
16
17
        foreach( $response['Items']['Item'] as $item )
18
        {
19
            if( !isset( $item['ItemAttributes']['Title'] ) )
20
            {
21
                continue;
22
            }
23
24
            $row = array();
25
26
            $row['asin'] = $item['ASIN'];
27
            $row['title'] = strip_tags( $item['ItemAttributes']['Title'] );
28
29
            if( isset( $item['LargeImage']['URL'] ) )
30
            {
31
                $row['large_image'] = $item['LargeImage']['URL'];
32
            }
33
34
            if( isset( $item['MediumImage']['URL'] ) )
35
            {
36
                $row['medium_image'] = $item['MediumImage']['URL'];
37
            }
38
39
            if( isset( $item['SmallImage']['URL'] ) )
40
            {
41
                $row['small_image'] = $item['SmallImage']['URL'];
42
            }
43
44 View Code Duplication
            if( isset( $item['ItemAttributes']['ISBN'] ) )
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
45
            {
46
                $row['isbn'] = $item['ItemAttributes']['ISBN'];
47
            }
48
49 View Code Duplication
            if( isset( $item['ItemAttributes']['Edition'] ) )
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
50
            {
51
                $row['edition'] = $item['ItemAttributes']['Edition'];
52
            }
53
54
            if( isset( $item['ItemAttributes']['Author'] ) )
55
            {
56
                $author = $item['ItemAttributes']['Author'];
57
                if( ! is_array( $author ) )
58
                {
59
                    $author = array($author);
60
                }
61
                $row['author'] = $author;
62
            }
63
64
            $data[] = $row;
65
        }
66
67
        return $data;
68
    }
69
70
}
71