Test Failed
Push — master ( 5d6517...76f70d )
by Roberto
03:19 queued 10s
created
src/Api/Places.php 2 patches
Indentation   +195 added lines, -195 removed lines patch added patch discarded remove patch
@@ -32,206 +32,206 @@
 block discarded – undo
32 32
 class Places extends Api
33 33
 {
34 34
 
35
-	/**
36
-	 * @var string
37
-	 */
38
-	const SERVICE_ENDPOINT = 'place';
39
-
40
-	/**
41
-	 * @var string
42
-	 */
43
-	protected $result_collection = PlaceResultsCollection::class;
44
-
45
-	/**
46
-	 * @param string     $query
47
-	 * @param array|null $params
48
-	 * @param array|null $fields
49
-	 *
50
-	 * @return GoogleMapsResultsCollection
51
-	 * @see https://developers.google.com/places/web-service/search#FindPlaceRequests
52
-	 */
53
-	public function findPlaceByText(
54
-		string $query,
55
-		?array $params = [],
56
-		?array $fields = []
57
-	): GoogleMapsResultsCollection {
58
-
59
-		$params = array_merge($params, [
60
-			GoogleMapsRequestFields::INPUT  => $query,
61
-			GoogleMapsRequestFields::FIELDS => implode(',', $fields)
62
-		]);
63
-
64
-		return $this->findPlace($params);
65
-
66
-	}
67
-
68
-	/**
69
-	 * Find Places requests
70
-	 *
71
-	 * @param array $params
72
-	 *        GoogleMapsRequestFields::INPUT required
73
-	 *
74
-	 * @see     https://developers.google.com/places/web-service/search#FindPlaceRequests
75
-	 * @return GoogleMapsResultsCollection
76
-	 * @throws InvalidArgumentException
77
-	 * @since   0.5.0
78
-	 */
79
-	public function findPlace(array $params): GoogleMapsResultsCollection
80
-	{
81
-
82
-		// see \Biscolab\GoogleMaps\Values\PlaceInputTypeValues
83
-		if (empty($params[GoogleMapsRequestFields::INPUTTYPE])) {
84
-			$params[GoogleMapsRequestFields::INPUTTYPE] = PlaceInputTypeValues::TEXTQUERY;
85
-		}
86
-
87
-		if (empty($params[GoogleMapsRequestFields::INPUT])) {
88
-			throw new InvalidArgumentException(GoogleMapsRequestFields::INPUT . " field is required");
89
-		}
90
-
91
-		return $this->makeApiCall($params, PlaceServicesEndpoints::FINDPLACEFROMTEXT);
92
-	}
93
-
94
-	/**
95
-	 * @param array  $params
96
-	 * @param string $endpoint
97
-	 *
98
-	 * @return GoogleMapsResultsCollection
99
-	 * @since   0.5.0
100
-	 */
101
-	public function makeApiCall(array $params, string $endpoint): GoogleMapsResultsCollection
102
-	{
103
-
104
-		return $this->callApi($params, $endpoint);
105
-	}
106
-
107
-	/**
108
-	 * @param string     $number
109
-	 * @param array|null $params
110
-	 * @param array|null $fields
111
-	 *
112
-	 * @return GoogleMapsResultsCollection
113
-	 */
114
-	public function findPlaceByPhoneNumber(
115
-		string $number,
116
-		?array $params = [],
117
-		?array $fields = []
118
-	): GoogleMapsResultsCollection {
119
-
120
-		$params = array_merge($params, [
121
-			GoogleMapsRequestFields::INPUT     => $number,
122
-			GoogleMapsRequestFields::INPUTTYPE => PlaceInputTypeValues::PHONENUMBER,
123
-			GoogleMapsRequestFields::FIELDS    => implode(',', $fields)
124
-		]);
125
-
126
-		return $this->findPlace($params);
127
-
128
-	}
129
-
130
-	/**
131
-	 * @param Location   $location
132
-	 * @param int        $radius
133
-	 * @param array|null $params
134
-	 *
135
-	 * @return GoogleMapsResultsCollection
136
-	 */
137
-	public function findNearbyPlaceByRadius(Location $location, int $radius, ?array $params = []): GoogleMapsResultsCollection
138
-	{
139
-
140
-		$params = array_merge($params, [
141
-			GoogleMapsRequestFields::LOCATION => $location,
142
-			GoogleMapsRequestFields::RADIUS => $radius
143
-		]);
144
-
145
-		return $this->findNearbyPlace($params);
146
-	}
147
-
148
-	/**
149
-	 * @param Location $location
150
-	 * @param array    $params
151
-	 *
152
-	 * @return GoogleMapsResultsCollection
153
-	 */
154
-	public function findNearbyPlaceByDistance(Location $location, array $params): GoogleMapsResultsCollection
155
-	{
156
-
157
-		$params = array_merge($params, [
158
-			GoogleMapsRequestFields::LOCATION => $location,
159
-			GoogleMapsRequestFields::RANKBY => RankByValues::DISTANCE
160
-		]);
161
-
162
-		return $this->findNearbyPlace($params);
163
-	}
164
-
165
-	/**
166
-	 * Nearby Search requests
167
-	 *
168
-	 * @param array $params
169
-	 *
170
-	 * @return GoogleMapsResultsCollection
171
-	 *
172
-	 * @throws InvalidArgumentException
173
-	 * @see     https://developers.google.com/places/web-service/search#PlaceSearchRequests
174
-	 * @since   0.5.0
175
-	 */
176
-	public function findNearbyPlace(array $params): GoogleMapsResultsCollection
177
-	{
178
-
179
-		if (!empty($params[GoogleMapsRequestFields::LOCATION])) {//-33.8670522,151.1957362
180
-			$location = $params[GoogleMapsRequestFields::LOCATION];
181
-			if (!$location instanceof Location) {
182
-				throw new InvalidArgumentException(GoogleMapsRequestFields::LOCATION . ' field must be instance of ' . Location::class . ' class');
183
-			}
184
-			$params[GoogleMapsRequestFields::LOCATION] = (string)$params[GoogleMapsRequestFields::LOCATION];
185
-		} else {
186
-			throw new InvalidArgumentException(GoogleMapsResultFields::LOCATION . ' field is required');
187
-		}
188
-
189
-		if (!empty($params[GoogleMapsRequestFields::RANKBY]) &&
190
-			$params[GoogleMapsRequestFields::RANKBY] === RankByValues::DISTANCE
191
-		) {
192
-			if (empty($params[GoogleMapsRequestFields::KEYWORD]) &&
193
-				empty($params[GoogleMapsRequestFields::NAME]) &&
194
-				empty($params[GoogleMapsRequestFields::TYPE])) {
35
+    /**
36
+     * @var string
37
+     */
38
+    const SERVICE_ENDPOINT = 'place';
39
+
40
+    /**
41
+     * @var string
42
+     */
43
+    protected $result_collection = PlaceResultsCollection::class;
44
+
45
+    /**
46
+     * @param string     $query
47
+     * @param array|null $params
48
+     * @param array|null $fields
49
+     *
50
+     * @return GoogleMapsResultsCollection
51
+     * @see https://developers.google.com/places/web-service/search#FindPlaceRequests
52
+     */
53
+    public function findPlaceByText(
54
+        string $query,
55
+        ?array $params = [],
56
+        ?array $fields = []
57
+    ): GoogleMapsResultsCollection {
58
+
59
+        $params = array_merge($params, [
60
+            GoogleMapsRequestFields::INPUT  => $query,
61
+            GoogleMapsRequestFields::FIELDS => implode(',', $fields)
62
+        ]);
63
+
64
+        return $this->findPlace($params);
65
+
66
+    }
67
+
68
+    /**
69
+     * Find Places requests
70
+     *
71
+     * @param array $params
72
+     *        GoogleMapsRequestFields::INPUT required
73
+     *
74
+     * @see     https://developers.google.com/places/web-service/search#FindPlaceRequests
75
+     * @return GoogleMapsResultsCollection
76
+     * @throws InvalidArgumentException
77
+     * @since   0.5.0
78
+     */
79
+    public function findPlace(array $params): GoogleMapsResultsCollection
80
+    {
81
+
82
+        // see \Biscolab\GoogleMaps\Values\PlaceInputTypeValues
83
+        if (empty($params[GoogleMapsRequestFields::INPUTTYPE])) {
84
+            $params[GoogleMapsRequestFields::INPUTTYPE] = PlaceInputTypeValues::TEXTQUERY;
85
+        }
86
+
87
+        if (empty($params[GoogleMapsRequestFields::INPUT])) {
88
+            throw new InvalidArgumentException(GoogleMapsRequestFields::INPUT . " field is required");
89
+        }
90
+
91
+        return $this->makeApiCall($params, PlaceServicesEndpoints::FINDPLACEFROMTEXT);
92
+    }
93
+
94
+    /**
95
+     * @param array  $params
96
+     * @param string $endpoint
97
+     *
98
+     * @return GoogleMapsResultsCollection
99
+     * @since   0.5.0
100
+     */
101
+    public function makeApiCall(array $params, string $endpoint): GoogleMapsResultsCollection
102
+    {
103
+
104
+        return $this->callApi($params, $endpoint);
105
+    }
106
+
107
+    /**
108
+     * @param string     $number
109
+     * @param array|null $params
110
+     * @param array|null $fields
111
+     *
112
+     * @return GoogleMapsResultsCollection
113
+     */
114
+    public function findPlaceByPhoneNumber(
115
+        string $number,
116
+        ?array $params = [],
117
+        ?array $fields = []
118
+    ): GoogleMapsResultsCollection {
119
+
120
+        $params = array_merge($params, [
121
+            GoogleMapsRequestFields::INPUT     => $number,
122
+            GoogleMapsRequestFields::INPUTTYPE => PlaceInputTypeValues::PHONENUMBER,
123
+            GoogleMapsRequestFields::FIELDS    => implode(',', $fields)
124
+        ]);
125
+
126
+        return $this->findPlace($params);
127
+
128
+    }
129
+
130
+    /**
131
+     * @param Location   $location
132
+     * @param int        $radius
133
+     * @param array|null $params
134
+     *
135
+     * @return GoogleMapsResultsCollection
136
+     */
137
+    public function findNearbyPlaceByRadius(Location $location, int $radius, ?array $params = []): GoogleMapsResultsCollection
138
+    {
139
+
140
+        $params = array_merge($params, [
141
+            GoogleMapsRequestFields::LOCATION => $location,
142
+            GoogleMapsRequestFields::RADIUS => $radius
143
+        ]);
144
+
145
+        return $this->findNearbyPlace($params);
146
+    }
147
+
148
+    /**
149
+     * @param Location $location
150
+     * @param array    $params
151
+     *
152
+     * @return GoogleMapsResultsCollection
153
+     */
154
+    public function findNearbyPlaceByDistance(Location $location, array $params): GoogleMapsResultsCollection
155
+    {
156
+
157
+        $params = array_merge($params, [
158
+            GoogleMapsRequestFields::LOCATION => $location,
159
+            GoogleMapsRequestFields::RANKBY => RankByValues::DISTANCE
160
+        ]);
161
+
162
+        return $this->findNearbyPlace($params);
163
+    }
164
+
165
+    /**
166
+     * Nearby Search requests
167
+     *
168
+     * @param array $params
169
+     *
170
+     * @return GoogleMapsResultsCollection
171
+     *
172
+     * @throws InvalidArgumentException
173
+     * @see     https://developers.google.com/places/web-service/search#PlaceSearchRequests
174
+     * @since   0.5.0
175
+     */
176
+    public function findNearbyPlace(array $params): GoogleMapsResultsCollection
177
+    {
178
+
179
+        if (!empty($params[GoogleMapsRequestFields::LOCATION])) {//-33.8670522,151.1957362
180
+            $location = $params[GoogleMapsRequestFields::LOCATION];
181
+            if (!$location instanceof Location) {
182
+                throw new InvalidArgumentException(GoogleMapsRequestFields::LOCATION . ' field must be instance of ' . Location::class . ' class');
183
+            }
184
+            $params[GoogleMapsRequestFields::LOCATION] = (string)$params[GoogleMapsRequestFields::LOCATION];
185
+        } else {
186
+            throw new InvalidArgumentException(GoogleMapsResultFields::LOCATION . ' field is required');
187
+        }
188
+
189
+        if (!empty($params[GoogleMapsRequestFields::RANKBY]) &&
190
+            $params[GoogleMapsRequestFields::RANKBY] === RankByValues::DISTANCE
191
+        ) {
192
+            if (empty($params[GoogleMapsRequestFields::KEYWORD]) &&
193
+                empty($params[GoogleMapsRequestFields::NAME]) &&
194
+                empty($params[GoogleMapsRequestFields::TYPE])) {
195 195
 //				If rankby=distance (described under Optional parameters below) is specified,
196 196
 // 				then one or more of keyword, name, or type is required.
197
-				throw new InvalidArgumentException('If ' . GoogleMapsRequestFields::RANKBY . ' is set as "' . RankByValues::DISTANCE . '" one or more of ' . GoogleMapsRequestFields::KEYWORD . ', ' . GoogleMapsRequestFields::NAME . ', ' . GoogleMapsRequestFields::TYPE . ' fields are required');
198
-			}
199
-			if (!empty($params[GoogleMapsRequestFields::RADIUS])) {
197
+                throw new InvalidArgumentException('If ' . GoogleMapsRequestFields::RANKBY . ' is set as "' . RankByValues::DISTANCE . '" one or more of ' . GoogleMapsRequestFields::KEYWORD . ', ' . GoogleMapsRequestFields::NAME . ', ' . GoogleMapsRequestFields::TYPE . ' fields are required');
198
+            }
199
+            if (!empty($params[GoogleMapsRequestFields::RADIUS])) {
200 200
 // 				Note that radius must not be included if rankby=distance (described under Optional parameters below) is specified.
201
-				throw new InvalidArgumentException(GoogleMapsRequestFields::RADIUS . ' must not be included if ' . GoogleMapsRequestFields::RANKBY . ' = ' . RankByValues::DISTANCE);
202
-			}
203
-		} elseif (empty($params[GoogleMapsRequestFields::RADIUS])) {
201
+                throw new InvalidArgumentException(GoogleMapsRequestFields::RADIUS . ' must not be included if ' . GoogleMapsRequestFields::RANKBY . ' = ' . RankByValues::DISTANCE);
202
+            }
203
+        } elseif (empty($params[GoogleMapsRequestFields::RADIUS])) {
204 204
 //			radius — Defines the distance (in meters) within which to return place results.
205
-			throw new InvalidArgumentException(GoogleMapsRequestFields::RADIUS . ' field is required');
206
-		}
205
+            throw new InvalidArgumentException(GoogleMapsRequestFields::RADIUS . ' field is required');
206
+        }
207 207
 
208
-		if (!empty($params[GoogleMapsRequestFields::RADIUS]) && floatval($params[GoogleMapsRequestFields::RADIUS]) > Util::MAX_PLACE_RADIUS_VALUE) {
208
+        if (!empty($params[GoogleMapsRequestFields::RADIUS]) && floatval($params[GoogleMapsRequestFields::RADIUS]) > Util::MAX_PLACE_RADIUS_VALUE) {
209 209
 // 			The maximum allowed radius is 50 000 meters.
210
-			throw new InvalidArgumentException(GoogleMapsRequestFields::RADIUS . ' must be lower than ' . Util::MAX_PLACE_RADIUS_VALUE);
211
-		}
212
-
213
-		return $this->makeApiCall($params, PlaceServicesEndpoints::NEARBYSEARCH);
214
-	}
215
-
216
-	/**
217
-	 * Nearby Search requests
218
-	 *
219
-	 * @param string     $query
220
-	 * @param array|null $params
221
-	 *
222
-	 * @see     https://developers.google.com/places/web-service/search#TextSearchRequests
223
-	 * @return GoogleMapsResultsCollection
224
-	 * @throws InvalidArgumentException
225
-	 * @since   0.5.0
226
-	 */
227
-	public function textSearch(string $query, ?array $params = []): GoogleMapsResultsCollection
228
-	{
229
-
230
-		$params = array_merge($params, [
231
-			GoogleMapsRequestFields::QUERY => $query
232
-		]);
233
-
234
-		return $this->makeApiCall($params, PlaceServicesEndpoints::TEXTSEARCH);
235
-	}
210
+            throw new InvalidArgumentException(GoogleMapsRequestFields::RADIUS . ' must be lower than ' . Util::MAX_PLACE_RADIUS_VALUE);
211
+        }
212
+
213
+        return $this->makeApiCall($params, PlaceServicesEndpoints::NEARBYSEARCH);
214
+    }
215
+
216
+    /**
217
+     * Nearby Search requests
218
+     *
219
+     * @param string     $query
220
+     * @param array|null $params
221
+     *
222
+     * @see     https://developers.google.com/places/web-service/search#TextSearchRequests
223
+     * @return GoogleMapsResultsCollection
224
+     * @throws InvalidArgumentException
225
+     * @since   0.5.0
226
+     */
227
+    public function textSearch(string $query, ?array $params = []): GoogleMapsResultsCollection
228
+    {
229
+
230
+        $params = array_merge($params, [
231
+            GoogleMapsRequestFields::QUERY => $query
232
+        ]);
233
+
234
+        return $this->makeApiCall($params, PlaceServicesEndpoints::TEXTSEARCH);
235
+    }
236 236
 
237 237
 }
