|
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\Place\Autocomplete\Response; |
|
13
|
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Service\Place\Autocomplete\Request\PlaceAutocompleteRequestInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @author GeLo <[email protected]> |
|
18
|
|
|
*/ |
|
19
|
|
View Code Duplication |
class PlaceAutocompleteResponse |
|
|
|
|
|
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var string|null |
|
23
|
|
|
*/ |
|
24
|
|
|
private $status; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var PlaceAutocompleteRequestInterface|null |
|
28
|
|
|
*/ |
|
29
|
|
|
private $request; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var PlaceAutocompletePrediction[] |
|
33
|
|
|
*/ |
|
34
|
|
|
private $predictions = []; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @return bool |
|
38
|
|
|
*/ |
|
39
|
|
|
public function hasStatus() |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->status !== null; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return string|null |
|
46
|
|
|
*/ |
|
47
|
|
|
public function getStatus() |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->status; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param string|null $status |
|
54
|
|
|
*/ |
|
55
|
|
|
public function setStatus($status) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->status = $status; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return bool |
|
62
|
|
|
*/ |
|
63
|
|
|
public function hasRequest() |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->request !== null; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return PlaceAutocompleteRequestInterface|null |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getRequest() |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->request; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param PlaceAutocompleteRequestInterface|null $request |
|
78
|
|
|
*/ |
|
79
|
|
|
public function setRequest(PlaceAutocompleteRequestInterface $request = null) |
|
80
|
|
|
{ |
|
81
|
|
|
$this->request = $request; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @return bool |
|
86
|
|
|
*/ |
|
87
|
|
|
public function hasPredictions() |
|
88
|
|
|
{ |
|
89
|
|
|
return !empty($this->predictions); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return PlaceAutocompletePrediction[] |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getPredictions() |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->predictions; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @param PlaceAutocompletePrediction[] $predictions |
|
102
|
|
|
*/ |
|
103
|
|
|
public function setPredictions(array $predictions) |
|
104
|
|
|
{ |
|
105
|
|
|
$this->predictions = []; |
|
106
|
|
|
$this->addPredictions($predictions); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param PlaceAutocompletePrediction[] $predictions |
|
111
|
|
|
*/ |
|
112
|
|
|
public function addPredictions(array $predictions) |
|
113
|
|
|
{ |
|
114
|
|
|
foreach ($predictions as $prediction) { |
|
115
|
|
|
$this->addPrediction($prediction); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @param PlaceAutocompletePrediction $prediction |
|
121
|
|
|
* |
|
122
|
|
|
* @return bool |
|
123
|
|
|
*/ |
|
124
|
|
|
public function hasPrediction(PlaceAutocompletePrediction $prediction) |
|
125
|
|
|
{ |
|
126
|
|
|
return in_array($prediction, $this->predictions, true); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @param PlaceAutocompletePrediction $prediction |
|
131
|
|
|
*/ |
|
132
|
|
|
public function addPrediction(PlaceAutocompletePrediction $prediction) |
|
133
|
|
|
{ |
|
134
|
|
|
if (!$this->hasPrediction($prediction)) { |
|
135
|
|
|
$this->predictions[] = $prediction; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @param PlaceAutocompletePrediction $prediction |
|
141
|
|
|
*/ |
|
142
|
|
|
public function removePrediction(PlaceAutocompletePrediction $prediction) |
|
143
|
|
|
{ |
|
144
|
|
|
unset($this->predictions[array_search($prediction, $this->predictions, true)]); |
|
145
|
|
|
$this->predictions = array_values($this->predictions); |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|
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.