Passed
Branch master (1e7e1e)
by Kris
01:37
created
lib/ApiHandler.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
      */
134 134
     public function report(string $ip = '', string $categories = '', string $message = '', bool $returnArray = false)
135 135
     {
136
-         // ip must be set
136
+            // ip must be set
137 137
         if (empty($ip)){
138 138
             throw new \InvalidArgumentException('Ip was empty');
139 139
         }
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
         }
145 145
 
146 146
         // message must be set
147
-          if (empty($message)){
147
+            if (empty($message)){
148 148
             throw new \InvalidArgumentException('report message was empty');
149 149
         }
150 150
 
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 
286 286
         // option
287 287
         if ($verbose){
288
-           $data['verbose'] = true;
288
+            $data['verbose'] = true;
289 289
         }
290 290
 
291 291
         $response = $this->apiRequest('check', $data, 'GET') ;
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
      * @access public
467 467
      * @param string      $message           The original message 
468 468
      *  
469
-	 * @return string
469
+     * @return string
470 470
      */
471 471
     protected function cleanMessage(string $message)
472 472
     {
@@ -491,10 +491,10 @@  discard block
 block discarded – undo
491 491
      *
492 492
      * @access public
493 493
      * @static
494
-	 * @param string    $filePath       The file's full path
495
-	 * @param bool      $throwError     Throw error on true or silent process. Default is true
494
+     * @param string    $filePath       The file's full path
495
+     * @param bool      $throwError     Throw error on true or silent process. Default is true
496 496
      *  
497
-	 * @return object|null 
497
+     * @return object|null 
498 498
      * @throws \Exception
499 499
      * @throws \LogicException
500 500
      */
@@ -502,10 +502,10 @@  discard block
 block discarded – undo
502 502
     {
503 503
         // check file exists
504 504
         if (!file_exists($filePath) || !is_file($filePath)){
505
-           if ($throwError) {
505
+            if ($throwError) {
506 506
                 throw new \Exception('Config file not found');
507
-           }
508
-           return null;  
507
+            }
508
+            return null;  
509 509
         }
510 510
 
511 511
         // get and parse content
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      * @access protected
40 40
      * @var array $selfIps  
41 41
      */
42
-    protected $selfIps = []; 
42
+    protected $selfIps = [ ]; 
43 43
 
44 44
     /**
45 45
      * Constructor
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
      * @param array   $myIps      The Ips/domain name you dont want to display in report messages
51 51
      * 
52 52
      */
53
-    public function __construct(string $apiKey, string $userId, array $myIps = [])
53
+    public function __construct(string $apiKey, string $userId, array $myIps = [ ])
54 54
     {
55 55
         $this->aipdbApiKey = $apiKey;
56 56
         $this->aipdbUserId = $userId;
@@ -88,21 +88,21 @@  discard block
 block discarded – undo
88 88
     {
89 89
 
90 90
         // check file exists
91
-        if (!file_exists($configPath) || !is_file($configPath)){
91
+        if (!file_exists($configPath) || !is_file($configPath)) {
92 92
             throw new \InvalidArgumentException('The file [' . $configPath . '] does not exist.');
93 93
         }
94 94
 
95 95
         // check file is readable
96
-        if (!is_readable($configPath)){
96
+        if (!is_readable($configPath)) {
97 97
             throw new InvalidPermissionException('The file [' . $configPath . '] is not readable.');
98 98
         }
99 99
 
100 100
         $keyConfig = self::loadJsonFile($configPath);
101
-        $selfIps = [];
101
+        $selfIps = [ ];
102 102
         
103 103
         // Look for other optional config files in the same directory 
104 104
         $selfIpsConfigPath = pathinfo($configPath, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR . 'self_ips.json';
105
-        if (file_exists($selfIpsConfigPath)){
105
+        if (file_exists($selfIpsConfigPath)) {
106 106
             $selfIps = self::loadJsonFile($selfIpsConfigPath)->self_ips;
107 107
         }
108 108
 
@@ -134,17 +134,17 @@  discard block
 block discarded – undo
134 134
     public function report(string $ip = '', string $categories = '', string $message = '', bool $returnArray = false)
135 135
     {
136 136
          // ip must be set
137
-        if (empty($ip)){
137
+        if (empty($ip)) {
138 138
             throw new \InvalidArgumentException('Ip was empty');
139 139
         }
140 140
 
141 141
         // categories must be set
142
-        if (empty($categories)){
142
+        if (empty($categories)) {
143 143
             throw new \InvalidArgumentException('categories list was empty');
144 144
         }
145 145
 
146 146
         // message must be set
147
-          if (empty($message)){
147
+          if (empty($message)) {
148 148
             throw new \InvalidArgumentException('report message was empty');
149 149
         }
150 150
 
@@ -204,17 +204,17 @@  discard block
 block discarded – undo
204 204
     public function bulkReport(string $filePath, bool $returnArray = false)
205 205
     {
206 206
         // check file exists
207
-        if (!file_exists($filePath) || !is_file($filePath)){
207
+        if (!file_exists($filePath) || !is_file($filePath)) {
208 208
             throw new \InvalidArgumentException('The file [' . $filePath . '] does not exist.');
209 209
         }
210 210
 
211 211
         // check file is readable
212
-        if (!is_readable($filePath)){
212
+        if (!is_readable($filePath)) {
213 213
             throw new InvalidPermissionException('The file [' . $filePath . '] is not readable.');
214 214
         }
215 215
 
216 216
         // AbuseIPDB request
217
-        $response = $this->apiRequest('bulk-report', [], 'POST', $filePath);
217
+        $response = $this->apiRequest('bulk-report', [ ], 'POST', $filePath);
218 218
 
219 219
         return json_decode($response, $returnArray);
220 220
     }
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
     public function clear(string $ip = null, bool $returnArray = false)
241 241
     {
242 242
         // ip must be set
243
-        if (empty($ip)){
243
+        if (empty($ip)) {
244 244
             throw new \InvalidArgumentException('ip argument must be set (null given)');
245 245
         }
246 246
 
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
             'ipAddress'     => $ip, 
250 250
         ];
251 251
 
252
-        $response = $this->apiRequest('clear-address', $data, "DELETE") ;
252
+        $response = $this->apiRequest('clear-address', $data, "DELETE");
253 253
         return json_decode($response, $returnArray);
254 254
     }
255 255
 
@@ -268,12 +268,12 @@  discard block
 block discarded – undo
268 268
     public function check(string $ip = null, int $maxAge = 30, bool $verbose = false, bool $returnArray = false)
269 269
     {
270 270
         // max age must be less or equal to 365
271
-        if ($maxAge > 365 || $maxAge < 1){
271
+        if ($maxAge > 365 || $maxAge < 1) {
272 272
             throw new \InvalidArgumentException('maxAge must be at least 1 and less than 365 (' . $maxAge . ' was given)');
273 273
         }
274 274
 
275 275
         // ip must be set
276
-        if (empty($ip)){
276
+        if (empty($ip)) {
277 277
             throw new \InvalidArgumentException('ip argument must be set (null given)');
278 278
         }
279 279
 
@@ -284,11 +284,11 @@  discard block
 block discarded – undo
284 284
         ];
285 285
 
286 286
         // option
287
-        if ($verbose){
288
-           $data['verbose'] = true;
287
+        if ($verbose) {
288
+           $data[ 'verbose' ] = true;
289 289
         }
290 290
 
291
-        $response = $this->apiRequest('check', $data, 'GET') ;
291
+        $response = $this->apiRequest('check', $data, 'GET');
292 292
 
293 293
         return json_decode($response, $returnArray);
294 294
     }
@@ -339,12 +339,12 @@  discard block
 block discarded – undo
339 339
     public function checkBlock(string $network = null, int $maxAge = 30, bool $returnArray = false)
340 340
     {
341 341
         // max age must be less or equal to 365
342
-        if ($maxAge > 365 || $maxAge < 1){
342
+        if ($maxAge > 365 || $maxAge < 1) {
343 343
             throw new \InvalidArgumentException('maxAge must be at least 1 and less than 365 (' . $maxAge . ' was given)');
344 344
         }
345 345
 
346 346
         // ip must be set
347
-        if (empty($network)){
347
+        if (empty($network)) {
348 348
             throw new \InvalidArgumentException('network argument must be set (null given)');
349 349
         }
350 350
 
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
             'maxAgeInDays'  => $maxAge,  
355 355
         ];
356 356
 
357
-        $response = $this->apiRequest('check-block', $data, 'GET') ;
357
+        $response = $this->apiRequest('check-block', $data, 'GET');
358 358
 
359 359
         return json_decode($response, $returnArray);
360 360
     }
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
     public function getBlacklist(int $limit = 10000, bool $plainText = false, bool $returnArray = false)
375 375
     {
376 376
 
377
-        if ($limit < 1){
377
+        if ($limit < 1) {
378 378
             throw new \InvalidArgumentException('limit must be at least 1 (' . $limit . ' was given)');
379 379
         }
380 380
 
@@ -386,13 +386,13 @@  discard block
 block discarded – undo
386 386
 
387 387
         // plaintext paremeter has no value and must be added only when true 
388 388
         // (set plaintext=false won't work)
389
-        if ($plainText){
390
-            $data['plaintext'] = $plainText;
389
+        if ($plainText) {
390
+            $data[ 'plaintext' ] = $plainText;
391 391
         }
392 392
 
393 393
         $response = $this->apiRequest('blacklist', $data, 'GET');
394 394
 
395
-        if ($plainText){
395
+        if ($plainText) {
396 396
             return $response;
397 397
         } 
398 398
        
@@ -428,8 +428,8 @@  discard block
 block discarded – undo
428 428
         $ch = curl_init(); 
429 429
   
430 430
         // for csv
431
-        if (!empty($csvFilePath)){
432
-            $cfile = new \CurlFile($csvFilePath,  'text/csv', 'csv');
431
+        if (!empty($csvFilePath)) {
432
+            $cfile = new \CurlFile($csvFilePath, 'text/csv', 'csv');
433 433
             //curl file itself return the realpath with prefix of @
434 434
             $data = array('csv' => $cfile);
435 435
         }
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
         $message = str_replace('\\', '', $message);
475 475
 
476 476
         // Remove self ips
477
-        foreach ($this->selfIps as $ip){
477
+        foreach ($this->selfIps as $ip) {
478 478
             $message = str_replace($ip, '*', $message);
479 479
         }
480 480
 
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
     protected static function loadJsonFile(string $filePath, bool $throwError = true)
502 502
     {
503 503
         // check file exists
504
-        if (!file_exists($filePath) || !is_file($filePath)){
504
+        if (!file_exists($filePath) || !is_file($filePath)) {
505 505
            if ($throwError) {
506 506
                 throw new \Exception('Config file not found');
507 507
            }
Please login to merge, or discard this patch.
lib/CurlTrait.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -36,9 +36,9 @@
 block discarded – undo
36 36
      * @return void
37 37
      * @throws \RuntimeException
38 38
      */
39
-    protected function setCurlOption($ch,int $option,$value){
40
-        if(!curl_setopt($ch,$option,$value)){
41
-            throw new \RuntimeException('curl_setopt failed! '.curl_error($ch));
39
+    protected function setCurlOption($ch, int $option, $value) {
40
+        if (!curl_setopt($ch, $option, $value)) {
41
+            throw new \RuntimeException('curl_setopt failed! ' . curl_error($ch));
42 42
         }
43 43
     }
44 44
 }
Please login to merge, or discard this patch.
lib/ApiBase.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -60,82 +60,82 @@  discard block
 block discarded – undo
60 60
     protected $aipdbApiCategories = [
61 61
         
62 62
         // Altering DNS records resulting in improper redirection.        
63
-        ['dns-c'           , '1', 'DNS Compromise', true],    
63
+        [ 'dns-c', '1', 'DNS Compromise', true ],    
64 64
         
65 65
         // Falsifying domain server cache (cache poisoning).
66
-        ['dns-p'           , '2', 'DNS Poisoning', true],     
66
+        [ 'dns-p', '2', 'DNS Poisoning', true ],     
67 67
         
68 68
         // Fraudulent orders.
69
-        ['fraud-orders'    , '3', 'Fraud Orders', true],      
69
+        [ 'fraud-orders', '3', 'Fraud Orders', true ],      
70 70
 
71 71
         // Participating in distributed denial-of-service (usually part of botnet).        
72
-        ['ddos'            , '4', 'DDoS Attack', true],       
72
+        [ 'ddos', '4', 'DDoS Attack', true ],       
73 73
         
74 74
         // 
75
-        ['ftp-bf'          , '5', 'FTP Brute-Force', true],   
75
+        [ 'ftp-bf', '5', 'FTP Brute-Force', true ],   
76 76
         
77 77
         // Oversized IP packet.
78
-        ['pingdeath'       , '6', 'Ping of Death', true],     
78
+        [ 'pingdeath', '6', 'Ping of Death', true ],     
79 79
 
80 80
         // Phishing websites and/or email.
81
-        ['phishing'        , '7', 'Phishing', true],          
81
+        [ 'phishing', '7', 'Phishing', true ],          
82 82
         
83 83
         //
84
-        ['fraudvoip'       , '8', 'Fraud VoIP', true],        
84
+        [ 'fraudvoip', '8', 'Fraud VoIP', true ],        
85 85
 
86 86
         // Open proxy, open relay, or Tor exit node.
87
-        ['openproxy'       , '9', 'Open Proxy', true],        
87
+        [ 'openproxy', '9', 'Open Proxy', true ],        
88 88
 
89 89
          // Comment/forum spam, HTTP referer spam, or other CMS spam.
90
-         ['webspam'         , '10', 'Web Spam', true],        
90
+         [ 'webspam', '10', 'Web Spam', true ],        
91 91
 
92 92
         // Spam email content, infected attachments, and phishing emails. Note: Limit comments to only relevent
93 93
         // information (instead of log dumps) and be sure to remove PII if you want to remain anonymous.
94
-        ['emailspam'       , '11', 'Email Spam', true],                                                   
94
+        [ 'emailspam', '11', 'Email Spam', true ],                                                   
95 95
              
96 96
         // CMS blog comment spam.
97
-        ['blogspam'        , '12', 'Blog Spam', true],      
97
+        [ 'blogspam', '12', 'Blog Spam', true ],      
98 98
         
99 99
         // Conjunctive category.
100
-        ['vpnip'           , '13', 'VPN IP', false], // to check alone ??           
100
+        [ 'vpnip', '13', 'VPN IP', false ], // to check alone ??           
101 101
 
102 102
         // Scanning for open ports and vulnerable services.
103
-        ['scan'            , '14', 'Port Scan', true],        
103
+        [ 'scan', '14', 'Port Scan', true ],        
104 104
        
105 105
         // 
106
-        ['hack'            , '15', 'Hacking', true],           
106
+        [ 'hack', '15', 'Hacking', true ],           
107 107
 
108 108
         // Attempts at SQL injection.
109
-        ['sql'             , '16', 'SQL Injection', true],     
109
+        [ 'sql', '16', 'SQL Injection', true ],     
110 110
         
111 111
         // Email sender spoofing.
112
-        ['spoof'           , '17', 'Spoofing', true],         
112
+        [ 'spoof', '17', 'Spoofing', true ],         
113 113
 
114 114
         // Credential brute-force attacks on webpage logins and services like SSH, FTP, SIP, SMTP, RDP, etc. 
115 115
         // This category is seperate from DDoS attacks.
116
-        ['brute'           , '18', 'Brute-Force', true],     
116
+        [ 'brute', '18', 'Brute-Force', true ],     
117 117
 
118 118
         // Webpage scraping (for email addresses, content, etc) and crawlers that do not honor robots.txt.                                  
119 119
         // Excessive requests and user agent spoofing can also be reported here.                        
120
-        ['badbot'          , '19', 'Bad Web Bot', true],      
120
+        [ 'badbot', '19', 'Bad Web Bot', true ],      
121 121
                                                          
122 122
         // Host is likely infected with malware and being used for other attacks or to host malicious content. 
123 123
         // The host owner may not be aware of the compromise. This category is often used in combination 
124 124
         // with other attack categories.
125
-        ['explhost'        , '20', 'Exploited Host', true],
125
+        [ 'explhost', '20', 'Exploited Host', true ],
126 126
         
127 127
         // Attempts to probe for or exploit installed web applications such as a CMS 
128 128
         // like WordPress/Drupal, e-commerce solutions, forum software, phpMyAdmin and 
129 129
         // various other software plugins/solutions.                                                         
130
-        ['webattack'       , '21', 'Web App Attack', true ],   
130
+        [ 'webattack', '21', 'Web App Attack', true ],   
131 131
         
132 132
         // Secure Shell (SSH) abuse. Use this category in combination 
133 133
         // with more specific categories.
134
-        ['ssh'             , '22', 'SSH', false],              
134
+        [ 'ssh', '22', 'SSH', false ],              
135 135
 
136 136
         // Abuse was targeted at an "Internet of Things" type device. Include 
137 137
         // information about what type of device was targeted in the comments.         
138
-        ['oit'             , '23', 'IoT Targeted', true],     
138
+        [ 'oit', '23', 'IoT Targeted', true ],     
139 139
     ];
140 140
 
141 141
     /**
@@ -159,8 +159,8 @@  discard block
 block discarded – undo
159 159
      */
160 160
     public function getCategoryIdbyName(string $categoryName)
161 161
     {
162
-        foreach ($this->aipdbApiCategories as $cat){
163
-            if ($cat[0] === $categoryName) {
162
+        foreach ($this->aipdbApiCategories as $cat) {
163
+            if ($cat[ 0 ] === $categoryName) {
164 164
                 return $cat;
165 165
             }
166 166
          }
@@ -179,8 +179,8 @@  discard block
 block discarded – undo
179 179
      */
180 180
     public function getCategoryNameById(string $categoryId)
181 181
     {
182
-        foreach ($this->aipdbApiCategories as $cat){
183
-           if ($cat[1] === $categoryId) {
182
+        foreach ($this->aipdbApiCategories as $cat) {
183
+           if ($cat[ 1 ] === $categoryId) {
184 184
                return $cat;
185 185
            }
186 186
         }
@@ -201,8 +201,8 @@  discard block
 block discarded – undo
201 201
     protected function getCategoryIndex(string $value, int $index)
202 202
     {
203 203
         $i = 0;
204
-        foreach ($this->aipdbApiCategories as $cat){
205
-            if ($cat[$index] === $value) {
204
+        foreach ($this->aipdbApiCategories as $cat) {
205
+            if ($cat[ $index ] === $value) {
206 206
                 return $i;
207 207
             }
208 208
             $i++;
@@ -236,21 +236,21 @@  discard block
 block discarded – undo
236 236
         foreach ($cats as $cat) {
237 237
 
238 238
             // get index on our array of categories
239
-            $catIndex    = is_numeric($cat) ? $this->getCategoryIndex($cat, 1) : $this->getCategoryIndex($cat, 0);
239
+            $catIndex = is_numeric($cat) ? $this->getCategoryIndex($cat, 1) : $this->getCategoryIndex($cat, 0);
240 240
 
241 241
             // check if found
242
-            if ($catIndex === false ){
243
-                throw new \InvalidArgumentException('Invalid report category was given : ['. $cat .  ']');
242
+            if ($catIndex === false) {
243
+                throw new \InvalidArgumentException('Invalid report category was given : [' . $cat . ']');
244 244
             }
245 245
 
246 246
             // get Id
247
-            $catId = $this->aipdbApiCategories[$catIndex][1];
247
+            $catId = $this->aipdbApiCategories[ $catIndex ][ 1 ];
248 248
 
249 249
             // need another ?
250
-            if ($needAnother !== false){
250
+            if ($needAnother !== false) {
251 251
 
252 252
                 // is a standalone cat ?
253
-                if ($this->aipdbApiCategories[$catIndex][3] === false) {
253
+                if ($this->aipdbApiCategories[ $catIndex ][ 3 ] === false) {
254 254
                     $needAnother = true;
255 255
 
256 256
                 } else {
@@ -261,10 +261,10 @@  discard block
 block discarded – undo
261 261
             }
262 262
 
263 263
             // set or add to cats list 
264
-            $catsString = ($catsString === '') ? $catId : $catsString .','.$catId;
264
+            $catsString = ($catsString === '') ? $catId : $catsString . ',' . $catId;
265 265
         }
266 266
 
267
-        if ($needAnother !== false){
267
+        if ($needAnother !== false) {
268 268
             throw new \InvalidArgumentException('Invalid report category paremeter given: some categories can\'t be used alone');
269 269
         }
270 270
 
Please login to merge, or discard this patch.