238 238
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 		}
86 86
 
87 87
 		if (empty($params[GoogleMapsRequestFields::INPUT])) {
88
-			throw new InvalidArgumentException(GoogleMapsRequestFields::INPUT . " field is required");
88
+			throw new InvalidArgumentException(GoogleMapsRequestFields::INPUT." field is required");
89 89
 		}
90 90
 
91 91
 		return $this->makeApiCall($params, PlaceServicesEndpoints::FINDPLACEFROMTEXT);
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
 		if (!empty($params[GoogleMapsRequestFields::LOCATION])) {//-33.8670522,151.1957362
180 180
 			$location = $params[GoogleMapsRequestFields::LOCATION];
181 181
 			if (!$location instanceof Location) {
182
-				throw new InvalidArgumentException(GoogleMapsRequestFields::LOCATION . ' field must be instance of ' . Location::class . ' class');
182
+				throw new InvalidArgumentException(GoogleMapsRequestFields::LOCATION.' field must be instance of '.Location::class.' class');
183 183
 			}
184
-			$params[GoogleMapsRequestFields::LOCATION] = (string)$params[GoogleMapsRequestFields::LOCATION];
184
+			$params[GoogleMapsRequestFields::LOCATION] = (string) $params[GoogleMapsRequestFields::LOCATION];
185 185
 		} else {
186
-			throw new InvalidArgumentException(GoogleMapsResultFields::LOCATION . ' field is required');
186
+			throw new InvalidArgumentException(GoogleMapsResultFields::LOCATION.' field is required');
187 187
 		}
