1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Ivory Google Map package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Ivory\GoogleMap\Service\Elevation\Response; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author GeLo <[email protected]> |
16
|
|
|
*/ |
17
|
|
View Code Duplication |
class ElevationResponse |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var string|null |
21
|
|
|
*/ |
22
|
|
|
private $status; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var ElevationResult[] |
26
|
|
|
*/ |
27
|
|
|
private $results = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return bool |
31
|
|
|
*/ |
32
|
|
|
public function hasStatus() |
33
|
|
|
{ |
34
|
|
|
return $this->status !== null; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return string|null |
39
|
|
|
*/ |
40
|
|
|
public function getStatus() |
41
|
|
|
{ |
42
|
|
|
return $this->status; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string|null $status |
47
|
|
|
*/ |
48
|
|
|
public function setStatus($status) |
49
|
|
|
{ |
50
|
|
|
$this->status = $status; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return bool |
55
|
|
|
*/ |
56
|
|
|
public function hasResults() |
57
|
|
|
{ |
58
|
|
|
return !empty($this->results); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return ElevationResult[] |
63
|
|
|
*/ |
64
|
|
|
public function getResults() |
65
|
|
|
{ |
66
|
|
|
return $this->results; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param ElevationResult[] $results |
71
|
|
|
*/ |
72
|
|
|
public function setResults(array $results) |
73
|
|
|
{ |
74
|
|
|
$this->results = []; |
75
|
|
|
$this->addResults($results); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param ElevationResult[] $results |
80
|
|
|
*/ |
81
|
|
|
public function addResults(array $results) |
82
|
|
|
{ |
83
|
|
|
foreach ($results as $result) { |
84
|
|
|
$this->addResult($result); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param ElevationResult $result |
90
|
|
|
* |
91
|
|
|
* @return bool |
92
|
|
|
*/ |
93
|
|
|
public function hasResult(ElevationResult $result) |
94
|
|
|
{ |
95
|
|
|
return in_array($result, $this->results, true); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param ElevationResult $result |
100
|
|
|
*/ |
101
|
|
|
public function addResult(ElevationResult $result) |
102
|
|
|
{ |
103
|
|
|
if (!$this->hasResult($result)) { |
104
|
|
|
$this->results[] = $result; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param ElevationResult $result |
110
|
|
|
*/ |
111
|
|
|
public function removeResult(ElevationResult $result) |
112
|
|
|
{ |
113
|
|
|
unset($this->results[array_search($result, $this->results, true)]); |
114
|
|
|
$this->results = array_values($this->results); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
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.