Passed
Push — master ( a94c99...9034c4 )
by Kris
02:06
created
lib/ApiHandler.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
      */
157 157
     public function report(string $ip = '', string $categories = '', string $message = '', bool $returnArray = false)
158 158
     {
159
-         // ip must be set
159
+            // ip must be set
160 160
         if (empty($ip)){
161 161
             throw new \InvalidArgumentException('Ip was empty');
162 162
         }
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
         }
168 168
 
169 169
         // message must be set
170
-          if (empty($message)){
170
+            if (empty($message)){
171 171
             throw new \InvalidArgumentException('report message was empty');
172 172
         }
173 173
 
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 
281 281
         // option
282 282
         if ($verbose){
283
-           $data['verbose'] = true;
283
+            $data['verbose'] = true;
284 284
         }
285 285
 
286 286
         // check AbuseIPDB request
@@ -367,14 +367,14 @@  discard block
 block discarded – undo
367 367
             'Key: ' . $this->aipdbApiKey,
368 368
         ]);
369 369
   
370
-      // execute curl call
371
-      $result = curl_exec($ch);
370
+        // execute curl call
371
+        $result = curl_exec($ch);
372 372
   
373
-      // close connection
374
-      curl_close($ch);
373
+        // close connection
374
+        curl_close($ch);
375 375
   
376
-      // return response as JSON data
377
-      return $result;
376
+        // return response as JSON data
377
+        return $result;
378 378
     }
379 379
 
380 380
     /** 
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
      * @access public
386 386
      * @param string      $message           The original message 
387 387
      *  
388
-	 * @return string
388
+     * @return string
389 389
      */
390 390
     protected function cleanMessage(string $message)