188 188
 
189 189
 		if (!empty($params[GoogleMapsRequestFields::RANKBY]) &&
@@ -194,20 +194,20 @@  discard block
 block discarded – undo
194 194
 				empty($params[GoogleMapsRequestFields::TYPE])) {
195 195
 //				If rankby=distance (described under Optional parameters below) is specified,
196 196
 // 				then one or more of keyword, name, or type is required.
197
-				throw new InvalidArgumentException('If ' . GoogleMapsRequestFields::RANKBY . ' is set as "' . RankByValues::DISTANCE . '" one or more of ' . GoogleMapsRequestFields::KEYWORD . ', ' . GoogleMapsRequestFields::NAME . ', ' . GoogleMapsRequestFields::TYPE . ' fields are required');
197
+				throw new InvalidArgumentException('If '.GoogleMapsRequestFields::RANKBY.' is set as "'.RankByValues::DISTANCE.'" one or more of '.GoogleMapsRequestFields::KEYWORD.', '.GoogleMapsRequestFields::NAME.', '.GoogleMapsRequestFields::TYPE.' fields are required');
198 198
 			}
199 199
 			if (!empty($params[GoogleMapsRequestFields::RADIUS])) {
200 200
 // 				Note that radius must not be included if rankby=distance (described under Optional parameters below) is specified.
201
-				throw new InvalidArgumentException(GoogleMapsRequestFields::RADIUS . ' must not be included if ' . GoogleMapsRequestFields::RANKBY . ' = ' . RankByValues::DISTANCE);
201
+				throw new InvalidArgumentException(GoogleMapsRequestFields::RADIUS.' must not be included if '.GoogleMapsRequestFields::RANKBY.' = '.RankByValues::DISTANCE);
202 202
 			}
203 203
 		} elseif (empty($params[GoogleMapsRequestFields::RADIUS])) {
204 204
 //			radius — Defines the distance (in meters) within which to return place results.
205
-			throw new InvalidArgumentException(GoogleMapsRequestFields::RADIUS . ' field is required');
205
+			throw new InvalidArgumentException(GoogleMapsRequestFields::RADIUS.' field is required');
206 206
 		}
207 207
 
208 208
 		if (!empty($params[GoogleMapsRequestFields::RADIUS]) && floatval($params[GoogleMapsRequestFields::RADIUS]) > Util::MAX_PLACE_RADIUS_VALUE) {
209 209
 // 			The maximum allowed radius is 50 000 meters.
210
-			throw new InvalidArgumentException(GoogleMapsRequestFields::RADIUS . ' must be lower than ' . Util::MAX_PLACE_RADIUS_VALUE);
210
+			throw new InvalidArgumentException(GoogleMapsRequestFields::RADIUS.' must be lower than '.Util::MAX_PLACE_RADIUS_VALUE);
211 211
 		}
212 212
 
213 213
 		return $this->makeApiCall($params, PlaceServicesEndpoints::NEARBYSEARCH);
Please login to merge, or discard this patch.
src/Api/Geocoding.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -25,53 +25,53 @@
 block discarded – undo
25 25
 class Geocoding extends Api
26 26
 {
27 27
 
28
-	/**
29
-	 * @var string
30
-	 */
31
-	const SERVICE_ENDPOINT = 'geocode';
28
+    /**
29
+     * @var string
30
+     */
31
+    const SERVICE_ENDPOINT = 'geocode';
32 32
 
33
-	/**
34
-	 * @var string
35
-	 */
36
-	protected $result_collection = GeocodingResultsCollection::class;
33
+    /**
34
+     * @var string
35
+     */
36
+    protected $result_collection = GeocodingResultsCollection::class;
37 37
 
38
-	/**
39
-	 * @param string $literal_address
40
-	 *
41
-	 * @return GoogleMapsResultsCollection
42
-	 */
43
-	public function getByAddress(string $literal_address): GoogleMapsResultsCollection
44
-	{
38
+    /**
39
+     * @param string $literal_address
40
+     *
41
+     * @return GoogleMapsResultsCollection
42
+     */
43
+    public function getByAddress(string $literal_address): GoogleMapsResultsCollection
44
+    {
45 45
 
46
-		return $this->callApi([
47
-			GoogleMapsRequestFields::ADDRESS => $literal_address
48
-		]);
49
-	}
46
+        return $this->callApi([
47
+            GoogleMapsRequestFields::ADDRESS => $literal_address
48
+        ]);
49
+    }
50 50
 
51
-	/**
52
-	 * @param LatLng $latlng
53
-	 *
54
-	 * @return GoogleMapsResultsCollection
55
-	 */
56
-	public function getReverse(LatLng $latlng): GoogleMapsResultsCollection
57
-	{
51
+    /**
52
+     * @param LatLng $latlng
53
+     *
54
+     * @return GoogleMapsResultsCollection
55
+     */
56
+    public function getReverse(LatLng $latlng): GoogleMapsResultsCollection
57
+    {
58 58
 
59
-		return $this->callApi([
60
-			GoogleMapsRequestFields::LATLNG => $latlng
61
-		]);
62
-	}
59
+        return $this->callApi([
60
+            GoogleMapsRequestFields::LATLNG => $latlng
61
+        ]);
62
+    }
63 63
 
64
-	/**
65
-	 * @param string $place_id
66
-	 *
67
-	 * @return GoogleMapsResultsCollection
68
-	 */
69
-	public function getByPlaceId(string $place_id): GoogleMapsResultsCollection
70
-	{
64
+    /**
65
+     * @param string $place_id
66
+     *
67
+     * @return GoogleMapsResultsCollection
68
+     */
69
+    public function getByPlaceId(string $place_id): GoogleMapsResultsCollection
70
+    {
71 71
 
72
-		return $this->callApi([
73
-			GoogleMapsRequestFields::PLACE_ID => $place_id
74
-		]);
75
-	}
72
+        return $this->callApi([
73
+            GoogleMapsRequestFields::PLACE_ID => $place_id
74
+        ]);
75
+    }
76 76
 
77 77
 }
78 78
\ No newline at end of file
Please login to merge, or discard this patch.
src/Api/Elevation.php 2 patches
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -28,92 +28,92 @@
 block discarded – undo
28 28
 class Elevation extends Api
