@@ -25,22 +25,22 @@ discard block |
||
25 | 25 | */ |
26 | 26 | public function __construct(string $userAgent, bool $needAutoloader = false) |
27 | 27 | { |
28 | - if($needAutoloader) |
|
28 | + if ($needAutoloader) |
|
29 | 29 | $this->autoload("./"); |
30 | 30 | |
31 | 31 | $this->userAgent = $userAgent; |
32 | 32 | } |
33 | 33 | |
34 | 34 | private function autoload($directory) { |
35 | - if(is_dir($directory)) { |
|
35 | + if (is_dir($directory)) { |
|
36 | 36 | $scan = scandir($directory); |
37 | 37 | unset($scan[0], $scan[1]); //unset . and .. |
38 | - foreach($scan as $file) { |
|
39 | - if(is_dir($directory."/".$file)) { |
|
40 | - $this->autoload($directory."/".$file); |
|
38 | + foreach ($scan as $file) { |
|
39 | + if (is_dir($directory . "/" . $file)) { |
|
40 | + $this->autoload($directory . "/" . $file); |
|
41 | 41 | } else { |
42 | - if(strpos($file, '.php') !== false) { |
|
43 | - include_once($directory."/".$file); |
|
42 | + if (strpos($file, '.php') !== false) { |
|
43 | + include_once($directory . "/" . $file); |
|
44 | 44 | } |
45 | 45 | } |
46 | 46 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | |
85 | 85 | $apiResult = $this->callAPI($endpoint); |
86 | 86 | |
87 | - if($apiResult === false || $apiResult == "Not Found") { |
|
87 | + if ($apiResult === false || $apiResult == "Not Found") { |
|
88 | 88 | $response->setErrorStatus(true)->setErrorMessage("[getMap] Something went wrong with the API call."); |
89 | 89 | return $response; |
90 | 90 | } |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | |
144 | 144 | $apiResult = $this->callAPI($endpoint); |
145 | 145 | |
146 | - if($apiResult === false || $apiResult == "Not Found") { |
|
146 | + if ($apiResult === false || $apiResult == "Not Found") { |
|
147 | 147 | $response->setErrorStatus(true)->setErrorMessage("[getMap] Something went wrong with the API call."); |
148 | 148 | return $response; |
149 | 149 | } |
@@ -189,15 +189,15 @@ discard block |
||
189 | 189 | $callNumber = 0; |
190 | 190 | $result = new ResponseMaps(); |
191 | 191 | |
192 | - if(count($hashes) < 2) { |
|
192 | + if (count($hashes) < 2) { |
|
193 | 193 | return $result->setErrorStatus(true)->setErrorMessage("This functions require a minimum of 2 hashes in the array"); |
194 | 194 | } |
195 | 195 | |
196 | - foreach($hashes as $hash) { |
|
196 | + foreach ($hashes as $hash) { |
|
197 | 197 | $hashesString .= $hash; |
198 | 198 | |
199 | - if($i !== 0 && $i % self::MAX_HASHES_NUMBER === 0) { |
|
200 | - if($callNumber === self::MAX_CALL_PER_SECS) { |
|
199 | + if ($i !== 0 && $i % self::MAX_HASHES_NUMBER === 0) { |
|
200 | + if ($callNumber === self::MAX_CALL_PER_SECS) { |
|
201 | 201 | sleep(1); |
202 | 202 | $callNumber = 0; |
203 | 203 | } |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | |
208 | 208 | $mapsArray = array_merge($mapsArray, $maps->getBeatMaps()); |
209 | 209 | |
210 | - if(!isset($mapsArray["errorStatus"]) || !$mapsArray["errorStatus"]) { |
|
210 | + if (!isset($mapsArray["errorStatus"]) || !$mapsArray["errorStatus"]) { |
|
211 | 211 | $mapsArray["errorStatus"] = $maps->getErrorStatus(); |
212 | 212 | $mapsArray["errorMessage"] = $maps->getErrorMessage(); |
213 | 213 | } |
@@ -221,18 +221,18 @@ discard block |
||
221 | 221 | } |
222 | 222 | |
223 | 223 | |
224 | - if($i !== 0) { |
|
224 | + if ($i !== 0) { |
|
225 | 225 | $maps = $this->getMaps(substr($hashesString, 0, -1)); |
226 | 226 | $mapsArray = array_merge($mapsArray, $maps->getBeatMaps()); |
227 | 227 | |
228 | - if(!isset($mapsArray["errorStatus"]) || !$mapsArray["errorStatus"]) { |
|
228 | + if (!isset($mapsArray["errorStatus"]) || !$mapsArray["errorStatus"]) { |
|
229 | 229 | $mapsArray["errorStatus"] = $maps->getErrorStatus(); |
230 | 230 | $mapsArray["errorMessage"] = $maps->getErrorMessage(); |
231 | 231 | } |
232 | 232 | } |
233 | 233 | |
234 | - if(isset($mapsArray["errorStatus"]) && $mapsArray["errorStatus"]) |
|
235 | - $result->setErrorStatus( $mapsArray["errorStatus"])->setErrorMessage( $mapsArray["errorMessage"]); |
|
234 | + if (isset($mapsArray["errorStatus"]) && $mapsArray["errorStatus"]) |
|
235 | + $result->setErrorStatus($mapsArray["errorStatus"])->setErrorMessage($mapsArray["errorMessage"]); |
|
236 | 236 | |
237 | 237 | unset($mapsArray["errorStatus"]); |
238 | 238 | unset($mapsArray["errorMessage"]); |
@@ -254,20 +254,20 @@ discard block |
||
254 | 254 | $callNumber = 0; |
255 | 255 | |
256 | 256 | // Latest |
257 | - if($numberOfPage === 0 && $startPage === 0){ |
|
257 | + if ($numberOfPage === 0 && $startPage === 0) { |
|
258 | 258 | $apiResult = json_decode($this->callAPI(str_ireplace("page", 0, $endpoint))); |
259 | 259 | |
260 | - if($apiResult === false || $apiResult == "Not Found") { |
|
260 | + if ($apiResult === false || $apiResult == "Not Found") { |
|
261 | 261 | $response->setErrorStatus(true)->setErrorMessage("[getMaps] Something went wrong with the API call while calling the first page."); |
262 | 262 | return $response; |
263 | - } else{ |
|
263 | + } else { |
|
264 | 264 | foreach ($apiResult->docs as $beatmap) { |
265 | 265 | $maps[] = new BeatMap($beatmap); |
266 | 266 | } |
267 | 267 | } |
268 | 268 | } else { |
269 | - for($i = $startPage; $i < ($startPage + $numberOfPage); $i++){ |
|
270 | - if($callNumber === self::MAX_CALL_PER_SECS) { |
|
269 | + for ($i = $startPage; $i < ($startPage + $numberOfPage); $i++) { |
|
270 | + if ($callNumber === self::MAX_CALL_PER_SECS) { |
|
271 | 271 | sleep(1); |
272 | 272 | $callNumber = 0; |
273 | 273 | } |
@@ -275,10 +275,10 @@ discard block |
||
275 | 275 | $apiResult = json_decode($this->callAPI(str_ireplace("page", $i, $endpoint))); |
276 | 276 | $callNumber++; |
277 | 277 | |
278 | - if($apiResult === false || $apiResult == "Not Found") { |
|
278 | + if ($apiResult === false || $apiResult == "Not Found") { |
|
279 | 279 | $response->setErrorStatus(true)->setErrorMessage("[getMaps] Something went wrong with the API call while calling page number " . $i . "."); |
280 | 280 | |
281 | - if($apiResult == "Not Found") |
|
281 | + if ($apiResult == "Not Found") |
|
282 | 282 | return $response; |
283 | 283 | } |
284 | 284 | |
@@ -360,23 +360,23 @@ discard block |
||
360 | 360 | |
361 | 361 | $endpoint = "/search/text/page?sortOrder=" . $sort[$sortOrder]; |
362 | 362 | |
363 | - if($mapName) $endpoint .= "&q=" . urlencode($mapName); |
|
364 | - if($startDate) $endpoint .= "&from=" . $startDate->format("Y-m-d"); |
|
365 | - if($endDate) $endpoint .= "&to=" . $endDate->format("Y-m-d"); |
|
366 | - if($ranked) $endpoint .= "&ranked=" . /** @scrutinizer ignore-type */ var_export($ranked, true); |
|
367 | - if($automapper) $endpoint .= "&automapper=" . /** @scrutinizer ignore-type */ var_export($automapper, true); |
|
368 | - if($chroma) $endpoint .= "&chroma=" . /** @scrutinizer ignore-type */ var_export($chroma, true); |
|
369 | - if($noodle) $endpoint .= "&noodle=" . /** @scrutinizer ignore-type */ var_export($noodle, true); |
|
370 | - if($cinema) $endpoint .= "&cinema=" . /** @scrutinizer ignore-type */ var_export($cinema, true); |
|
371 | - if($fullSpread) $endpoint .= "&fullSpread=" . /** @scrutinizer ignore-type */ var_export($fullSpread, true); |
|
372 | - if($minBpm) $endpoint .= "&minBpm=" . /** @scrutinizer ignore-type */ $minBpm; |
|
373 | - if($maxBpm) $endpoint .= "&maxBpm=" . /** @scrutinizer ignore-type */ $maxBpm; |
|
374 | - if($minNps) $endpoint .= "&minNps=" . /** @scrutinizer ignore-type */ $minNps; |
|
375 | - if($maxNps) $endpoint .= "&maxNps=" . /** @scrutinizer ignore-type */ $maxNps; |
|
376 | - if($minRating) $endpoint .= "&minRating=" . /** @scrutinizer ignore-type */ $minRating; |
|
377 | - if($maxRating) $endpoint .= "&maxRating=" . /** @scrutinizer ignore-type */ $maxRating; |
|
378 | - if($minDuration !== null) $endpoint .= "&minDuration=" . /** @scrutinizer ignore-type */ $minDuration; |
|
379 | - if($maxDuration !== null) $endpoint .= "&maxDuration=" . /** @scrutinizer ignore-type */ $maxDuration; |
|
363 | + if ($mapName) $endpoint .= "&q=" . urlencode($mapName); |
|
364 | + if ($startDate) $endpoint .= "&from=" . $startDate->format("Y-m-d"); |
|
365 | + if ($endDate) $endpoint .= "&to=" . $endDate->format("Y-m-d"); |
|
366 | + if ($ranked) $endpoint .= "&ranked=" . /** @scrutinizer ignore-type */ var_export($ranked, true); |
|
367 | + if ($automapper) $endpoint .= "&automapper=" . /** @scrutinizer ignore-type */ var_export($automapper, true); |
|
368 | + if ($chroma) $endpoint .= "&chroma=" . /** @scrutinizer ignore-type */ var_export($chroma, true); |
|
369 | + if ($noodle) $endpoint .= "&noodle=" . /** @scrutinizer ignore-type */ var_export($noodle, true); |
|
370 | + if ($cinema) $endpoint .= "&cinema=" . /** @scrutinizer ignore-type */ var_export($cinema, true); |
|
371 | + if ($fullSpread) $endpoint .= "&fullSpread=" . /** @scrutinizer ignore-type */ var_export($fullSpread, true); |
|
372 | + if ($minBpm) $endpoint .= "&minBpm=" . /** @scrutinizer ignore-type */ $minBpm; |
|
373 | + if ($maxBpm) $endpoint .= "&maxBpm=" . /** @scrutinizer ignore-type */ $maxBpm; |
|
374 | + if ($minNps) $endpoint .= "&minNps=" . /** @scrutinizer ignore-type */ $minNps; |
|
375 | + if ($maxNps) $endpoint .= "&maxNps=" . /** @scrutinizer ignore-type */ $maxNps; |
|
376 | + if ($minRating) $endpoint .= "&minRating=" . /** @scrutinizer ignore-type */ $minRating; |
|
377 | + if ($maxRating) $endpoint .= "&maxRating=" . /** @scrutinizer ignore-type */ $maxRating; |
|
378 | + if ($minDuration !== null) $endpoint .= "&minDuration=" . /** @scrutinizer ignore-type */ $minDuration; |
|
379 | + if ($maxDuration !== null) $endpoint .= "&maxDuration=" . /** @scrutinizer ignore-type */ $maxDuration; |
|
380 | 380 | |
381 | 381 | return $this->getMapsByEndpoint($endpoint, $numberOfPage, $startPage); |
382 | 382 | } |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | |
397 | 397 | $apiResult = $this->callAPI($endpoint); |
398 | 398 | |
399 | - if($apiResult === false || $apiResult == "Not Found") { |
|
399 | + if ($apiResult === false || $apiResult == "Not Found") { |
|
400 | 400 | $response->setErrorStatus(true)->setErrorMessage("[getMap] Something went wrong with the API call."); |
401 | 401 | return $response; |
402 | 402 | } |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | mkdir($targetDir, 0777, true); |
429 | 429 | } |
430 | 430 | |
431 | - if(substr($targetDir, -1) !== "/") |
|
431 | + if (substr($targetDir, -1) !== "/") |
|
432 | 432 | $targetDir .= "/"; |
433 | 433 | |
434 | 434 | foreach ($hashes as $hash) { |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | |
450 | 450 | $result = curl_exec($ch); |
451 | 451 | |
452 | - if(curl_errno($ch) === 0) { |
|
452 | + if (curl_errno($ch) === 0) { |
|
453 | 453 | $response->pushDownloadMapHash($hash); |
454 | 454 | echo "Ok "; |
455 | 455 | } else { |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | |
473 | 473 | $result = curl_exec($ch); |
474 | 474 | |
475 | - if(curl_errno($ch) === 0) { |
|
475 | + if (curl_errno($ch) === 0) { |
|
476 | 476 | $response->pushDownloadMapHash($hash); |
477 | 477 | echo "Ok "; |
478 | 478 | } else { |