Passed
Push — master ( 1c1fe7...fa238f )
by Kris
01:52
created
lib/ApiManager.php 2 patches
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -80,8 +80,8 @@  discard block
 block discarded – undo
80 80
             'userId'  => $this->aipdbUserId,
81 81
             'apiKey'  => $this->aipdbApiKey,
82 82
 
83
-          // TODO 'selfIps' => $this->selfIps,
84
-          // TODO  default report cat 
83
+            // TODO 'selfIps' => $this->selfIps,
84
+            // TODO  default report cat 
85 85
         );
86 86
     }
87 87
 
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
      */
151 151
     public function report(string $ip = '', string $categories = '', string $message = '', bool $returnArray = false)
152 152
     {
153
-         // ip must be set
153
+            // ip must be set
154 154
         if (empty($ip)){
155 155
             throw new \InvalidArgumentException('Ip was empty');
156 156
         }
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
         }
162 162
 
163 163
         // message must be set
164
-          if (empty($message)){
164
+            if (empty($message)){
165 165
             throw new \InvalidArgumentException('report message was empty');
166 166
         }
167 167
 
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 
278 278
         // option
279 279
         if ($verbose){
280
-           $data['verbose'] = true;
280
+            $data['verbose'] = true;
281 281
         }
282 282
 
283 283
         // check AbuseIPDB request
@@ -321,14 +321,14 @@  discard block
 block discarded – undo
321 321
             'Key: ' . $this->aipdbApiKey,
322 322
         ]);
323 323
   
324
-      // execute curl call
325
-      $result = curl_exec($ch);
324
+        // execute curl call
325
+        $result = curl_exec($ch);
326 326
   
327
-      // close connection
328
-      curl_close($ch);
327
+        // close connection
328
+        curl_close($ch);
329 329
   
330
-      // return response as object / array
331
-      return json_decode($result, $returnArray);
330
+        // return response as object / array
331
+        return json_decode($result, $returnArray);
332 332
     }
333 333
 
334 334
     /** 
@@ -336,10 +336,10 @@  discard block
 block discarded – undo
336 336
      *
337 337
      * @access public
338 338
      * @static
339
-	 * @param string    $filePath       The file's full path
340
-	 * @param bool     [$trowError]     Throw error on true or silent process. Default is true
339
+     * @param string    $filePath       The file's full path
340
+     * @param bool     [$trowError]     Throw error on true or silent process. Default is true
341 341
      *  
342
-	 * @return string|null 
342
+     * @return string|null 
343 343
      * @throws \Exception
344 344
      * @throws \LogicException
345 345
      */
@@ -347,10 +347,10 @@  discard block
 block discarded – undo