29 29
 {
30 30
 
31
-	/**
32
-	 * @var string
33
-	 */
34
-	const SERVICE_ENDPOINT = 'elevation';
35
-
36
-	/**
37
-	 * @var string
38
-	 */
39
-	protected $result_collection = ElevationResultsCollection::class;
40
-
41
-	/**
42
-	 * Positional Requests
43
-	 *
44
-	 * @param LatLng|string|array $locations
45
-	 * This parameter takes either a single location or multiple locations passed as an array or as an encoded polyline
46
-	 *
47
-	 * @return GoogleMapsResultsCollection
48
-	 *
49
-	 * @since 0.3.0
50
-	 */
51
-	public function getByLocations($locations): GoogleMapsResultsCollection
52
-	{
53
-
54
-		$locations = $this->parseLocations($locations);
55
-
56
-		return $this->callApi([
57
-			GoogleMapsRequestFields::LOCATIONS => $locations
58
-		]);
59
-	}
60
-
61
-	/**
62
-	 * @param array|string $locations
63
-	 *
64
-	 * @return string
65
-	 *
66
-	 * @since   0.3.0
67
-	 */
68
-	public function parseLocations($locations): string
69
-	{
70
-
71
-		if ($locations instanceof Path) {
72
-			$locations = $locations->toArray();
73
-		}
74
-
75
-		if (is_array($locations)) {
76
-			$locations = implode('|', array_map(function ($item) {
77
-
78
-				return (string)$item;
79
-			}, $locations));
80
-		}
81
-
82
-		return (string)$locations;
83
-	}
84
-
85
-	/**
86
-	 * Sampled Path Requests
87
-	 *
88
-	 * @param array|string $path
89
-	 * This parameter takes either a multiple locations passed as an array or as an encoded polyline
90
-	 *
91
-	 * @param int          $samples
92
-	 * This will be the number of results as well
93
-	 *
94
-	 * @throws InvalidArgumentException
95
-	 * @return GoogleMapsResultsCollection
96
-	 *
97
-	 * @since 0.4.0
98
-	 */
99
-	public function getBySampledPath($path, int $samples): GoogleMapsResultsCollection
100
-	{
101
-
102
-		if ((is_array($path) && count($path) < 2) ||
103
-			$path instanceof Path && $path->count() < 2) {
104
-			throw new InvalidArgumentException('The number of items provided in the path must be greater than 1 (One)');
105
-		}
106
-
107
-		if ($samples <= 0) {
108
-			throw new InvalidArgumentException('The number of samples must be greater than 0 (Zero)');
109
-		}
110
-
111
-		$path = $this->parseLocations($path);
112
-
113
-		return $this->callApi([
114
-			GoogleMapsRequestFields::PATH    => $path,
115
-			GoogleMapsRequestFields::SAMPLES => $samples,
116
-		]);
117
-	}
31
+    /**
32
+     * @var string
33
+     */
34
+    const SERVICE_ENDPOINT = 'elevation';
35
+
36
+    /**
37
+     * @var string
38
+     */
39
+    protected $result_collection = ElevationResultsCollection::class;
40
+
41
+    /**
42
+     * Positional Requests
43
+     *
44
+     * @param LatLng|string|array $locations
45
+     * This parameter takes either a single location or multiple locations passed as an array or as an encoded polyline
46
+     *
47
+     * @return GoogleMapsResultsCollection
48
+     *
49
+     * @since 0.3.0
50
+     */
51
+    public function getByLocations($locations): GoogleMapsResultsCollection
52
+    {
53
+
54
+        $locations = $this->parseLocations($locations);
55
+
56
+        return $this->callApi([
57
+            GoogleMapsRequestFields::LOCATIONS => $locations
58
+        ]);
59
+    }
60
+
61
+    /**
62
+     * @param array|string $locations
63
+     *
64
+     * @return string
65
+     *
66
+     * @since   0.3.0
67
+     */
68
+    public function parseLocations($locations): string
69
+    {
70
+
71
+        if ($locations instanceof Path) {
72
+            $locations = $locations->toArray();
73
+        }
74
+
75
+        if (is_array($locations)) {
76
+            $locations = implode('|', array_map(function ($item) {
77
+
78
+                return (string)$item;
79
+            }, $locations));
80
+        }
81
+
82
+        return (string)$locations;
83
+    }
84
+
85
+    /**
86
+     * Sampled Path Requests
87
+     *
88
+     * @param array|string $path
89
+     * This parameter takes either a multiple locations passed as an array or as an encoded polyline
90
+     *
91
+     * @param int          $samples
92
+     * This will be the number of results as well
93
+     *
94
+     * @throws InvalidArgumentException
95
+     * @return GoogleMapsResultsCollection
96
+     *
97
+     * @since 0.4.0
98
+     */
99
+    public function getBySampledPath($path, int $samples): GoogleMapsResultsCollection
100
+    {
101
+
102
+        if ((is_array($path) && count($path) < 2) ||
103
+            $path instanceof Path && $path->count() < 2) {
104
+            throw new InvalidArgumentException('The number of items provided in the path must be greater than 1 (One)');
105
+        }
106
+
107
+        if ($samples <= 0) {
108
+            throw new InvalidArgumentException('The number of samples must be greater than 0 (Zero)');
109
+        }
110
+
111
+        $path = $this->parseLocations($path);
112
+
113
+        return $this->callApi([
114
+            GoogleMapsRequestFields::PATH    => $path,
115
+            GoogleMapsRequestFields::SAMPLES => $samples,
116
+        ]);
117
+    }
118 118
 
119 119
 }
120 120
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -73,13 +73,13 @@
 block discarded – undo
73 73
 		}
74 74
 
