@@ -50,7 +50,7 @@ discard block |
||
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 |
||
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,22 +100,22 @@ discard block |
||
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 | // todo check file exist |
113 | 113 | $keyConfig = self::loadJsonFile($configPath); |
114 | - $selfIps = []; |
|
114 | + $selfIps = [ ]; |
|
115 | 115 | |
116 | 116 | // Look for other optional config files in the same directory |
117 | 117 | $selfIpsConfigPath = pathinfo($configPath, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR . 'self_ips.json'; |
118 | - if (file_exists($selfIpsConfigPath)){ |
|
118 | + if (file_exists($selfIpsConfigPath)) { |
|
119 | 119 | $selfIps = self::loadJsonFile($selfIpsConfigPath)->self_ips; |
120 | 120 | } |
121 | 121 | |
@@ -158,17 +158,17 @@ discard block |
||
158 | 158 | public function report(string $ip = '', string $categories = '', string $message = '', bool $returnArray = false) |
159 | 159 | { |
160 | 160 | // ip must be set |
161 | - if (empty($ip)){ |
|
161 | + if (empty($ip)) { |
|
162 | 162 | throw new \InvalidArgumentException('Ip was empty'); |
163 | 163 | } |
164 | 164 | |
165 | 165 | // categories must be set |
166 | - if (empty($categories)){ |
|
166 | + if (empty($categories)) { |
|
167 | 167 | throw new \InvalidArgumentException('categories list was empty'); |
168 | 168 | } |
169 | 169 | |
170 | 170 | // message must be set |
171 | - if (empty($message)){ |
|
171 | + if (empty($message)) { |
|
172 | 172 | throw new \InvalidArgumentException('report message was empty'); |
173 | 173 | } |
174 | 174 | |
@@ -211,21 +211,21 @@ discard block |
||
211 | 211 | foreach ($cats as $cat) { |
212 | 212 | |
213 | 213 | // get index on our array of categories |
214 | - $catIndex = is_numeric($cat) ? $this->getCategoryIndex($cat, 1) : $this->getCategoryIndex($cat, 0); |
|
214 | + $catIndex = is_numeric($cat) ? $this->getCategoryIndex($cat, 1) : $this->getCategoryIndex($cat, 0); |
|
215 | 215 | |
216 | 216 | // check if found |
217 | - if ($catIndex === false ){ |
|
218 | - throw new \InvalidArgumentException('Invalid report category was given : ['. $cat . ']'); |
|
217 | + if ($catIndex === false) { |
|
218 | + throw new \InvalidArgumentException('Invalid report category was given : [' . $cat . ']'); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | // get Id |
222 | - $catId = $this->aipdbApiCategories[$catIndex][1]; |
|
222 | + $catId = $this->aipdbApiCategories[ $catIndex ][ 1 ]; |
|
223 | 223 | |
224 | 224 | // need another ? |
225 | - if ($needAnother !== false){ |
|
225 | + if ($needAnother !== false) { |
|
226 | 226 | |
227 | 227 | // is a standalone cat ? |
228 | - if ($this->aipdbApiCategories[$catIndex][3] === false) { |
|
228 | + if ($this->aipdbApiCategories[ $catIndex ][ 3 ] === false) { |
|
229 | 229 | $needAnother = true; |
230 | 230 | |
231 | 231 | } else { |
@@ -236,10 +236,10 @@ discard block |
||
236 | 236 | } |
237 | 237 | |
238 | 238 | // set or add to cats list |
239 | - $catsString = ($catsString === '') ? $catId : $catsString .','.$catId; |
|
239 | + $catsString = ($catsString === '') ? $catId : $catsString . ',' . $catId; |
|
240 | 240 | } |
241 | 241 | |
242 | - if ($needAnother !== false){ |
|
242 | + if ($needAnother !== false) { |
|
243 | 243 | throw new \InvalidArgumentException('Invalid report category paremeter given: some categories can\'t be used alone'); |
244 | 244 | } |
245 | 245 | |
@@ -263,18 +263,18 @@ discard block |
||
263 | 263 | public function check(string $ip = null, string $maxAge = '30', bool $verbose = false, bool $returnArray = false) |
264 | 264 | { |
265 | 265 | |
266 | - if (!is_numeric($maxAge)){ |
|
266 | + if (!is_numeric($maxAge)) { |
|
267 | 267 | throw new \InvalidArgumentException('maxAge must be a numeric value (' . $maxAge . ' was given)'); |
268 | 268 | } |
269 | 269 | $maxAge = intval($maxAge); |
270 | 270 | |
271 | 271 | // max age must less or equal to 365 |
272 | - if ($maxAge > 365 || $maxAge < 1){ |
|
272 | + if ($maxAge > 365 || $maxAge < 1) { |
|
273 | 273 | throw new \InvalidArgumentException('maxAge must be at least 1 and less than 365 (' . $maxAge . ' was given)'); |
274 | 274 | } |
275 | 275 | |
276 | 276 | //ip must be set |
277 | - if (empty($ip)){ |
|
277 | + if (empty($ip)) { |
|
278 | 278 | throw new \InvalidArgumentException('ip argument must be set (null given)'); |
279 | 279 | } |
280 | 280 | |
@@ -285,12 +285,12 @@ discard block |
||
285 | 285 | ]; |
286 | 286 | |
287 | 287 | // option |
288 | - if ($verbose){ |
|
289 | - $data['verbose'] = true; |
|
288 | + if ($verbose) { |
|
289 | + $data[ 'verbose' ] = true; |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | // check AbuseIPDB request |
293 | - return $this->apiRequest('check', $data, 'GET', $returnArray) ; |
|
293 | + return $this->apiRequest('check', $data, 'GET', $returnArray); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | $message = str_replace('\\', '', $message); |
356 | 356 | |
357 | 357 | // Remove self ips |
358 | - foreach ($this->selfIps as $ip){ |
|
358 | + foreach ($this->selfIps as $ip) { |
|
359 | 359 | $message = str_replace($ip, '[-]', $message); |
360 | 360 | } |
361 | 361 | |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | $message = preg_replace($emailPattern, $emailRemplacement, $message); |
366 | 366 | |
367 | 367 | // Make sure message is less 1024 chars |
368 | - return substr($message, 0,1024); |
|
368 | + return substr($message, 0, 1024); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | /** |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | protected static function loadJsonFile(string $filePath, bool $throwError = true) |
384 | 384 | { |
385 | 385 | // check file exists |
386 | - if (!file_exists($filePath) || !is_file($filePath)){ |
|
386 | + if (!file_exists($filePath) || !is_file($filePath)) { |
|
387 | 387 | if ($throwError) { |
388 | 388 | throw new \Exception('Config file not found'); |
389 | 389 | } |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | $json = json_decode(utf8_encode($content)); |
396 | 396 | |
397 | 397 | // check for errors |
398 | - if ($json == null && json_last_error() != JSON_ERROR_NONE){ |
|
398 | + if ($json == null && json_last_error() != JSON_ERROR_NONE) { |
|
399 | 399 | if ($throwError) { |
400 | 400 | throw new \LogicException(sprintf("Failed to parse config file Error: '%s'", json_last_error_msg())); |
401 | 401 | } |