347 347
     {
348 348
         // check file exists
349 349
         if (!file_exists($filePath) || !is_file($filePath)){
350
-           if ($throwError) {
350
+            if ($throwError) {
351 351
                 throw new \Exception('Config file not found');
352
-           }
353
-           return null;  
352
+            }
353
+            return null;  
354 354
         }
355 355
 
356 356
         // get and parse content
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 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 you dont want to report
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,12 +100,12 @@  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 redable
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
 
@@ -151,17 +151,17 @@  discard block
 block discarded – undo
151 151
     public function report(string $ip = '', string $categories = '', string $message = '', bool $returnArray = false)
152 152
     {
153 153
          // ip must be set
154
-        if (empty($ip)){
154
+        if (empty($ip)) {
155 155
             throw new \InvalidArgumentException('Ip was empty');
156 156
         }
157 157
 
158 158
         // categories must be set
159
-        if (empty($categories)){
159
+        if (empty($categories)) {
160 160
             throw new \InvalidArgumentException('categories list was empty');
161 161
         }
162 162
 
163 163
         // message must be set
164
-          if (empty($message)){
164
+          if (empty($message)) {
165 165
             throw new \InvalidArgumentException('report message was empty');
166 166
         }
167 167
 
@@ -202,21 +202,21 @@  discard block
 block discarded – undo
202 202
         foreach ($cats as $cat) {
203 203
 
204 204
             // get index on our array of categories
205
-            $catIndex    = is_numeric($cat) ? $this->getCategoryIndex($cat, 1) : $this->getCategoryIndex($cat, 0);
205
+            $catIndex = is_numeric($cat) ? $this->getCategoryIndex($cat, 1) : $this->getCategoryIndex($cat, 0);
206 206
 
207 207
             // check if found
208
-            if ($catIndex === false ){
209
-                throw new \InvalidArgumentException('Invalid report category was given : ['. $cat .  ']');
208
+            if ($catIndex === false) {
209
+                throw new \InvalidArgumentException('Invalid report category was given : [' . $cat . ']');
210 210
             }
211 211
 
212 212
             // get Id
213
-            $catId = $this->aipdbApiCategories[$catIndex][1];
213
+            $catId = $this->aipdbApiCategories[ $catIndex ][ 1 ];
214 214
 
215 215
             // need another ?
216
-            if ($needAnother !== false){
216
+            if ($needAnother !== false) {
217 217
 
218 218
                 // is a standalone cat ?
219
-                if ($this->aipdbApiCategories[$catIndex][3] === false) {
219
+                if ($this->aipdbApiCategories[ $catIndex ][ 3 ] === false) {
220 220
                     $needAnother = true;
221 221
 
222 222
                 } else {
@@ -227,10 +227,10 @@  discard block
 block discarded – undo
227 227
             }
228 228
 
229 229
             // set or add to cats list 
230
-            $catsString = ($catsString === '') ? $catId : $catsString .','.$catId;
230
+            $catsString = ($catsString === '') ? $catId : $catsString . ',' . $catId;
231 231
         }
232 232
 
233
-        if ($needAnother !== false){
233
+        if ($needAnother !== false) {
234 234
             throw new \InvalidArgumentException('Invalid report category paremeter given: some categories can\'t be used alone');
235 235
         }
236 236
 
@@ -254,18 +254,18 @@  discard block
 block discarded – undo
254 254
     public function check(string $ip = null, string $maxAge = '30', bool $verbose = false, bool $returnArray = false)
255 255
     {
256 256
         
257
-        if (!is_numeric($maxAge)){
257
+        if (!is_numeric($maxAge)) {
258 258
             throw new \InvalidArgumentException('maxAge must be a numeric value (' . $maxAge . ' was given)');
259 259
         }
260 260
         $maxAge = intval($maxAge);
261 261
 
262 262
         // max age must less or equal to 365
263
-        if ($maxAge > 365 || $maxAge < 1){
263
+        if ($maxAge > 365 || $maxAge < 1) {
264 264
             throw new \InvalidArgumentException('maxAge must be at least 1 and less than 365 (' . $maxAge . ' was given)');
265 265
         }
266 266
 
267 267
         //ip must be set
268
-        if (empty($ip)){
268
+        if (empty($ip)) {
269 269
             throw new \InvalidArgumentException('ip argument must be set (null given)');
270 270
         }
271 271
 
@@ -276,12 +276,12 @@  discard block
 block discarded – undo
276 276
         ];
277 277
 
278 278
         // option
279
-        if ($verbose){
280
-           $data['verbose'] = true;
279
+        if ($verbose) {
280
+           $data[ 'verbose' ] = true;
281 281
         }
282 282
 
283 283
         // check AbuseIPDB request
284
-        return $this->apiRequest('check', $data, 'GET', $returnArray) ;
284
+        return $this->apiRequest('check', $data, 'GET', $returnArray);
285 285
     }
286 286
 
287 287
     /**
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
     protected static function loadJsonFile(string $filePath, bool $throwError = true)
347 347
     {
348 348
         // check file exists
349
-        if (!file_exists($filePath) || !is_file($filePath)){
349
+        if (!file_exists($filePath) || !is_file($filePath)) {
350 350
            if ($throwError) {
351 351
                 throw new \Exception('Config file not found');
352 352
            }
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
         $json    = json_decode(utf8_encode($content));
359 359
 
360 360
         // check for errors
361
-        if ($json == null && json_last_error() != JSON_ERROR_NONE){
361
+        if ($json == null && json_last_error() != JSON_ERROR_NONE) {
362 362
             if ($throwError) {
363 363
                 throw new \LogicException(sprintf("Failed to parse config file Error: '%s'", json_last_error_msg()));
364 364
             }
Please login to merge, or discard this patch.
lib/ApiDefintion.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -28,10 +28,10 @@  discard block
 block discarded – undo
28 28
  */
29 29
 abstract class ApiDefintion
30 30
 {
31
-     /**
32
-     * AbuseIPDB API v2 Endpoint
33
-     * @var string $api_endpoint  
34
-     */
31
+        /**
32
+         * AbuseIPDB API v2 Endpoint
33
+         * @var string $api_endpoint  
34
+         */
35 35
     protected $aipdbApiEndpoint = 'https://api.abuseipdb.com/api/v2/'; 
36 36
 
37 37
     /**
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
         // Open proxy, open relay, or Tor exit node.
68 68
         ['openproxy'       , '9', 'Open Proxy', true],        
69 69
 
70
-         // Comment/forum spam, HTTP referer spam, or other CMS spam.
71
-         ['webspam'         , '10', 'Web Spam', true],        
70
+            // Comment/forum spam, HTTP referer spam, or other CMS spam.
71
+            ['webspam'         , '10', 'Web Spam', true],        
72 72
 
73 73
         // Spam email content, infected attachments, and phishing emails. Note: Limit comments to only relevent
74 74
         // information (instead of log dumps) and be sure to remove PII if you want to remain anonymous.
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
         // Abuse was targeted at an "Internet of Things" type device. Include 
118 118
         // information about what type of device was targeted in the comments.         
119 119
         ['oit'             , '23', 'IoT Targeted', true],     
120
-      ];
120
+        ];
121 121
 
122 122
     /**
123 123
      * Get the category id corresponding to given name
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
             if ($cat[0] === $categoryName) {
134 134
                 return $cat;
135 135
             }
136
-         }
136
+            }
137 137
 
138 138
         // not found
139 139
         return false;
@@ -150,9 +150,9 @@  discard block
 block discarded – undo
150 150
     public function getCategoryNameById(string $categoryId)
151 151
     {
152 152
         foreach ($this->aipdbApiCategories as $cat){
153
-           if ($cat[1] === $categoryId) {
154
-               return $cat;
155
-           }
153
+            if ($cat[1] === $categoryId) {
154
+                return $cat;
155
+            }
156 156
         }
157 157
 
158 158
         // not found
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
             if ($cat[$index] === $value) {
179 179
                 return $i;
180 180
             }
181
-         }
181
+            }
182 182
 
183 183
         // not found
184 184
         return false;
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -41,82 +41,82 @@  discard block
 block discarded – undo
41 41
     protected $aipdbApiCategories = [
42 42
         
43 43
         // Altering DNS records resulting in improper redirection.        
44
-        ['dns-c'           , '1', 'DNS Compromise', true],    
44
+        [ 'dns-c', '1', 'DNS Compromise', true ],    
45 45
         
46 46
         // Falsifying domain server cache (cache poisoning).
47
-        ['dns-p'           , '2', 'DNS Poisoning', true],     
47
+        [ 'dns-p', '2', 'DNS Poisoning', true ],     
48 48
         
49 49
         // Fraudulent orders.
50
-        ['fraud-orders'    , '3', 'Fraud Orders', true],      
50
+        [ 'fraud-orders', '3', 'Fraud Orders', true ],      
51 51
 
52 52
         // Participating in distributed denial-of-service (usually part of botnet).        
53
-        ['ddos'            , '4', 'DDoS Attack', true],       
53
+        [ 'ddos', '4', 'DDoS Attack', true ],       
54 54
         
55 55
         // 
56
-        ['ftp-bf'          , '5', 'FTP Brute-Force', true],   
56
+        [ 'ftp-bf', '5', 'FTP Brute-Force', true ],   
57 57
         
58 58
         // Oversized IP packet.
59
-        ['pingdeath'       , '6', 'Ping of Death', true],     
59
+        [ 'pingdeath', '6', 'Ping of Death', true ],     
60 60
 
61 61
         // Phishing websites and/or email.
62
-        ['phishing'        , '7', 'Phishing', true],          
62
+        [ 'phishing', '7', 'Phishing', true ],          
63 63
         
64 64
         //
65
-        ['fraudvoip'       , '8', 'Fraud VoIP', true],        
65
+        [ 'fraudvoip', '8', 'Fraud VoIP', true ],        
66 66
 
67 67
         // Open proxy, open relay, or Tor exit node.
68
-        ['openproxy'       , '9', 'Open Proxy', true],        
68
+        [ 'openproxy', '9', 'Open Proxy', true ],        
69 69
 
70 70
          // Comment/forum spam, HTTP referer spam, or other CMS spam.
71
-         ['webspam'         , '10', 'Web Spam', true],        
71
+         [ 'webspam', '10', 'Web Spam', true ],        
72 72
 
73 73
         // Spam email content, infected attachments, and phishing emails. Note: Limit comments to only relevent
74 74
         // information (instead of log dumps) and be sure to remove PII if you want to remain anonymous.
75
-        ['emailspam'       , '11', 'Email Spam', true],                                                   
75
+        [ 'emailspam', '11', 'Email Spam', true ],                                                   
76 76
              
77 77
         // CMS blog comment spam.
78
-        ['blogspam'        , '12', 'Blog Spam', true],      
78
+        [ 'blogspam', '12', 'Blog Spam', true ],      
79 79
         
80 80
         // Conjunctive category.
81
-        ['vpnip'           , '13', 'VPN IP', false], // to check alone ??           
81
+        [ 'vpnip', '13', 'VPN IP', false ], // to check alone ??           
82 82
 
83 83
         // Scanning for open ports and vulnerable services.
84
-        ['scan'            , '14', 'Port Scan', true],        
84
+        [ 'scan', '14', 'Port Scan', true ],        
85 85
        
86 86
         // seems to can't be used alone
87
-        ['hack'            , '15', 'Hacking', false],           
87
+        [ 'hack', '15', 'Hacking', false ],           
88 88
 
89 89
         // Attempts at SQL injection.
90
-        ['sql'             , '16', 'SQL Injection', true],     
90
+        [ 'sql', '16', 'SQL Injection', true ],     
91 91
         
92 92
         // Email sender spoofing.
93
-        ['spoof'           , '17', 'Spoofing', true],         
93
+        [ 'spoof', '17', 'Spoofing', true ],         
94 94
 
95 95
         // Credential brute-force attacks on webpage logins and services like SSH, FTP, SIP, SMTP, RDP, etc. 
96 96
         // This category is seperate from DDoS attacks.
97
-        ['brute'           , '18', 'Brute-Force', true],     
97
+        [ 'brute', '18', 'Brute-Force', true ],     
98 98
 
99 99
         // Webpage scraping (for email addresses, content, etc) and crawlers that do not honor robots.txt.                                  
100 100
         // Excessive requests and user agent spoofing can also be reported here.                        
101
-        ['badbot'          , '19', 'Bad Web Bot', true],      
101
+        [ 'badbot', '19', 'Bad Web Bot', true ],      
102 102
                                                          
103 103
         // Host is likely infected with malware and being used for other attacks or to host malicious content. 
104 104
         // The host owner may not be aware of the compromise. This category is often used in combination 
105 105
         // with other attack categories.
106
-        ['explhost'        , '20', 'Exploited Host', true],
106
+        [ 'explhost', '20', 'Exploited Host', true ],
107 107
         
108 108
         // Attempts to probe for or exploit installed web applications such as a CMS 
109 109
         // like WordPress/Drupal, e-commerce solutions, forum software, phpMyAdmin and 
110 110
         // various other software plugins/solutions.                                                         
111
-        ['webattack'       , '21', 'Web App Attack', true ],   
111
+        [ 'webattack', '21', 'Web App Attack', true ],   
112 112
         
113 113
         // Secure Shell (SSH) abuse. Use this category in combination 
114 114
         // with more specific categories.
115
-        ['ssh'             , '22', 'SSH', false],              
115
+        [ 'ssh', '22', 'SSH', false ],              
116 116
 
117 117
         // Abuse was targeted at an "Internet of Things" type device. Include 
118 118
         // information about what type of device was targeted in the comments.         
119
-        ['oit'             , '23', 'IoT Targeted', true],     
119
+        [ 'oit', '23', 'IoT Targeted', true ],     
120 120
       ];
121 121
 
122 122
     /**
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
      */
130 130
     public function getCategoryIdbyName(string $categoryName)
131 131
     {
132
-        foreach ($this->aipdbApiCategories as $cat){
133
-            if ($cat[0] === $categoryName) {
132
+        foreach ($this->aipdbApiCategories as $cat) {
133
+            if ($cat[ 0 ] === $categoryName) {
134 134
                 return $cat;
135 135
             }
136 136
          }
@@ -149,8 +149,8 @@  discard block
 block discarded – undo
149 149
      */
150 150
     public function getCategoryNameById(string $categoryId)
151 151
     {
152
-        foreach ($this->aipdbApiCategories as $cat){
153
-           if ($cat[1] === $categoryId) {
152
+        foreach ($this->aipdbApiCategories as $cat) {
153
+           if ($cat[ 1 ] === $categoryId) {
154 154
                return $cat;
155 155
            }
156 156
         }
@@ -171,11 +171,11 @@  discard block
 block discarded – undo
171 171
     protected function getCategoryIndex(string $value, int $index)
172 172
     {
173 173
         $i = -1;
174
-        foreach ($this->aipdbApiCategories as $cat){
174
+        foreach ($this->aipdbApiCategories as $cat) {
175 175
             
176 176
             $i++;
177 177
 
178
-            if ($cat[$index] === $value) {
178
+            if ($cat[ $index ] === $value) {
179 179
                 return $i;
180 180
             }
181 181
          }
Please login to merge, or discard this patch.