391 391
     {
@@ -410,10 +410,10 @@  discard block
 block discarded – undo
410 410
      *
411 411
      * @access public
412 412
      * @static
413
-	 * @param string    $filePath       The file's full path
414
-	 * @param bool      $trowError      Throw error on true or silent process. Default is true
413
+     * @param string    $filePath       The file's full path
414
+     * @param bool      $trowError      Throw error on true or silent process. Default is true
415 415
      *  
416
-	 * @return object|null 
416
+     * @return object|null 
417 417
      * @throws \Exception
418 418
      * @throws \LogicException
419 419
      */
@@ -421,10 +421,10 @@  discard block
 block discarded – undo
421 421
     {
422 422
         // check file exists
423 423
         if (!file_exists($filePath) || !is_file($filePath)){
424
-           if ($throwError) {
424
+            if ($throwError) {
425 425
                 throw new \Exception('Config file not found');
426
-           }
427
-           return null;  
426
+            }
427
+            return null;  
428 428
         }
429 429
 
430 430
         // get and parse content
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
      * @access protected
51 51
      * @var array $selfIps  
52 52
      */
53
-    protected $selfIps = []; 
53
+    protected $selfIps = [ ]; 
54 54
 
55 55
     /**
56 56
      * Constructor
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
      * @param array   $myIps      The Ips/domain name you dont want to display in report messages
62 62
      * 
63 63
      */
64
-    public function __construct(string $apiKey, string $userId, array $myIps = [])
64
+    public function __construct(string $apiKey, string $userId, array $myIps = [ ])
65 65
     {
66 66
         $this->aipdbApiKey = $apiKey;
67 67
         $this->aipdbUserId = $userId;
@@ -100,21 +100,21 @@  discard block
 block discarded – undo
100 100
     {
101 101
 
102 102
         // check file exists
103
-        if (!file_exists($configPath) || !is_file($configPath)){
103
+        if (!file_exists($configPath) || !is_file($configPath)) {
104 104
             throw new \InvalidArgumentException('The file [' . $configPath . '] does not exist.');
105 105
         }
106 106
 
107 107
         // check file is readable
108
-        if (!is_readable($configPath)){
108
+        if (!is_readable($configPath)) {
109 109
             throw new InvalidPermissionException('The file [' . $configPath . '] is not readable.');
110 110
         }
111 111
 
112 112
         $keyConfig = self::loadJsonFile($configPath);
113
-        $selfIps = [];
113
+        $selfIps = [ ];
114 114
         
115 115
         // Look for other optional config files in the same directory 
116 116
         $selfIpsConfigPath = pathinfo($configPath, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR . 'self_ips.json';
117
-        if (file_exists($selfIpsConfigPath)){
117
+        if (file_exists($selfIpsConfigPath)) {
118 118
             $selfIps = self::loadJsonFile($selfIpsConfigPath)->self_ips;
119 119
         }
120 120
 
@@ -157,17 +157,17 @@  discard block
 block discarded – undo
157 157
     public function report(string $ip = '', string $categories = '', string $message = '', bool $returnArray = false)
158 158
     {
159 159
          // ip must be set
160
-        if (empty($ip)){
160
+        if (empty($ip)) {
161 161
             throw new \InvalidArgumentException('Ip was empty');
162 162
         }
163 163
 
164 164
         // categories must be set
165
-        if (empty($categories)){
165
+        if (empty($categories)) {
166 166
             throw new \InvalidArgumentException('categories list was empty');
167 167
         }
168 168
 
169 169
         // message must be set
170
-          if (empty($message)){
170
+          if (empty($message)) {
171 171
             throw new \InvalidArgumentException('report message was empty');
172 172
         }
173 173
 
@@ -212,21 +212,21 @@  discard block
 block discarded – undo
212 212
         foreach ($cats as $cat) {
213 213
 
214 214
             // get index on our array of categories
215
-            $catIndex    = is_numeric($cat) ? $this->getCategoryIndex($cat, 1) : $this->getCategoryIndex($cat, 0);
215
+            $catIndex = is_numeric($cat) ? $this->getCategoryIndex($cat, 1) : $this->getCategoryIndex($cat, 0);
216 216
 
217 217
             // check if found
218
-            if ($catIndex === false ){
219
-                throw new \InvalidArgumentException('Invalid report category was given : ['. $cat .  ']');
218
+            if ($catIndex === false) {
219
+                throw new \InvalidArgumentException('Invalid report category was given : [' . $cat . ']');
220 220
             }
221 221
 
222 222
             // get Id
223
-            $catId = $this->aipdbApiCategories[$catIndex][1];
223
+            $catId = $this->aipdbApiCategories[ $catIndex ][ 1 ];
224 224
 
225 225
             // need another ?
226
-            if ($needAnother !== false){
226
+            if ($needAnother !== false) {
227 227
 
228 228
                 // is a standalone cat ?
229
-                if ($this->aipdbApiCategories[$catIndex][3] === false) {
229
+                if ($this->aipdbApiCategories[ $catIndex ][ 3 ] === false) {
230 230
                     $needAnother = true;
231 231
 
232 232
                 } else {
@@ -237,10 +237,10 @@  discard block
 block discarded – undo
237 237
             }
238 238
 
239 239
             // set or add to cats list 
240
-            $catsString = ($catsString === '') ? $catId : $catsString .','.$catId;
240
+            $catsString = ($catsString === '') ? $catId : $catsString . ',' . $catId;
241 241
         }
242 242
 
243
-        if ($needAnother !== false){
243
+        if ($needAnother !== false) {
244 244
             throw new \InvalidArgumentException('Invalid report category paremeter given: some categories can\'t be used alone');
245 245
         }
246 246
 
@@ -263,12 +263,12 @@  discard block
 block discarded – undo
263 263
     public function check(string $ip = null, int $maxAge = 30, bool $verbose = false, bool $returnArray = false)
264 264
     {
265 265
         // max age must be less or equal to 365
266
-        if ($maxAge > 365 || $maxAge < 1){
266
+        if ($maxAge > 365 || $maxAge < 1) {
267 267
             throw new \InvalidArgumentException('maxAge must be at least 1 and less than 365 (' . $maxAge . ' was given)');
268 268
         }
269 269
 
270 270
         // ip must be set
271
-        if (empty($ip)){
271
+        if (empty($ip)) {
272 272
             throw new \InvalidArgumentException('ip argument must be set (null given)');
273 273
         }
274 274
 
@@ -279,12 +279,12 @@  discard block
 block discarded – undo
279 279
         ];
280 280
 
281 281
         // option
282
-        if ($verbose){
283
-           $data['verbose'] = true;
282
+        if ($verbose) {
283
+           $data[ 'verbose' ] = true;
284 284
         }
285 285
 
286 286
         // check AbuseIPDB request
287
-        $response = $this->apiRequest('check', $data, 'GET', $returnArray) ;
287
+        $response = $this->apiRequest('check', $data, 'GET', $returnArray);
288 288
 
289 289
         return json_decode($response, $returnArray);
290 290
     }
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
     public function getBlacklist(int $limit = 10000, bool $plainText = false, bool $returnArray = false)
305 305
     {
306 306
 
307
-        if ($limit < 1){
307
+        if ($limit < 1) {
308 308
             throw new \InvalidArgumentException('limit must be at least 1 (' . $limit . ' was given)');
309 309
         }
310 310
 
@@ -316,13 +316,13 @@  discard block
 block discarded – undo
316 316
 
317 317
         // plaintext paremeter has no value and must be added only when true 
318 318
         // (set plaintext=false won't work)
319
-        if ($plainText){
320
-            $data['plaintext'] = $plainText;
319
+        if ($plainText) {
320
+            $data[ 'plaintext' ] = $plainText;
321 321
         }
322 322
 
323 323
         $response = $this->apiRequest('blacklist', $data, 'GET');
324 324
 
325
-        if ($plainText){
325
+        if ($plainText) {
326 326
             return $response;
327 327
         } 
328 328
        
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
         $message = str_replace('\\', '', $message);
394 394
 
395 395
         // Remove self ips
396
-        foreach ($this->selfIps as $ip){
396
+        foreach ($this->selfIps as $ip) {
397 397
             $message = str_replace($ip, '*', $message);
398 398
         }
399 399
 
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
     protected static function loadJsonFile(string $filePath, bool $throwError = true)
421 421
     {
422 422
         // check file exists
423
-        if (!file_exists($filePath) || !is_file($filePath)){
423
+        if (!file_exists($filePath) || !is_file($filePath)) {
424 424
            if ($throwError) {
425 425
                 throw new \Exception('Config file not found');
426 426
            }
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
         $json    = json_decode(utf8_encode($content));
433 433
 
434 434
         // check for errors
435
-        if ($json == null && json_last_error() != JSON_ERROR_NONE){
435
+        if ($json == null && json_last_error() != JSON_ERROR_NONE) {
436 436
             if ($throwError) {
437 437
                 throw new \LogicException(sprintf("Failed to parse config file Error: '%s'", json_last_error_msg()));
438 438
             }
Please login to merge, or discard this patch.
lib/ApiDefintion.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
         // Open proxy, open relay, or Tor exit node.
71 71
         ['openproxy'       , '9', 'Open Proxy', true],        
72 72
 
73
-         // Comment/forum spam, HTTP referer spam, or other CMS spam.
74
-         ['webspam'         , '10', 'Web Spam', true],        
73
+            // Comment/forum spam, HTTP referer spam, or other CMS spam.
74
+            ['webspam'         , '10', 'Web Spam', true],        
75 75
 
76 76
         // Spam email content, infected attachments, and phishing emails. Note: Limit comments to only relevent
77 77
         // information (instead of log dumps) and be sure to remove PII if you want to remain anonymous.
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
         // Abuse was targeted at an "Internet of Things" type device. Include 
121 121
         // information about what type of device was targeted in the comments.         
122 122
         ['oit'             , '23', 'IoT Targeted', true],     
123
-      ];
123
+        ];
124 124
 
125 125
     /**
126 126
      * Get the category id corresponding to given name
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
             if ($cat[0] === $categoryName) {
137 137
                 return $cat;
138 138
             }
139
-         }
139
+            }
140 140
 
141 141
         // not found
142 142
         return false;
@@ -153,9 +153,9 @@  discard block
 block discarded – undo
153 153
     public function getCategoryNameById(string $categoryId)
154 154
     {
155 155
         foreach ($this->aipdbApiCategories as $cat){
156
-           if ($cat[1] === $categoryId) {
157
-               return $cat;
158
-           }
156
+            if ($cat[1] === $categoryId) {
157
+                return $cat;
158
+            }
159 159
         }
160 160
 
161 161
         // not found
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
                 return $i;
180 180
             }
181 181
             $i++;
182
-         }
182
+            }
183 183
 
184 184
         // not found
185 185
         return false;
Please login to merge, or discard this patch.