75 75
 		if (is_array($locations)) {
76
-			$locations = implode('|', array_map(function ($item) {
76
+			$locations = implode('|', array_map(function($item) {
77 77
 
78
-				return (string)$item;
78
+				return (string) $item;
79 79
 			}, $locations));
80 80
 		}
81 81
 
82
-		return (string)$locations;
82
+		return (string) $locations;
83 83
 	}
84 84
 
85 85
 	/**
Please login to merge, or discard this patch.
src/GoogleMapsApi.php 2 patches
Indentation   +274 added lines, -274 removed lines patch added patch discarded remove patch
@@ -25,279 +25,279 @@
 block discarded – undo
25 25
 class GoogleMapsApi
26 26
 {
27 27
 
28
-	/**
29
-	 * @var GoogleMapsApi
30
-	 */
31
-	protected static $instance = null;
32
-
33
-	/**
34
-	 * @var GoogleMapsRequest
35
-	 */
36
-	protected $request = null;
37
-
38
-	/**
39
-	 * Google Maps Geocode Service API url
40
-	 * @var string
41
-	 */
42
-	private $api_url = "https://maps.googleapis.com/maps/api/";
43
-
44
-	/**
45
-	 * your own Google Maps API key
46
-	 * @var string
47
-	 * @see https://developers.google.com/maps/documentation/javascript/get-api-key
48
-	 */
49
-	private $key = '';
50
-
51
-	/**
52
-	 * Google Maps API sensor
53
-	 * @var string - true|false
54
-	 */
55
-	private $sensor = 'false';
56
-
57
-	/**
58
-	 * Google Maps API service name
59
-	 * @var string
60
-	 */
61
-	private $service_endpoint = '';
62
-
63
-	/**
64
-	 * @var string
65
-	 */
66
-	private $response = null;
67
-
68
-	/**
69
-	 * @var GoogleMapsClient
70
-	 */
71
-	private $client = null;
72
-
73
-	/**
74
-	 * @var string
75
-	 */
76
-	private $type = null;
77
-
78
-	/**
79
-	 * GoogleMapsApi constructor.
80
-	 *
81
-	 * @param array $config
82
-	 */
83
-	public function __construct(array $config = [])
84
-	{
85
-
86
-		// Set "API key"
87
-		$key = (empty($config[GoogleMapsApiConfigFields::KEY])) ? '' : $config[GoogleMapsApiConfigFields::KEY];
88
-		$this->setKey($key);
89
-
90
-		// Set "sensor"
91
-		$sensor = (empty($config[GoogleMapsApiConfigFields::SENSOR])) ? SensorValues::FALSE : $config[GoogleMapsApiConfigFields::SENSOR];
92
-		$this->setSensor($sensor);
93
-
94
-		// Set the endpoint
95
-		$service_endpoint = (empty($config[GoogleMapsApiConfigFields::SERVICE_ENDPOINT])) ? '' : $config[GoogleMapsApiConfigFields::SERVICE_ENDPOINT];
96
-		$this->setServiceEndpoint($service_endpoint);
97
-
98
-		// Set Client
99
-		$this->setClient();
100
-	}
101
-
102
-	/**
103
-	 * @return string
104
-	 */
105
-	public function getApiUrl(): string
106
-	{
107
-
108
-		return $this->api_url;
109
-	}
110
-
111
-	/**
112
-	 * Perform the Google Maps API call
113
-	 *
114
-	 * @param GoogleMapsRequest $request
115
-	 *
116
-	 * @return Http\GoogleMapsResponse|string
117
-	 */
118
-	public function get(GoogleMapsRequest $request)
119
-	{
120
-
121
-		$this->setRequest($request);
122
-
123
-		$url = $this->getUrl();
124
-
125
-		$query = $this->getQuery();
126
-
127
-		$this->response = $this->getClient()->get($url, $query);
128
-
129
-		return $this->response;
130
-	}
131
-
132
-	/**
133
-	 * @return string
134
-	 * @throws RequestException
135
-	 */
136
-	public function getUrl(): string
137
-	{
138
-
139
-		$url_chunks = [];
140
-		$service_endpoint = $this->getServiceEndpoint();
141
-		if (!$service_endpoint) {
142
-			throw new RequestException('Service name missing!');
143
-		}
144
-
145
-		$request_endpoint = $this->request->getEndpoint();
146
-		array_push($url_chunks, $this->api_url . $service_endpoint);
147
-
148
-		if($request_endpoint) {
149
-			array_push($url_chunks, $request_endpoint);
150
-		}
151
-
152
-		array_push($url_chunks, GoogleMapsResponseFormat::JSON);
153
-		return implode("/", $url_chunks);
154
-	}
155
-
156
-	/**
157
-	 * @return string
158
-	 */
159
-	public function getServiceEndpoint(): string
160
-	{
161
-
162
-		return $this->service_endpoint;
163
-	}
164
-
165
-	/**
166
-	 * @param string $service_endpoint
167
-	 *
168
-	 * @return GoogleMapsApi
169
-	 */
170
-	public function setServiceEndpoint(string $service_endpoint): GoogleMapsApi
171
-	{
172
-
173
-		$this->service_endpoint = $service_endpoint;
174
-
175
-		return $this;
176
-	}
177
-
178
-	/**
179
-	 * @return string
180
-	 */
181
-	public function getQuery(): string
182
-	{
183
-
184
-		$api_query = http_build_query([
185
-			GoogleMapsRequestFields::KEY    => $this->getKey(),
186
-			GoogleMapsRequestFields::SENSOR => $this->getSensor(),
187
-		]);
188
-
189
-		$request_query = $this->getRequest()->getQuery();
190
-
191
-		return implode('&', [
192
-			$api_query,
193
-			$request_query
194
-		]);
195
-	}
196
-
197
-	/**
198
-	 * @return string
199
-	 */
200
-	public function getKey(): string
201
-	{
202
-
203
-		return $this->key;
204
-	}
205
-
206
-	/**
207
-	 * @param string $key
208
-	 *
209
-	 * @return GoogleMapsApi
210
-	 */
211
-	public function setKey(string $key): GoogleMapsApi
212
-	{
213
-
214
-		$this->key = $key;
215
-
216
-		return $this;
217
-	}
218
-
219
-	/**
220
-	 * @return string
221
-	 */
222
-	public function getSensor(): string
223
-	{
224
-
225
-		return $this->sensor ? 'true' : 'false';
226
-	}
227
-
228
-	/**
229
-	 * Set sensor parameter
230
-	 *
231
-	 * @param bool|string $sensor
232
-	 *
233
-	 * @return GoogleMapsApi
234
-	 */
235
-	public function setSensor($sensor): GoogleMapsApi
236
-	{
237
-
238
-		if ($sensor !== SensorValues::FALSE) {
239
-			$sensor = SensorValues::TRUE;
240
-		}
241
-		$this->sensor = $sensor;
242
-
243
-		return $this;
244
-	}
245
-
246
-	/**
247
-	 * @return GoogleMapsRequest
248
-	 */
249
-	public function getRequest(): GoogleMapsRequest
250
-	{
251
-
252
-		return $this->request;
253
-	}
254
-
255
-	/**
256
-	 * @param GoogleMapsRequest $request
257
-	 *
258
-	 * @return GoogleMapsApi
259
-	 */
260
-	public function setRequest(GoogleMapsRequest $request)
261
-	{
262
-
263
-		$this->request = $request;
264
-
265
-		return $this;
266
-	}
267
-
268
-	/**
269
-	 * @return GoogleMapsClient
270
-	 */
271
-	public function getClient()
272
-	{
273
-
274
-		return $this->client;
275
-	}
276
-
277
-	/**
278
-	 * @param GoogleMapsClient|null $client
279
-	 *
280
-	 * @return GoogleMapsApi
281
-	 */
282
-	public function setClient(?GoogleMapsClient $client = null): GoogleMapsApi
283
-	{
284
-
285
-		$this->client = $client ?? new GoogleMapsClient();
286
-
287
-		return $this;
288
-	}
289
-
290
-	/**
291
-	 * @param string $type
292
-	 *
293
-	 * @return GoogleMapsApi
294
-	 */
295
-	protected function setType(string $type): GoogleMapsApi
296
-	{
297
-
298
-		$this->type = $type;
299
-
300
-		return $this;
301
-	}
28
+    /**
29
+     * @var GoogleMapsApi
30
+     */
31
+    protected static $instance = null;
32
+
33
+    /**
34
+     * @var GoogleMapsRequest
35
+     */
36
+    protected $request = null;
37
+
38
+    /**
39
+     * Google Maps Geocode Service API url
40
+     * @var string
41
+     */
42
+    private $api_url = "https://maps.googleapis.com/maps/api/";
43
+
44
+    /**
45
+     * your own Google Maps API key
46
+     * @var string
47
+     * @see https://developers.google.com/maps/documentation/javascript/get-api-key
48
+     */
49
+    private $key = '';
50
+
51
+    /**
52
+     * Google Maps API sensor
53
+     * @var string - true|false
54
+     */
55
+    private $sensor = 'false';
56
+
57
+    /**
58
+     * Google Maps API service name
59
+     * @var string
60
+     */
61
+    private $service_endpoint = '';
62
+
63
+    /**
64
+     * @var string
65
+     */
66
+    private $response = null;
67
+
68
+    /**
69
+     * @var GoogleMapsClient
70
+     */
71
+    private $client = null;
72
+
73
+    /**
74
+     * @var string
75
+     */
76
+    private $type = null;
77
+
78
+    /**
79
+     * GoogleMapsApi constructor.
80
+     *
81
+     * @param array $config
82
+     */
83
+    public function __construct(array $config = [])
84
+    {
85
+
86
+        // Set "API key"
87
+        $key = (empty($config[GoogleMapsApiConfigFields::KEY])) ? '' : $config[GoogleMapsApiConfigFields::KEY];
88
+        $this->setKey($key);
89
+
90
+        // Set "sensor"
91
+        $sensor = (empty($config[GoogleMapsApiConfigFields::SENSOR])) ? SensorValues::FALSE : $config[GoogleMapsApiConfigFields::SENSOR];
92
+        $this->setSensor($sensor);
93
+
94
+        // Set the endpoint
95
+        $service_endpoint = (empty($config[GoogleMapsApiConfigFields::SERVICE_ENDPOINT])) ? '' : $config[GoogleMapsApiConfigFields::SERVICE_ENDPOINT];
96
+        $this->setServiceEndpoint($service_endpoint);
97
+
98
+        // Set Client
99
+        $this->setClient();
100
+    }
101
+
102
+    /**
103
+     * @return string
104
+     */
105
+    public function getApiUrl(): string
106
+    {
107
+
108
+        return $this->api_url;
109
+    }
110
+
111
+    /**
112
+     * Perform the Google Maps API call
113
+     *
114
+     * @param GoogleMapsRequest $request
115
+     *
116
+     * @return Http\GoogleMapsResponse|string
117
+     */
118
+    public function get(GoogleMapsRequest $request)
119
+    {
120
+
121
+        $this->setRequest($request);
122
+
123
+        $url = $this->getUrl();
124
+
125
+        $query = $this->getQuery();
126
+
127
+        $this->response = $this->getClient()->get($url, $query);
128
+
129
+        return $this->response;
130
+    }
131
+
132
+    /**
133
+     * @return string
134
+     * @throws RequestException
135
+     */
136
+    public function getUrl(): string
137
+    {
138
+
139
+        $url_chunks = [];
140
+        $service_endpoint = $this->getServiceEndpoint();
141
+        if (!$service_endpoint) {
142
+            throw new RequestException('Service name missing!');
143
+        }
144
+
145
+        $request_endpoint = $this->request->getEndpoint();
146
+        array_push($url_chunks, $this->api_url . $service_endpoint);
147
+
148
+        if($request_endpoint) {
149
+            array_push($url_chunks, $request_endpoint);
150
+        }
151
+
152
+        array_push($url_chunks, GoogleMapsResponseFormat::JSON);
153
+        return implode("/", $url_chunks);
154
+    }
155
+
156
+    /**
157
+     * @return string
158
+     */
159
+    public function getServiceEndpoint(): string
160
+    {
161
+
162
+        return $this->service_endpoint;
163
+    }
164
+
165
+    /**
166
+     * @param string $service_endpoint
167
+     *
168
+     * @return GoogleMapsApi
169
+     */
170
+    public function setServiceEndpoint(string $service_endpoint): GoogleMapsApi
171
+    {
172
+
173
+        $this->service_endpoint = $service_endpoint;
174
+
175
+        return $this;
176
+    }
177
+
178
+    /**
179
+     * @return string
180
+     */
181
+    public function getQuery(): string
182
+    {
183
+
184
+        $api_query = http_build_query([
185
+            GoogleMapsRequestFields::KEY    => $this->getKey(),
186
+            GoogleMapsRequestFields::SENSOR => $this->getSensor(),
187
+        ]);
188
+
189
+        $request_query = $this->getRequest()->getQuery();
190
+
191
+        return implode('&', [
192
+            $api_query,
193
+            $request_query
194
+        ]);
195
+    }
196
+
197
+    /**
198
+     * @return string
199
+     */
200
+    public function getKey(): string
201
+    {
202
+
203
+        return $this->key;
204
+    }
205
+
206
+    /**
207
+     * @param string $key
208
+     *
209
+     * @return GoogleMapsApi
210
+     */
211
+    public function setKey(string $key): GoogleMapsApi
212
+    {
213
+
214
+        $this->key = $key;
215
+
216
+        return $this;
217
+    }
218
+
219
+    /**
220
+     * @return string
221
+     */
222
+    public function getSensor(): string
223
+    {
224
+
225
+        return $this->sensor ? 'true' : 'false';
226
+    }
227
+
228
+    /**
229
+     * Set sensor parameter
230
+     *
231
+     * @param bool|string $sensor
232
+     *
233
+     * @return GoogleMapsApi
234
+     */
235
+    public function setSensor($sensor): GoogleMapsApi
236
+    {
237
+
238
+        if ($sensor !== SensorValues::FALSE) {
239
+            $sensor = SensorValues::TRUE;
240
+        }
241
+        $this->sensor = $sensor;
242
+
243
+        return $this;
244
+    }
245
+
246
+    /**
247
+     * @return GoogleMapsRequest
248
+     */
249
+    public function getRequest(): GoogleMapsRequest
250
+    {
251
+
252
+        return $this->request;
253
+    }
254
+
255
+    /**
256
+     * @param GoogleMapsRequest $request
257
+     *
258
+     * @return GoogleMapsApi
259
+     */
260
+    public function setRequest(GoogleMapsRequest $request)
261
+    {
262
+
263
+        $this->request = $request;
264
+
265
+        return $this;
266
+    }
267
+
268
+    /**
269
+     * @return GoogleMapsClient
270
+     */
271
+    public function getClient()
272
+    {
273
+
274
+        return $this->client;
275
+    }
276
+
277
+    /**
278
+     * @param GoogleMapsClient|null $client
279
+     *
280
+     * @return GoogleMapsApi
281
+     */
282
+    public function setClient(?GoogleMapsClient $client = null): GoogleMapsApi
283
+    {
284
+
285
+        $this->client = $client ?? new GoogleMapsClient();
286
+
287
+        return $this;
288
+    }
289
+
290
+    /**
291
+     * @param string $type
292
+     *
293
+     * @return GoogleMapsApi
294
+     */
295
+    protected function setType(string $type): GoogleMapsApi
296
+    {
297
+
298
+        $this->type = $type;
299
+
300
+        return $this;
301
+    }
302 302
 
303 303
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -143,9 +143,9 @@
 block discarded – undo
143 143
 		}
144 144
 
145 145
 		$request_endpoint = $this->request->getEndpoint();
146
-		array_push($url_chunks, $this->api_url . $service_endpoint);
146
+		array_push($url_chunks, $this->api_url.$service_endpoint);
147 147
 
148
-		if($request_endpoint) {
148
+		if ($request_endpoint) {
149 149
 			array_push($url_chunks, $request_endpoint);
150 150
 		}
151 151
 
Please login to merge, or discard this patch.
src/Abstracts/AbstractCollection.php 1 patch
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -17,227 +17,227 @@
 block discarded – undo
17 17
 abstract class AbstractCollection implements \Iterator, \Countable
18 18
 {
19 19
 
20
-	/**
21
-	 * @var array
22
-	 */
23
-	protected $items = [];
24
-
25
-	/**
26
-	 * @var int
27
-	 */
28
-	protected $index = 0;
29
-
30
-	/**
31
-	 * AbstractCollection constructor.
32
-	 *
33
-	 * @param null|array $items
34
-	 */
35
-	public function __construct(?array $items = [])
36
-	{
37
-
38
-		$this->setItems($items);
39
-	}
40
-
41
-	/**
42
-	 * @param array $items
43
-	 *
44
-	 * @return AbstractCollection
45
-	 */
46
-	protected function setItems(?array $items = [])
47
-	{
48
-
49
-		if (is_array($items) && count($items)) {
50
-			foreach ($items as $item) {
51
-				$this->addItem($item);
52
-			}
53
-		}
54
-
55
-		return $this;
56
-	}
57
-
58
-	/**
59
-	 * @param $item
60
-	 *
61
-	 * @return AbstractCollection
62
-	 */
63
-	public function addItem($item)
64
-	{
65
-
66
-		$item = $this->parseItem($item);
67
-		array_push($this->items, $item);
68
-
69
-		return $this;
70
-	}
71
-
72
-	/**
73
-	 * @param $item
74
-	 *
75
-	 * @return mixed
76
-	 */
77
-	protected function parseItem($item)
78
-	{
79
-
80
-		return $item;
81
-	}
82
-
83
-	/**
84
-	 * @return string
85
-	 */
86
-	public function toJson(): string
87
-	{
88
-
89
-		return json_encode($this->toArray());
90
-	}
91
-
92
-	/**
93
-	 * @return array
94
-	 */
95
-	public function toArray(): array
96
-	{
97
-
98
-		return $this->items;
99
-	}
100
-
101
-	/**
102
-	 * @return string
103
-	 */
104
-	public function __toString(): string
105
-	{
106
-
107
-		return implode(',', $this->toArray());
108
-	}
109
-
110
-	/**
111
-	 * Return the current position of the index
112
-	 *
113
-	 * @return int
114
-	 */
115
-	public function position(): int
116
-	{
117
-
118
-		return $this->index;
119
-	}
120
-
121
-	/**
122
-	 * Move index to first position and return current element
123
-	 *
124
-	 * @return mixed|null
125
-	 */
126
-	public function first()
127
-	{
128
-
129
-		return $this->get(0);
130
-	}
131
-
132
-	/**
133
-	 * @param $index
134
-	 *
135
-	 * @return mixed|null
136
-	 */
137
-	public function get(int $index)
138
-	{
139
-
140
-		return isset($this->items[$index]) ? $this->items[$index] : null;
141
-	}
142
-
143
-	/**
144
-	 * Move the index at the specified position
145
-	 *
146
-	 * @param int|null $index
147
-	 *
148
-	 * @return mixed|null
149
-	 */
150
-	public function seek(?int $index = 0)
151
-	{
152
-
153
-		$this->index = ($index < $this->count()) ? $index : $this->getLastIndex();
154
-
155
-		return $this->get(intval($this->index));
156
-	}
157
-
158
-	/**
159
-	 * @return int
160
-	 */
161
-	public function count(): int
162
-	{
163
-
164
-		return count($this->items);
165
-	}
166
-
167
-	/**
168
-	 * @return int
169
-	 */
170
-	public function getLastIndex(): int
171
-	{
172
-
173
-		$last_position = $this->count() - 1;
174
-
175
-		return ($last_position) < 0 ? 0 : $last_position;
176
-	}
177
-
178
-	/**
179
-	 * Move index at the end of collection and return current element
180
-	 *
181
-	 * @return mixed|null
182
-	 */
183
-	public function last()
184
-	{
185
-
186
-		return $this->get($this->getLastIndex());
187
-	}
188
-
189
-	/**
190
-	 *
191
-	 * @return mixed|null
192
-	 */
193
-	public function current()
194
-	{
195
-
196
-		return $this->get($this->index);
197
-	}
198
-
199
-	/**
200
-	 * Move index to next position and return current element
201
-	 *
202
-	 * @return mixed|null
203
-	 */
204
-	public function next()
205
-	{
206
-
207
-		++$this->index;
208
-	}
209
-
210
-	/**
211
-	 * Return current key/index
212
-	 *
213
-	 * @return mixed|null
214
-	 */
215
-	public function key()
216
-	{
217
-
218
-		return $this->index;
219
-	}
220
-
221
-	/**
222
-	 * Return current key/index
223
-	 *
224
-	 * @return mixed|null
225
-	 */
226
-	public function valid()
227
-	{
228
-
229
-		return !empty($this->current());
230
-	}
231
-
232
-	/**
233
-	 * Move index to first position and return current element
234
-	 *
235
-	 * @return mixed|null
236
-	 */
237
-	public function rewind()
238
-	{
239
-
240
-		return $this->index = 0;
241
-	}
20
+    /**
21
+     * @var array
22
+     */
23
+    protected $items = [];
24
+
25
+    /**
26
+     * @var int
27
+     */
28
+    protected $index = 0;
29
+
30
+    /**
31
+     * AbstractCollection constructor.
32
+     *
33
+     * @param null|array $items
34
+     */
35
+    public function __construct(?array $items = [])
36
+    {
37
+
38
+        $this->setItems($items);
39
+    }
40
+
41
+    /**
42
+     * @param array $items
43
+     *
44
+     * @return AbstractCollection
45
+     */
46
+    protected function setItems(?array $items = [])
47
+    {
48
+
49
+        if (is_array($items) && count($items)) {
50
+            foreach ($items as $item) {
51
+                $this->addItem($item);
52
+            }
53
+        }
54
+
55
+        return $this;
56
+    }
57
+
58
+    /**
59
+     * @param $item
60
+     *
61
+     * @return AbstractCollection
62
+     */
63
+    public function addItem($item)
64
+    {
65
+
66
+        $item = $this->parseItem($item);
67
+        array_push($this->items, $item);
68
+
69
+        return $this;
70
+    }
71
+
72
+    /**
73
+     * @param $item
74
+     *
75
+     * @return mixed
76
+     */
77
+    protected function parseItem($item)
78
+    {
79
+
80
+        return $item;
81
+    }
82
+
83
+    /**
84
+     * @return string
85
+     */
86
+    public function toJson(): string
87
+    {
88
+
89
+        return json_encode($this->toArray());
90
+    }
91
+
92
+    /**
93
+     * @return array
94
+     */
95
+    public function toArray(): array
96
+    {
97
+
98
+        return $this->items;
99
+    }
100
+
101
+    /**
102
+     * @return string
103
+     */
104
+    public function __toString(): string
105
+    {
106
+
107
+        return implode(',', $this->toArray());
108
+    }
109
+
110
+    /**
111
+     * Return the current position of the index
112
+     *
113
+     * @return int
114
+     */
115
+    public function position(): int
116
+    {
117
+
118
+        return $this->index;
119
+    }
120
+
121
+    /**
122
+     * Move index to first position and return current element
123
+     *
124
+     * @return mixed|null
125
+     */
126
+    public function first()
127
+    {
128
+
129
+        return $this->get(0);
130
+    }
131
+
132
+    /**
133
+     * @param $index
134
+     *
135
+     * @return mixed|null
136
+     */
137
+    public function get(int $index)
138
+    {
139
+
140
+        return isset($this->items[$index]) ? $this->items[$index] : null;
141
+    }
142
+
143
+    /**
144
+     * Move the index at the specified position
145
+     *
146
+     * @param int|null $index
147
+     *
148
+     * @return mixed|null
149
+     */
150
+    public function seek(?int $index = 0)
151
+    {
152
+
153
+        $this->index = ($index < $this->count()) ? $index : $this->getLastIndex();
154
+
155
+        return $this->get(intval($this->index));
156
+    }
157
+
158
+    /**
159
+     * @return int
160
+     */
161
+    public function count(): int
162
+    {
163
+
164
+        return count($this->items);
165
+    }
166
+
167
+    /**
168
+     * @return int
169
+     */
170
+    public function getLastIndex(): int
171
+    {
172
+
173
+        $last_position = $this->count() - 1;
174
+
175
+        return ($last_position) < 0 ? 0 : $last_position;
176
+    }
177
+
178
+    /**
179
+     * Move index at the end of collection and return current element
180
+     *
181
+     * @return mixed|null
182
+     */
183
+    public function last()
184
+    {
185
+
186
+        return $this->get($this->getLastIndex());
187
+    }
188
+
189
+    /**
190
+     *
191
+     * @return mixed|null
192
+     */
193
+    public function current()
194
+    {
195
+
196
+        return $this->get($this->index);
197
+    }
198
+
199
+    /**
200
+     * Move index to next position and return current element
201
+     *
202
+     * @return mixed|null
203
+     */
204
+    public function next()
205
+    {
206
+
207
+        ++$this->index;
208
+    }
209
+
210
+    /**
211
+     * Return current key/index
212
+     *
213
+     * @return mixed|null
214
+     */
215
+    public function key()
216
+    {
217
+
218
+        return $this->index;
219
+    }
220
+
221
+    /**
222
+     * Return current key/index
223
+     *
224
+     * @return mixed|null
225
+     */
226
+    public function valid()
227
+    {
228
+
229
+        return !empty($this->current());
230
+    }
231
+
232
+    /**
233
+     * Move index to first position and return current element
234
+     *
235
+     * @return mixed|null
236
+     */
237
+    public function rewind()
238
+    {
239
+
240
+        return $this->index = 0;
241
+    }
242 242
 
243 243
 }
244 244
\ No newline at end of file
Please login to merge, or discard this patch.
src/Abstracts/Api.php 2 patches
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -24,158 +24,158 @@
 block discarded – undo
24 24
 abstract class Api
25 25
 {
26 26
 
27
-	/**
28
-	 * @var string
29
-	 */
30
-	const SERVICE_ENDPOINT = null;
31
-
32
-	/**
33
-	 * @var GoogleMapsApi
34
-	 */
35
-	protected $google_maps_api = null;
36
-
37
-	/**
38
-	 * @var string
39
-	 */
40
-	protected $result_collection = '';
41
-
42
-	/**
43
-	 * @var GoogleMapsResponse
44
-	 */
45
-	protected $response;
46
-
47
-	/**
48
-	 * @var GoogleMapsRequest
49
-	 */
50
-	protected $request;
51
-
52
-	/**
53
-	 * Api constructor.
54
-	 *
55
-	 * @param array $config
56
-	 */
57
-	public function __construct(array $config = [])
58
-	{
59
-
60
-		$service_config = $this->getServiceConfig($config);
61
-		$this->setGoogleMapsApi(new GoogleMapsApi($service_config));
62
-	}
63
-
64
-	/**
65
-	 * @param array $config
66
-	 *
67
-	 * @return array
68
-	 */
69
-	protected function getServiceConfig(array $config = []): array
70
-	{
71
-
72
-		return array_merge($config, [
73
-			GoogleMapsApiConfigFields::SERVICE_ENDPOINT => $this->getServiceEndpoint()
74
-		]);
75
-	}
76
-
77
-	/**
78
-	 * @return string
79
-	 */
80
-	public function getServiceEndpoint(): string
81
-	{
82
-
83
-		return static::SERVICE_ENDPOINT ?? '';
84
-	}
85
-
86
-	/**
87
-	 * @param array       $params
88
-	 * @param null|string $endpoint
89
-	 *
90
-	 * @return GoogleMapsResultsCollection
91
-	 */
92
-	public function callApi(array $params, ?string $endpoint = null): GoogleMapsResultsCollection
93
-	{
94
-
95
-		$this->createRequest($params, $endpoint);
96
-
97
-		return $this->getResultsCollections();
98
-	}
99
-
100
-	/**
101
-	 * @param array       $params
102
-	 * @param null|string $endpoint since 0.5.0
103
-	 *
104
-	 * @return GoogleMapsRequest
105
-	 */
106
-	public function createRequest(array $params, ?string $endpoint = null): GoogleMapsRequest
107
-	{
108
-
109
-		$this->request = new GoogleMapsRequest($params, $endpoint);;
110
-
111
-		return $this->request;
112
-	}
113
-
114
-	/**
115
-	 * @return GoogleMapsResultsCollection
116
-	 */
117
-	public function getResultsCollections(): GoogleMapsResultsCollection
118
-	{
119
-
120
-		$results = $this->getResponse()->getResults();
121
-
122
-		$result_collection_class = $this->result_collection;
123
-
124
-		return new $result_collection_class($results);
125
-	}
126
-
127
-	/**
128
-	 * @return GoogleMapsResponse
129
-	 */
130
-	public function getResponse(): GoogleMapsResponse
131
-	{
132
-
133
-		$this->response = $this->getGoogleMapsApi()->get($this->request);
134
-
135
-		return $this->response;
136
-	}
137
-
138
-	/**
139
-	 * @return GoogleMapsApi
140
-	 */
141
-	public function getGoogleMapsApi(): GoogleMapsApi
142
-	{
143
-
144
-		return $this->google_maps_api;
145
-	}
146
-
147
-	/**
148
-	 * @param GoogleMapsApi $google_maps_api
149
-	 *
150
-	 * @return Api
151
-	 */
152
-	public function setGoogleMapsApi(GoogleMapsApi $google_maps_api): Api
153
-	{
154
-
155
-		$this->google_maps_api = $google_maps_api;
156
-
157
-		return $this;
158
-	}
159
-
160
-	/**
161
-	 * @return GoogleMapsResultsCollection
162
-	 */
163
-	public function getNextPage(): GoogleMapsResultsCollection
164
-	{
165
-
166
-		if ($this->responseHasNewPage()) {
167
-			$this->request->setParam(GoogleMapsRequestFields::NEXT_PAGE_TOKEN, $this->response->getNextPageToken());
168
-		}
169
-
170
-		return $this->getResultsCollections();
171
-	}
172
-
173
-	/**
174
-	 * @return bool
175
-	 */
176
-	public function responseHasNewPage(): bool
177
-	{
178
-
179
-		return ($this->response instanceof GoogleMapsResponse) ? $this->response->getNextPageToken() : false;
180
-	}
27
+    /**
28
+     * @var string
29
+     */
30
+    const SERVICE_ENDPOINT = null;
31
+
32
+    /**
33
+     * @var GoogleMapsApi
34
+     */
35
+    protected $google_maps_api = null;
36
+
37
+    /**
38
+     * @var string
39
+     */
40
+    protected $result_collection = '';
41
+
42
+    /**
43
+     * @var GoogleMapsResponse
44
+     */
45
+    protected $response;
46
+
47
+    /**
48
+     * @var GoogleMapsRequest
49
+     */
50
+    protected $request;
51
+
52
+    /**
53
+     * Api constructor.
54
+     *
55
+     * @param array $config
56
+     */
57
+    public function __construct(array $config = [])
58
+    {
59
+
60
+        $service_config = $this->getServiceConfig($config);
61
+        $this->setGoogleMapsApi(new GoogleMapsApi($service_config));
62
+    }
63
+
64
+    /**
65
+     * @param array $config
66
+     *
67
+     * @return array
68
+     */
69
+    protected function getServiceConfig(array $config = []): array
70
+    {
71
+
72
+        return array_merge($config, [
73
+            GoogleMapsApiConfigFields::SERVICE_ENDPOINT => $this->getServiceEndpoint()
74
+        ]);
75
+    }
76
+
77
+    /**
78
+     * @return string
79
+     */
80
+    public function getServiceEndpoint(): string
81
+    {
82
+
83
+        return static::SERVICE_ENDPOINT ?? '';
84
+    }
85
+
86
+    /**
87
+     * @param array       $params
88
+     * @param null|string $endpoint
89
+     *
90
+     * @return GoogleMapsResultsCollection
91
+     */
92
+    public function callApi(array $params, ?string $endpoint = null): GoogleMapsResultsCollection
93
+    {
94
+
95
+        $this->createRequest($params, $endpoint);
96
+
97
+        return $this->getResultsCollections();
98
+    }
99
+
100
+    /**
101
+     * @param array       $params
102
+     * @param null|string $endpoint since 0.5.0
103
+     *
104
+     * @return GoogleMapsRequest
105
+     */
106
+    public function createRequest(array $params, ?string $endpoint = null): GoogleMapsRequest
107
+    {
108
+
109
+        $this->request = new GoogleMapsRequest($params, $endpoint);;
110
+
111
+        return $this->request;
112
+    }
113
+
114
+    /**
115
+     * @return GoogleMapsResultsCollection
116
+     */
117
+    public function getResultsCollections(): GoogleMapsResultsCollection
118
+    {
119
+
120
+        $results = $this->getResponse()->getResults();
121
+
122
+        $result_collection_class = $this->result_collection;
123
+
124
+        return new $result_collection_class($results);
125
+    }
126
+
127
+    /**
128
+     * @return GoogleMapsResponse
129
+     */
130
+    public function getResponse(): GoogleMapsResponse
131
+    {
132
+
133
+        $this->response = $this->getGoogleMapsApi()->get($this->request);
134
+
135
+        return $this->response;
136
+    }
137
+
138
+    /**
139
+     * @return GoogleMapsApi
140
+     */
141
+    public function getGoogleMapsApi(): GoogleMapsApi
142
+    {
143
+
144
+        return $this->google_maps_api;
145
+    }
146
+
147
+    /**
148
+     * @param GoogleMapsApi $google_maps_api
149
+     *
150
+     * @return Api
151
+     */
152
+    public function setGoogleMapsApi(GoogleMapsApi $google_maps_api): Api
153
+    {
154
+
155
+        $this->google_maps_api = $google_maps_api;
156
+
157
+        return $this;
158
+    }
159
+
160
+    /**
161
+     * @return GoogleMapsResultsCollection
162
+     */
163
+    public function getNextPage(): GoogleMapsResultsCollection
164
+    {
165
+
166
+        if ($this->responseHasNewPage()) {
167
+            $this->request->setParam(GoogleMapsRequestFields::NEXT_PAGE_TOKEN, $this->response->getNextPageToken());
168
+        }
169
+
170
+        return $this->getResultsCollections();
171
+    }
172
+
173
+    /**
174
+     * @return bool
175
+     */
176
+    public function responseHasNewPage(): bool
177
+    {
178
+
179
+        return ($this->response instanceof GoogleMapsResponse) ? $this->response->getNextPageToken() : false;
180
+    }
181 181
 }
182 182
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -106,7 +106,7 @@
 block discarded – undo
106 106
 	public function createRequest(array $params, ?string $endpoint = null): GoogleMapsRequest
107 107
 	{
108 108
 
109
-		$this->request = new GoogleMapsRequest($params, $endpoint);;
109
+		$this->request = new GoogleMapsRequest($params, $endpoint); ;
110 110
 
111 111
 		return $this->request;
112 112
 	}
Please login to merge, or discard this patch.
src/Enum/GoogleMapsResponseFormat.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -17,15 +17,15 @@
 block discarded – undo
17 17
 class GoogleMapsResponseFormat
18 18
 {
19 19
 
20
-	/**
21
-	 * string: json
22
-	 */
23
-	const JSON = 'json';
20
+    /**
21
+     * string: json
22
+     */
23
+    const JSON = 'json';
24 24
 
25
-	/**
26
-	 * string: xml
27
-	 * NOT supported in this version
28
-	 */
29
-	const XML = 'xml';
25
+    /**
26
+     * string: xml
27
+     * NOT supported in this version
28
+     */
29
+    const XML = 'xml';
30 30
 
31 31
 }
32 32
\ No newline at end of file
Please login to merge, or discard this patch.
src/Enum/PlaceServicesEndpoints.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -17,18 +17,18 @@
 block discarded – undo
17 17
 class PlaceServicesEndpoints
18 18
 {
19 19
 
20
-	/**
21
-	 * @var string
22
-	 */
23
-	const FINDPLACEFROMTEXT = "findplacefromtext";
20
+    /**
21
+     * @var string
22
+     */
23
+    const FINDPLACEFROMTEXT = "findplacefromtext";
24 24
 
25
-	/**
26
-	 * @var string
27
-	 */
28
-	const NEARBYSEARCH = "nearbysearch";
25
+    /**
26
+     * @var string
27
+     */
28
+    const NEARBYSEARCH = "nearbysearch";
29 29
 
30
-	/**
31
-	 * @var string
32
-	 */
33
-	const TEXTSEARCH = "textsearch";
30
+    /**
31
+     * @var string
32
+     */
33
+    const TEXTSEARCH = "textsearch";
34 34
 }
35 35
\ No newline at end of file
Please login to merge, or discard this patch.
src/Enum/GoogleMapsApiConfigFields.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -17,18 +17,18 @@
 block discarded – undo
17 17
 class GoogleMapsApiConfigFields
18 18
 {
19 19
 
20
-	/**
21
-	 * string: key
22
-	 */
23
-	const KEY = 'key';
20
+    /**
21
+     * string: key
22
+     */
23
+    const KEY = 'key';
24 24
 
25
-	/**
26
-	 * string: sensor
27
-	 */
28
-	const SENSOR = 'sensor';
25
+    /**
26
+     * string: sensor
27
+     */
28
+    const SENSOR = 'sensor';
29 29
 
30
-	/**
31
-	 * string: service_endpoint
32
-	 */
33
-	const SERVICE_ENDPOINT = 'service_endpoint';
30
+    /**
31
+     * string: service_endpoint
32
+     */
33
+    const SERVICE_ENDPOINT = 'service_endpoint';
34 34
 }
35 35
\ No newline at end of file
Please login to merge, or discard this patch.