Passed
Push — master ( ec8b1a...0c5029 )
by Kylian
01:50
created
lib/object/beatmap/BeatMap.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -180,7 +180,7 @@
 block discarded – undo
180 180
     {
181 181
         $response = [];
182 182
 
183
-        foreach($this->bm->versions as $version) {
183
+        foreach ($this->bm->versions as $version) {
184 184
             $response[] = new BeatMapVersion($version);
185 185
         }
186 186
 
Please login to merge, or discard this patch.
lib/functions/MultiQuery.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
         $l_Handles  = [];
35 35
         foreach ($p_URLs as $l_URL)
36 36
         {
37
-            $l_CURL = curl_init($this->apiUrl.$apiUrlExt.$l_URL);
37
+            $l_CURL = curl_init($this->apiUrl . $apiUrlExt . $l_URL);
38 38
             curl_setopt($l_CURL, CURLOPT_USERAGENT, $this->userAgent);
39 39
             curl_setopt($l_CURL, CURLOPT_RETURNTRANSFER, true);
40 40
 
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
                     mkdir($targetDir, 0777, true);
88 88
                 }
89 89
 
90
-                if(substr($targetDir, -1) !== "/")
90
+                if (substr($targetDir, -1) !== "/")
91 91
                     $targetDir .= "/";
92 92
 
93 93
                 //The path & filename to save to.
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 
102 102
                 $result = curl_exec($ch);
103 103
 
104
-                if(curl_errno($ch) === 0) {
104
+                if (curl_errno($ch) === 0) {
105 105
                     $response->pushDownloadMapHash($hash);
106 106
                     echo "Ok ";
107 107
                 } else {
Please login to merge, or discard this patch.
Braces   +11 added lines, -8 removed lines patch added patch discarded remove patch
@@ -41,8 +41,9 @@  discard block
 block discarded – undo
41 41
             $l_Handles[] = $l_CURL;
42 42
         }
43 43
 
44
-        foreach ($l_Handles as $l_Current)
45
-            curl_multi_add_handle($l_Multi, $l_Current);
44
+        foreach ($l_Handles as $l_Current) {
45
+                    curl_multi_add_handle($l_Multi, $l_Current);
46
+        }
46 47
 
47 48
         $l_RunningHandles = null;
48 49
 
@@ -57,10 +58,11 @@  discard block
 block discarded – undo
57 58
         {
58 59
             $l_Error = curl_error($l_Current);
59 60
 
60
-            if (!empty($l_Error) || curl_getinfo($l_Current, CURLINFO_HTTP_CODE) !== 200)
61
-                $l_Result[] = false;
62
-            else
63
-                $l_Result[] = new BeatMap(json_decode(curl_multi_getcontent($l_Current)));
61
+            if (!empty($l_Error) || curl_getinfo($l_Current, CURLINFO_HTTP_CODE) !== 200) {
62
+                            $l_Result[] = false;
63
+            } else {
64
+                            $l_Result[] = new BeatMap(json_decode(curl_multi_getcontent($l_Current)));
65
+            }
64 66
 
65 67
             curl_multi_remove_handle($l_Multi, $l_Current);
66 68
         }
@@ -87,8 +89,9 @@  discard block
 block discarded – undo
87 89
                     mkdir($targetDir, 0777, true);
88 90
                 }
89 91
 
90
-                if(substr($targetDir, -1) !== "/")
91
-                    $targetDir .= "/";
92
+                if(substr($targetDir, -1) !== "/") {
93
+                                    $targetDir .= "/";
94
+                }
92 95
 
93 96
                 //The path & filename to save to.
94 97
                 $saveTo = $targetDir . $hash . $extension;
Please login to merge, or discard this patch.
lib/BeatSaverAPI.php 2 patches
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
      */
27 27
     public function __construct(string $userAgent, bool $needAutoloader = false)
28 28
     {
29
-        if($needAutoloader)
29
+        if ($needAutoloader)
30 30
             $this->autoload("./");
31 31
 
32 32
         $this->userAgent = $userAgent;
@@ -34,15 +34,15 @@  discard block
 block discarded – undo
34 34
     }
35 35
 
36 36
     private function autoload($directory) {
37
-        if(is_dir($directory)) {
37
+        if (is_dir($directory)) {
38 38
             $scan = scandir($directory);
39 39
             unset($scan[0], $scan[1]); //unset . and ..
40
-            foreach($scan as $file) {
41
-                if(is_dir($directory."/".$file)) {
42
-                    $this->autoload($directory."/".$file);
40
+            foreach ($scan as $file) {
41
+                if (is_dir($directory . "/" . $file)) {
42
+                    $this->autoload($directory . "/" . $file);
43 43
                 } else {
44
-                    if(strpos($file, '.php') !== false) {
45
-                        include_once($directory."/".$file);
44
+                    if (strpos($file, '.php') !== false) {
45
+                        include_once($directory . "/" . $file);
46 46
                     }
47 47
                 }
48 48
             }
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 
87 87
         $apiResult = $this->callAPI($endpoint);
88 88
 
89
-        if($apiResult === false || $apiResult == "Not Found") {
89
+        if ($apiResult === false || $apiResult == "Not Found") {
90 90
             $response->setErrorStatus(true)->setErrorMessage("[getMap] Something went wrong with the API call.");
91 91
             return $response;
92 92
         }
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 
146 146
         $apiResult = $this->callAPI($endpoint);
147 147
 
148
-        if($apiResult === false || $apiResult == "Not Found") {
148
+        if ($apiResult === false || $apiResult == "Not Found") {
149 149
             $response->setErrorStatus(true)->setErrorMessage("[getMap] Something went wrong with the API call.");
150 150
             return $response;
151 151
         }
@@ -191,15 +191,15 @@  discard block
 block discarded – undo
191 191
         $callNumber = 0;
192 192
         $result = new ResponseMaps();
193 193
 
194
-        if(count($hashes) < 2) {
194
+        if (count($hashes) < 2) {
195 195
             return $result->setErrorStatus(true)->setErrorMessage("This functions require a minimum of 2 hashes in the array");
196 196
         }
197 197
 
198
-        foreach($hashes as $hash) {
198
+        foreach ($hashes as $hash) {
199 199
             $hashesString .= $hash;
200 200
 
201
-            if($i !== 0 && $i % self::MAX_HASHES_NUMBER === 0) {
202
-                if($callNumber === self::MAX_CALL_PER_SECS) {
201
+            if ($i !== 0 && $i % self::MAX_HASHES_NUMBER === 0) {
202
+                if ($callNumber === self::MAX_CALL_PER_SECS) {
203 203
                     sleep(1);
204 204
                     $callNumber = 0;
205 205
                 }
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 
210 210
                 $mapsArray[] = array_merge($mapsArray, $maps->getBeatMaps());
211 211
 
212
-                if(!isset($mapsArray["errorStatus"]) || !$mapsArray["errorStatus"]) {
212
+                if (!isset($mapsArray["errorStatus"]) || !$mapsArray["errorStatus"]) {
213 213
                     $mapsArray["errorStatus"] = $maps->getErrorStatus();
214 214
                     $mapsArray["errorMessage"] = $maps->getErrorMessage();
215 215
                 }
@@ -223,18 +223,18 @@  discard block
 block discarded – undo
223 223
         }
224 224
 
225 225
 
226
-        if($i !== 0) {
226
+        if ($i !== 0) {
227 227
             $maps = $this->getMaps($hashesString);
228 228
             $mapsArray[] = array_merge($mapsArray, $maps->getBeatMaps());
229 229
 
230
-            if(!isset($mapsArray["errorStatus"]) || !$mapsArray["errorStatus"]) {
230
+            if (!isset($mapsArray["errorStatus"]) || !$mapsArray["errorStatus"]) {
231 231
                 $mapsArray["errorStatus"] = $maps->getErrorStatus();
232 232
                 $mapsArray["errorMessage"] = $maps->getErrorMessage();
233 233
             }
234 234
         }
235 235
 
236
-        if(isset($mapsArray["errorStatus"]) && $mapsArray["errorStatus"])
237
-            $result->setErrorStatus( $mapsArray["errorStatus"])->setErrorMessage( $mapsArray["errorMessage"]);
236
+        if (isset($mapsArray["errorStatus"]) && $mapsArray["errorStatus"])
237
+            $result->setErrorStatus($mapsArray["errorStatus"])->setErrorMessage($mapsArray["errorMessage"]);
238 238
 
239 239
         unset($mapsArray["errorStatus"]);
240 240
         unset($mapsArray["errorMessage"]);
@@ -256,20 +256,20 @@  discard block
 block discarded – undo
256 256
         $callNumber = 0;
257 257
 
258 258
         // Latest
259
-        if($numberOfPage === 0 && $startPage === 0){
259
+        if ($numberOfPage === 0 && $startPage === 0) {
260 260
             $apiResult = json_decode($this->callAPI(str_ireplace("page", 0, $endpoint)));
261 261
 
262
-            if($apiResult === false || $apiResult == "Not Found") {
262
+            if ($apiResult === false || $apiResult == "Not Found") {
263 263
                 $response->setErrorStatus(true)->setErrorMessage("[getMaps] Something went wrong with the API call while calling the first page.");
264 264
                 return $response;
265
-            } else{
265
+            } else {
266 266
                 foreach ($apiResult->docs as $beatmap) {
267 267
                     $maps[] = new BeatMap($beatmap);
268 268
                 }
269 269
             }
270 270
         } else {
271
-            for($i = $startPage; $i < ($i + $numberOfPage); $i++){
272
-                if($callNumber === self::MAX_CALL_PER_SECS) {
271
+            for ($i = $startPage; $i < ($i + $numberOfPage); $i++) {
272
+                if ($callNumber === self::MAX_CALL_PER_SECS) {
273 273
                     sleep(1);
274 274
                     $callNumber = 0;
275 275
                 }
@@ -277,10 +277,10 @@  discard block
 block discarded – undo
277 277
                 $apiResult = json_decode($this->callAPI(str_ireplace("page", $i, $endpoint)));
278 278
                 $callNumber++;
279 279
 
280
-                if($apiResult === false || $apiResult == "Not Found") {
280
+                if ($apiResult === false || $apiResult == "Not Found") {
281 281
                     $response->setErrorStatus(true)->setErrorMessage("[getMaps] Something went wrong with the API call while calling page number " . $i . ".");
282 282
 
283
-                    if($apiResult == "Not Found")
283
+                    if ($apiResult == "Not Found")
284 284
                         return $response;
285 285
                 }
286 286
 
@@ -362,23 +362,23 @@  discard block
 block discarded – undo
362 362
 
363 363
         $endpoint = "/search/text/page?sortOrder=" . $sort[$sortOrder];
364 364
 
365
-        if($mapName)                $endpoint .= "&q=" . urlencode($mapName);
366
-        if($startDate)              $endpoint .= "&from=" . $startDate->format("Y-m-d");
367
-        if($endDate)                $endpoint .= "&to=" . $endDate->format("Y-m-d");
368
-        if($ranked)                 $endpoint .= "&ranked=" . /** @scrutinizer ignore-type */ var_export($ranked, true);
369
-        if($automapper)             $endpoint .= "&automapper=" . /** @scrutinizer ignore-type */ var_export($automapper, true);
370
-        if($chroma)                 $endpoint .= "&chroma=" . /** @scrutinizer ignore-type */ var_export($chroma, true);
371
-        if($noodle)                 $endpoint .= "&noodle=" . /** @scrutinizer ignore-type */ var_export($noodle, true);
372
-        if($cinema)                 $endpoint .= "&cinema=" . /** @scrutinizer ignore-type */ var_export($cinema, true);
373
-        if($fullSpread)             $endpoint .= "&fullSpread=" . /** @scrutinizer ignore-type */ var_export($fullSpread, true);
374
-        if($minBpm)                 $endpoint .= "&minBpm=" . /** @scrutinizer ignore-type */ $minBpm;
375
-        if($maxBpm)                 $endpoint .= "&maxBpm=" . /** @scrutinizer ignore-type */ $maxBpm;
376
-        if($minNps)                 $endpoint .= "&minNps=" . /** @scrutinizer ignore-type */ $minNps;
377
-        if($maxNps)                 $endpoint .= "&maxNps=" . /** @scrutinizer ignore-type */ $maxNps;
378
-        if($minRating)              $endpoint .= "&minRating=" . /** @scrutinizer ignore-type */ $minRating;
379
-        if($maxRating)              $endpoint .= "&maxRating=" . /** @scrutinizer ignore-type */ $maxRating;
380
-        if($minDuration !== null)   $endpoint .= "&minDuration=" . /** @scrutinizer ignore-type */ $minDuration;
381
-        if($maxDuration !== null)   $endpoint .= "&maxDuration=" . /** @scrutinizer ignore-type */ $maxDuration;
365
+        if ($mapName)                $endpoint .= "&q=" . urlencode($mapName);
366
+        if ($startDate)              $endpoint .= "&from=" . $startDate->format("Y-m-d");
367
+        if ($endDate)                $endpoint .= "&to=" . $endDate->format("Y-m-d");
368
+        if ($ranked)                 $endpoint .= "&ranked=" . /** @scrutinizer ignore-type */ var_export($ranked, true);
369
+        if ($automapper)             $endpoint .= "&automapper=" . /** @scrutinizer ignore-type */ var_export($automapper, true);
370
+        if ($chroma)                 $endpoint .= "&chroma=" . /** @scrutinizer ignore-type */ var_export($chroma, true);
371
+        if ($noodle)                 $endpoint .= "&noodle=" . /** @scrutinizer ignore-type */ var_export($noodle, true);
372
+        if ($cinema)                 $endpoint .= "&cinema=" . /** @scrutinizer ignore-type */ var_export($cinema, true);
373
+        if ($fullSpread)             $endpoint .= "&fullSpread=" . /** @scrutinizer ignore-type */ var_export($fullSpread, true);
374
+        if ($minBpm)                 $endpoint .= "&minBpm=" . /** @scrutinizer ignore-type */ $minBpm;
375
+        if ($maxBpm)                 $endpoint .= "&maxBpm=" . /** @scrutinizer ignore-type */ $maxBpm;
376
+        if ($minNps)                 $endpoint .= "&minNps=" . /** @scrutinizer ignore-type */ $minNps;
377
+        if ($maxNps)                 $endpoint .= "&maxNps=" . /** @scrutinizer ignore-type */ $maxNps;
378
+        if ($minRating)              $endpoint .= "&minRating=" . /** @scrutinizer ignore-type */ $minRating;
379
+        if ($maxRating)              $endpoint .= "&maxRating=" . /** @scrutinizer ignore-type */ $maxRating;
380
+        if ($minDuration !== null)   $endpoint .= "&minDuration=" . /** @scrutinizer ignore-type */ $minDuration;
381
+        if ($maxDuration !== null)   $endpoint .= "&maxDuration=" . /** @scrutinizer ignore-type */ $maxDuration;
382 382
 
383 383
         return $this->getMapsByEndpoint($endpoint, $numberOfPage, $startPage);
384 384
     }
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 
399 399
         $apiResult = $this->callAPI($endpoint);
400 400
 
401
-        if($apiResult === false || $apiResult == "Not Found") {
401
+        if ($apiResult === false || $apiResult == "Not Found") {
402 402
             $response->setErrorStatus(true)->setErrorMessage("[getMap] Something went wrong with the API call.");
403 403
             return $response;
404 404
         }
Please login to merge, or discard this patch.
Braces   +60 added lines, -23 removed lines patch added patch discarded remove patch
@@ -26,8 +26,9 @@  discard block
 block discarded – undo
26 26
      */
27 27
     public function __construct(string $userAgent, bool $needAutoloader = false)
28 28
     {
29
-        if($needAutoloader)
30
-            $this->autoload("./");
29
+        if($needAutoloader) {
30
+                    $this->autoload("./");
31
+        }
31 32
 
32 33
         $this->userAgent = $userAgent;
33 34
         $this->multiQuery = new MultiQuery(self::BEATSAVER_URL, $userAgent);
@@ -233,8 +234,9 @@  discard block
 block discarded – undo
233 234
             }
234 235
         }
235 236
 
236
-        if(isset($mapsArray["errorStatus"]) && $mapsArray["errorStatus"])
237
-            $result->setErrorStatus( $mapsArray["errorStatus"])->setErrorMessage( $mapsArray["errorMessage"]);
237
+        if(isset($mapsArray["errorStatus"]) && $mapsArray["errorStatus"]) {
238
+                    $result->setErrorStatus( $mapsArray["errorStatus"])->setErrorMessage( $mapsArray["errorMessage"]);
239
+        }
238 240
 
239 241
         unset($mapsArray["errorStatus"]);
240 242
         unset($mapsArray["errorMessage"]);
@@ -280,8 +282,9 @@  discard block
 block discarded – undo
280 282
                 if($apiResult === false || $apiResult == "Not Found") {
281 283
                     $response->setErrorStatus(true)->setErrorMessage("[getMaps] Something went wrong with the API call while calling page number " . $i . ".");
282 284
 
283
-                    if($apiResult == "Not Found")
284
-                        return $response;
285
+                    if($apiResult == "Not Found") {
286
+                                            return $response;
287
+                    }
285 288
                 }
286 289
 
287 290
                 foreach ($apiResult->docs as $beatmap) {
@@ -362,23 +365,57 @@  discard block
 block discarded – undo
362 365
 
363 366
         $endpoint = "/search/text/page?sortOrder=" . $sort[$sortOrder];
364 367
 
365
-        if($mapName)                $endpoint .= "&q=" . urlencode($mapName);
366
-        if($startDate)              $endpoint .= "&from=" . $startDate->format("Y-m-d");
367
-        if($endDate)                $endpoint .= "&to=" . $endDate->format("Y-m-d");
368
-        if($ranked)                 $endpoint .= "&ranked=" . /** @scrutinizer ignore-type */ var_export($ranked, true);
369
-        if($automapper)             $endpoint .= "&automapper=" . /** @scrutinizer ignore-type */ var_export($automapper, true);
370
-        if($chroma)                 $endpoint .= "&chroma=" . /** @scrutinizer ignore-type */ var_export($chroma, true);
371
-        if($noodle)                 $endpoint .= "&noodle=" . /** @scrutinizer ignore-type */ var_export($noodle, true);
372
-        if($cinema)                 $endpoint .= "&cinema=" . /** @scrutinizer ignore-type */ var_export($cinema, true);
373
-        if($fullSpread)             $endpoint .= "&fullSpread=" . /** @scrutinizer ignore-type */ var_export($fullSpread, true);
374
-        if($minBpm)                 $endpoint .= "&minBpm=" . /** @scrutinizer ignore-type */ $minBpm;
375
-        if($maxBpm)                 $endpoint .= "&maxBpm=" . /** @scrutinizer ignore-type */ $maxBpm;
376
-        if($minNps)                 $endpoint .= "&minNps=" . /** @scrutinizer ignore-type */ $minNps;
377
-        if($maxNps)                 $endpoint .= "&maxNps=" . /** @scrutinizer ignore-type */ $maxNps;
378
-        if($minRating)              $endpoint .= "&minRating=" . /** @scrutinizer ignore-type */ $minRating;
379
-        if($maxRating)              $endpoint .= "&maxRating=" . /** @scrutinizer ignore-type */ $maxRating;
380
-        if($minDuration !== null)   $endpoint .= "&minDuration=" . /** @scrutinizer ignore-type */ $minDuration;
381
-        if($maxDuration !== null)   $endpoint .= "&maxDuration=" . /** @scrutinizer ignore-type */ $maxDuration;
368
+        if($mapName) {
369
+            $endpoint .= "&q=" . urlencode($mapName);
370
+        }
371
+        if($startDate) {
372
+            $endpoint .= "&from=" . $startDate->format("Y-m-d");
373
+        }
374
+        if($endDate) {
375
+            $endpoint .= "&to=" . $endDate->format("Y-m-d");
376
+        }
377
+        if($ranked) {
378
+            $endpoint .= "&ranked=" . /** @scrutinizer ignore-type */ var_export($ranked, true);
379
+        }
380
+        if($automapper) {
381
+            $endpoint .= "&automapper=" . /** @scrutinizer ignore-type */ var_export($automapper, true);
382
+        }
383
+        if($chroma) {
384
+            $endpoint .= "&chroma=" . /** @scrutinizer ignore-type */ var_export($chroma, true);
385
+        }
386
+        if($noodle) {
387
+            $endpoint .= "&noodle=" . /** @scrutinizer ignore-type */ var_export($noodle, true);
388
+        }
389
+        if($cinema) {
390
+            $endpoint .= "&cinema=" . /** @scrutinizer ignore-type */ var_export($cinema, true);
391
+        }
392
+        if($fullSpread) {
393
+            $endpoint .= "&fullSpread=" . /** @scrutinizer ignore-type */ var_export($fullSpread, true);
394
+        }
395
+        if($minBpm) {
396
+            $endpoint .= "&minBpm=" . /** @scrutinizer ignore-type */ $minBpm;
397
+        }
398
+        if($maxBpm) {
399
+            $endpoint .= "&maxBpm=" . /** @scrutinizer ignore-type */ $maxBpm;
400
+        }
401
+        if($minNps) {
402
+            $endpoint .= "&minNps=" . /** @scrutinizer ignore-type */ $minNps;
403
+        }
404
+        if($maxNps) {
405
+            $endpoint .= "&maxNps=" . /** @scrutinizer ignore-type */ $maxNps;
406
+        }
407
+        if($minRating) {
408
+            $endpoint .= "&minRating=" . /** @scrutinizer ignore-type */ $minRating;
409
+        }
410
+        if($maxRating) {
411
+            $endpoint .= "&maxRating=" . /** @scrutinizer ignore-type */ $maxRating;
412
+        }
413
+        if($minDuration !== null) {
414
+            $endpoint .= "&minDuration=" . /** @scrutinizer ignore-type */ $minDuration;
415
+        }
416
+        if($maxDuration !== null) {
417
+            $endpoint .= "&maxDuration=" . /** @scrutinizer ignore-type */ $maxDuration;
418
+        }
382 419
 
383 420
         return $this->getMapsByEndpoint($endpoint, $numberOfPage, $startPage);
384 421
     }
Please login to merge, or discard this patch.