RawResponse   A
last analyzed

Complexity

Total Complexity 24

Size/Duplication

Total Lines 118
Duplicated Lines 33.9 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 24
c 5
b 1
f 0
lcom 2
cbo 0
dl 40
loc 118
ccs 54
cts 54
cp 1
rs 10

16 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getRaw() 0 4 1
A getValues() 0 4 1
A getArrays() 0 4 1
A getMaps() 0 4 1
A getTuples() 0 4 1
A hasValue() 0 4 1
A getValue() 10 10 3
A hasArray() 0 4 1
A getArray() 10 10 3
A hasMap() 0 4 1
A getMap() 10 10 3
A getMapValue() 0 4 1
A getMapKey() 0 6 1
A hasTuple() 0 4 1
A getTuple() 10 10 3

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 Thunder\SimilarWebApi;
3
4
/**
5
 * @author Tomasz Kowalczyk <[email protected]>
6
 */
7
final class RawResponse
8
    {
9
    private $raw;
10
    private $values;
11
    private $arrays;
12
    private $maps;
13
    private $tuples;
14
15 43
    public function __construct($raw, array $values, array $arrays, array $maps, array $tuples)
16
        {
17 43
        $this->raw = $raw;
18 43
        $this->values = $values;
19 43
        $this->arrays = $arrays;
20 43
        $this->maps = $maps;
21 43
        $this->tuples = $tuples;
22 43
        }
23
24 1
    public function getRaw()
25
        {
26 1
        return $this->raw;
27
        }
28
29 1
    public function getValues()
30
        {
31 1
        return $this->values;
32
        }
33
34 1
    public function getArrays()
35
        {
36 1
        return $this->arrays;
37
        }
38
39 1
    public function getMaps()
40
        {
41 1
        return $this->maps;
42
        }
43
44 1
    public function getTuples()
45
        {
46 1
        return $this->tuples;
47
        }
48
49 23
    public function hasValue($name)
50
        {
51 23
        return array_key_exists($name, $this->values);
52
        }
53
54 23 View Code Duplication
    public function getValue($name)
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...
55
        {
56 23
        if(!$this->hasValue($name))
57 23
            {
58 1
            $mapsKeys = $this->maps ? implode(', ', array_keys($this->values)) : 'empty array';
59 1
            throw new \RuntimeException(sprintf('Value %s not found among %s!', $name, $mapsKeys));
60
            }
61
62 22
        return $this->values[$name];
63
        }
64
65 5
    public function hasArray($name)
66
        {
67 5
        return array_key_exists($name, $this->arrays);
68
        }
69
70 5 View Code Duplication
    public function getArray($name)
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...
71
        {
72 5
        if(!$this->hasArray($name))
73 5
            {
74 1
            $mapsKeys = $this->maps ? implode(', ', array_keys($this->arrays)) : 'empty array';
75 1
            throw new \RuntimeException(sprintf('Array %s not found among %s!', $name, $mapsKeys));
76
            }
77
78 4
        return $this->arrays[$name];
79
        }
80
81 17
    public function hasMap($name)
82
        {
83 17
        return array_key_exists($name, $this->maps);
84
        }
85
86 17 View Code Duplication
    public function getMap($name)
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...
87
        {
88 17
        if(!$this->hasMap($name))
89 17
            {
90 1
            $mapsKeys = $this->maps ? implode(', ', array_keys($this->maps)) : 'empty array';
91 1
            throw new \RuntimeException(sprintf('Map %s not found among %s!', $name, $mapsKeys));
92
            }
93
94 16
        return $this->maps[$name];
95
        }
96
97 1
    public function getMapValue($name, $key)
98
        {
99 1
        return $this->maps[$name][$key];
100
        }
101
102 1
    public function getMapKey($name, $value)
103
        {
104 1
        $flip = array_flip($this->maps[$name]);
105
106 1
        return $flip[$value];
107
        }
108
109 5
    public function hasTuple($name)
110
        {
111 5
        return array_key_exists($name, $this->tuples);
112
        }
113
114 5 View Code Duplication
    public function getTuple($name)
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...
115
        {
116 5
        if(!$this->hasTuple($name))
117 5
            {
118 1
            $tuplesKeys = $this->tuples ? implode(', ', array_keys($this->tuples)) : 'empty array';
119 1
            throw new \RuntimeException(sprintf('Tuple %s not found among %s!', $name, $tuplesKeys));
120
            }
121
122 4
        return $this->tuples[$name];
123
        }
124
    }
125