RawResponse::hasValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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