Passed
Push — master ( 4606a0...67a022 )
by Kylian
08:10 queued 06:32
created
lib/BeatSaverAPI.php 1 patch
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -25,22 +25,22 @@  discard block
 block discarded – undo
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,10 +84,10 @@  discard block
 block discarded – undo
84 84
 
85 85
         $apiResult = $this->callAPI($endpoint);
86 86
 
87
-        if($apiResult === false) {
87
+        if ($apiResult === false) {
88 88
             $response->setErrorStatus(true)->setErrorMessage("[getMap] Something went wrong with the API call (" . $endpoint . ")");
89 89
             return $response;
90
-        } elseif((json_decode($apiResult))->error == "Not Found") {
90
+        } elseif ((json_decode($apiResult))->error == "Not Found") {
91 91
             $response->setErrorStatus(true)->setErrorMessage("[getMap] Map not found (" . $endpoint . ")");
92 92
             return $response;
93 93
         }
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 
147 147
         $apiResult = $this->callAPI($endpoint);
148 148
 
149
-        if($apiResult === false || $apiResult == "Not Found") {
149
+        if ($apiResult === false || $apiResult == "Not Found") {
150 150
             $response->setErrorStatus(true)->setErrorMessage("[getMap] Something went wrong with the API call.");
151 151
             return $response;
152 152
         }
@@ -192,15 +192,15 @@  discard block
 block discarded – undo
192 192
         $callNumber = 0;
193 193
         $result = new ResponseMaps();
194 194
 
195
-        if(count($hashes) < 2) {
195
+        if (count($hashes) < 2) {
196 196
             return $result->setErrorStatus(true)->setErrorMessage("This functions require a minimum of 2 hashes in the array");
197 197
         }
198 198
 
199
-        foreach($hashes as $hash) {
199
+        foreach ($hashes as $hash) {
200 200
             $hashesString .= $hash;
201 201
 
202
-            if($i !== 0 && $i % self::MAX_HASHES_NUMBER === 0) {
203
-                if($callNumber === self::MAX_CALL_PER_SECS) {
202
+            if ($i !== 0 && $i % self::MAX_HASHES_NUMBER === 0) {
203
+                if ($callNumber === self::MAX_CALL_PER_SECS) {
204 204
                     sleep(1);
205 205
                     $callNumber = 0;
206 206
                 }
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 
211 211
                 $mapsArray = array_merge($mapsArray, $maps->getBeatMaps());
212 212
 
213
-                if(!isset($mapsArray["errorStatus"]) || !$mapsArray["errorStatus"]) {
213
+                if (!isset($mapsArray["errorStatus"]) || !$mapsArray["errorStatus"]) {
214 214
                     $mapsArray["errorStatus"] = $maps->getErrorStatus();
215 215
                     $mapsArray["errorMessage"] = $maps->getErrorMessage();
216 216
                 }
@@ -224,18 +224,18 @@  discard block
 block discarded – undo
224 224
         }
225 225
 
226 226
 
227
-        if($i !== 0) {
227
+        if ($i !== 0) {
228 228
             $maps = $this->getMaps(substr($hashesString, 0, -1));
229 229
             $mapsArray = array_merge($mapsArray, $maps->getBeatMaps());
230 230
 
231
-            if(!isset($mapsArray["errorStatus"]) || !$mapsArray["errorStatus"]) {
231
+            if (!isset($mapsArray["errorStatus"]) || !$mapsArray["errorStatus"]) {
232 232
                 $mapsArray["errorStatus"] = $maps->getErrorStatus();
233 233
                 $mapsArray["errorMessage"] = $maps->getErrorMessage();
234 234
             }
235 235
         }
236 236
 
237
-        if(isset($mapsArray["errorStatus"]) && $mapsArray["errorStatus"])
238
-            $result->setErrorStatus( $mapsArray["errorStatus"])->setErrorMessage( $mapsArray["errorMessage"]);
237
+        if (isset($mapsArray["errorStatus"]) && $mapsArray["errorStatus"])
238
+            $result->setErrorStatus($mapsArray["errorStatus"])->setErrorMessage($mapsArray["errorMessage"]);
239 239
 
240 240
         unset($mapsArray["errorStatus"]);
241 241
         unset($mapsArray["errorMessage"]);
@@ -257,20 +257,20 @@  discard block
 block discarded – undo
257 257
         $callNumber = 0;
258 258
 
259 259
         // Latest
260
-        if($numberOfPage === 0 && $startPage === 0){
260
+        if ($numberOfPage === 0 && $startPage === 0) {
261 261
             $apiResult = json_decode($this->callAPI(str_ireplace("page", 0, $endpoint)));
262 262
 
263
-            if($apiResult === false || $apiResult == "Not Found") {
263
+            if ($apiResult === false || $apiResult == "Not Found") {
264 264
                 $response->setErrorStatus(true)->setErrorMessage("[getMaps] Something went wrong with the API call while calling the first page.");
265 265
                 return $response;
266
-            } else{
266
+            } else {
267 267
                 foreach ($apiResult->docs as $beatmap) {
268 268
                     $maps[] = new BeatMap($beatmap);
269 269
                 }
270 270
             }
271 271
         } else {
272
-            for($i = $startPage; $i < ($startPage + $numberOfPage); $i++){
273
-                if($callNumber === self::MAX_CALL_PER_SECS) {
272
+            for ($i = $startPage; $i < ($startPage + $numberOfPage); $i++) {
273
+                if ($callNumber === self::MAX_CALL_PER_SECS) {
274 274
                     sleep(1);
275 275
                     $callNumber = 0;
276 276
                 }
@@ -278,10 +278,10 @@  discard block
 block discarded – undo
278 278
                 $apiResult = json_decode($this->callAPI(str_ireplace("page", $i, $endpoint)));
279 279
                 $callNumber++;
280 280
 
281
-                if($apiResult === false || $apiResult == "Not Found") {
281
+                if ($apiResult === false || $apiResult == "Not Found") {
282 282
                     $response->setErrorStatus(true)->setErrorMessage("[getMaps] Something went wrong with the API call while calling page number " . $i . ".");
283 283
 
284
-                    if($apiResult == "Not Found")
284
+                    if ($apiResult == "Not Found")
285 285
                         return $response;
286 286
                 }
287 287
 
@@ -363,23 +363,23 @@  discard block
 block discarded – undo
363 363
 
364 364
         $endpoint = "/search/text/page?sortOrder=" . $sort[$sortOrder];
365 365
 
366
-        if($mapName)                $endpoint .= "&q=" . urlencode($mapName);
367
-        if($startDate)              $endpoint .= "&from=" . $startDate->format("Y-m-d");
368
-        if($endDate)                $endpoint .= "&to=" . $endDate->format("Y-m-d");
369
-        if($ranked)                 $endpoint .= "&ranked=" . /** @scrutinizer ignore-type */ var_export($ranked, true);
370
-        if($automapper)             $endpoint .= "&automapper=" . /** @scrutinizer ignore-type */ var_export($automapper, true);
371
-        if($chroma)                 $endpoint .= "&chroma=" . /** @scrutinizer ignore-type */ var_export($chroma, true);
372
-        if($noodle)                 $endpoint .= "&noodle=" . /** @scrutinizer ignore-type */ var_export($noodle, true);
373
-        if($cinema)                 $endpoint .= "&cinema=" . /** @scrutinizer ignore-type */ var_export($cinema, true);
374
-        if($fullSpread)             $endpoint .= "&fullSpread=" . /** @scrutinizer ignore-type */ var_export($fullSpread, true);
375
-        if($minBpm)                 $endpoint .= "&minBpm=" . /** @scrutinizer ignore-type */ $minBpm;
376
-        if($maxBpm)                 $endpoint .= "&maxBpm=" . /** @scrutinizer ignore-type */ $maxBpm;
377
-        if($minNps)                 $endpoint .= "&minNps=" . /** @scrutinizer ignore-type */ $minNps;
378
-        if($maxNps)                 $endpoint .= "&maxNps=" . /** @scrutinizer ignore-type */ $maxNps;
379
-        if($minRating)              $endpoint .= "&minRating=" . /** @scrutinizer ignore-type */ $minRating;
380
-        if($maxRating)              $endpoint .= "&maxRating=" . /** @scrutinizer ignore-type */ $maxRating;
381
-        if($minDuration !== null)   $endpoint .= "&minDuration=" . /** @scrutinizer ignore-type */ $minDuration;
382
-        if($maxDuration !== null)   $endpoint .= "&maxDuration=" . /** @scrutinizer ignore-type */ $maxDuration;
366
+        if ($mapName)                $endpoint .= "&q=" . urlencode($mapName);
367
+        if ($startDate)              $endpoint .= "&from=" . $startDate->format("Y-m-d");
368
+        if ($endDate)                $endpoint .= "&to=" . $endDate->format("Y-m-d");
369
+        if ($ranked)                 $endpoint .= "&ranked=" . /** @scrutinizer ignore-type */ var_export($ranked, true);
370
+        if ($automapper)             $endpoint .= "&automapper=" . /** @scrutinizer ignore-type */ var_export($automapper, true);
371
+        if ($chroma)                 $endpoint .= "&chroma=" . /** @scrutinizer ignore-type */ var_export($chroma, true);
372
+        if ($noodle)                 $endpoint .= "&noodle=" . /** @scrutinizer ignore-type */ var_export($noodle, true);
373
+        if ($cinema)                 $endpoint .= "&cinema=" . /** @scrutinizer ignore-type */ var_export($cinema, true);
374
+        if ($fullSpread)             $endpoint .= "&fullSpread=" . /** @scrutinizer ignore-type */ var_export($fullSpread, true);
375
+        if ($minBpm)                 $endpoint .= "&minBpm=" . /** @scrutinizer ignore-type */ $minBpm;
376
+        if ($maxBpm)                 $endpoint .= "&maxBpm=" . /** @scrutinizer ignore-type */ $maxBpm;
377
+        if ($minNps)                 $endpoint .= "&minNps=" . /** @scrutinizer ignore-type */ $minNps;
378
+        if ($maxNps)                 $endpoint .= "&maxNps=" . /** @scrutinizer ignore-type */ $maxNps;
379
+        if ($minRating)              $endpoint .= "&minRating=" . /** @scrutinizer ignore-type */ $minRating;
380
+        if ($maxRating)              $endpoint .= "&maxRating=" . /** @scrutinizer ignore-type */ $maxRating;
381
+        if ($minDuration !== null)   $endpoint .= "&minDuration=" . /** @scrutinizer ignore-type */ $minDuration;
382
+        if ($maxDuration !== null)   $endpoint .= "&maxDuration=" . /** @scrutinizer ignore-type */ $maxDuration;
383 383
 
384 384
         return $this->getMapsByEndpoint($endpoint, $numberOfPage, $startPage);
385 385
     }
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
 
400 400
         $apiResult = $this->callAPI($endpoint);
401 401
 
402
-        if($apiResult === false || $apiResult == "Not Found") {
402
+        if ($apiResult === false || $apiResult == "Not Found") {
403 403
             $response->setErrorStatus(true)->setErrorMessage("[getMap] Something went wrong with the API call.");
404 404
             return $response;
405 405
         }
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
             mkdir($targetDir, 0777, true);
432 432
         }
433 433
 
434
-        if(substr($targetDir, -1) !== "/")
434
+        if (substr($targetDir, -1) !== "/")
435 435
             $targetDir .= "/";
436 436
 
437 437
         foreach ($hashes as $hash) {
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
 
453 453
             $result = curl_exec($ch);
454 454
 
455
-            if(curl_errno($ch) === 0) {
455
+            if (curl_errno($ch) === 0) {
456 456
                 $response->pushDownloadMapHash($hash);
457 457
                 echo "Ok ";
458 458
             } else {
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
 
476 476
             $result = curl_exec($ch);
477 477
 
478
-            if(curl_errno($ch) === 0) {
478
+            if (curl_errno($ch) === 0) {
479 479
                 $response->pushDownloadMapHash($hash);
480 480
                 echo "Ok ";
481 481
             } else {
Please login to merge, or discard this patch.