@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | protected static function printPlainTextErrors(object $response) |
38 | 38 | { |
39 | - foreach ($response->errors as $err){ |
|
39 | + foreach ($response->errors as $err) { |
|
40 | 40 | $text = 'Error: '; |
41 | 41 | $text .= self::getErrorDetail($err, 'title'); |
42 | 42 | $text .= self::getErrorDetail($err, 'statuts'); |
@@ -59,11 +59,11 @@ discard block |
||
59 | 59 | */ |
60 | 60 | private static function getErrorDetail(object $error, string $field, ?string $parent = null) |
61 | 61 | { |
62 | - if (!empty($parent)){ |
|
63 | - return !empty($error->$parent) && !empty($error->$parent->$field) ? ' ' . $field . ': ' . $error->$parent->$field : ''; |
|
62 | + if (!empty($parent)) { |
|
63 | + return !empty($error->$parent) && !empty($error->$parent->$field) ? ' '.$field.': '.$error->$parent->$field : ''; |
|
64 | 64 | } |
65 | 65 | |
66 | - return !empty($error->$field) ? ' ' . $field . ': ' . $error->$field : ''; |
|
66 | + return !empty($error->$field) ? ' '.$field.': '.$error->$field : ''; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | protected static function checkForEmpty(object $response) |
79 | 79 | { |
80 | 80 | // check for empty response ? |
81 | - if ( empty($response) || empty($response->data) ){ |
|
81 | + if (empty($response) || empty($response->data)) { |
|
82 | 82 | self::error('An unexpected error occurred.'); |
83 | 83 | return true; |
84 | 84 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | protected static function printTempMessage() |
83 | 83 | { |
84 | 84 | if (self::isDefaultOuput()) { |
85 | - Console::reLog(Console::text(' ? ', 'green') . Console::text('waiting for api response', 'white') . Console::text(' ... ', 'green')); |
|
85 | + Console::reLog(Console::text(' ? ', 'green').Console::text('waiting for api response', 'white').Console::text(' ... ', 'green')); |
|
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
@@ -140,11 +140,11 @@ discard block |
||
140 | 140 | self::printLogo(); |
141 | 141 | |
142 | 142 | Console::log(); |
143 | - Console::log(Console::text(' Kristuff/AbuseIPDB Client version: ', 'darkgray') . Console::text(AbuseIPDBClient::VERSION, 'lightgray')); |
|
144 | - Console::log(Console::text(' Kristuff/AbuseIPDB Core version: ', 'darkgray') . Console::text(ApiHandler::VERSION, 'lightgray')); |
|
143 | + Console::log(Console::text(' Kristuff/AbuseIPDB Client version: ', 'darkgray').Console::text(AbuseIPDBClient::VERSION, 'lightgray')); |
|
144 | + Console::log(Console::text(' Kristuff/AbuseIPDB Core version: ', 'darkgray').Console::text(ApiHandler::VERSION, 'lightgray')); |
|
145 | 145 | Console::log(Console::text(' --------------------------------------------------', 'darkgray')); |
146 | 146 | Console::log(Console::text(' Released under the MIT licence', 'darkgray')); |
147 | - Console::log(Console::text(' Made with ', 'darkgray') . Console::text('♥', 'red') . Console::text(' in France', 'darkgray')); |
|
147 | + Console::log(Console::text(' Made with ', 'darkgray').Console::text('♥', 'red').Console::text(' in France', 'darkgray')); |
|
148 | 148 | Console::log( |
149 | 149 | Console::text(' © 2020-2021 Kristuff (', 'darkgray'). |
150 | 150 | Console::text('https://github.com/kristuff', 'darkgray', 'underlined'). |
@@ -166,8 +166,8 @@ discard block |
||
166 | 166 | { |
167 | 167 | if (self::isDefaultOuput()) { |
168 | 168 | Console::log(); |
169 | - Console::log( Console::text(' Kristuff\AbuseIPDB ', 'darkgray') . Console::text(' ' . AbuseIPDBClient::VERSION . ' ', 'white', 'blue')); |
|
170 | - Console::log(Console::text(' Made with ', 'darkgray') . Console::text('♥', 'red') . Console::text(' in France', 'darkgray')); |
|
169 | + Console::log(Console::text(' Kristuff\AbuseIPDB ', 'darkgray').Console::text(' '.AbuseIPDBClient::VERSION.' ', 'white', 'blue')); |
|
170 | + Console::log(Console::text(' Made with ', 'darkgray').Console::text('♥', 'red').Console::text(' in France', 'darkgray')); |
|
171 | 171 | Console::log(' © 2020-2021 Kristuff', 'darkgray'); |
172 | 172 | Console::log(); |
173 | 173 | } |
@@ -184,19 +184,19 @@ discard block |
||
184 | 184 | protected static function printFooter(string $requestTime = '') |
185 | 185 | { |
186 | 186 | if (self::isDefaultOuput()) { |
187 | - if (!empty($requestTime)){ |
|
187 | + if (!empty($requestTime)) { |
|
188 | 188 | $date_utc = new \DateTime("now", new \DateTimeZone("UTC")); |
189 | 189 | Console::log( |
190 | - Console::text(' Request time: ', 'darkgray') . Console::text($requestTime . 's', 'lightgray'). |
|
191 | - Console::text(' | UTC time: ', 'darkgray') . Console::text($date_utc->format('Y-m-d H:i:s'), 'lightgray') |
|
190 | + Console::text(' Request time: ', 'darkgray').Console::text($requestTime.'s', 'lightgray'). |
|
191 | + Console::text(' | UTC time: ', 'darkgray').Console::text($date_utc->format('Y-m-d H:i:s'), 'lightgray') |
|
192 | 192 | ); |
193 | 193 | } |
194 | 194 | Console::log(Console::text(' ------------------------------------------------------------------------------------------------------', 'darkgray')); |
195 | 195 | Console::log( |
196 | - Console::text(' Kristuff\AbuseIPDB ', 'darkgray') . |
|
197 | - Console::text(AbuseIPDBClient::VERSION, 'lightgray') . |
|
198 | - Console::text(' | Made with ', 'darkgray') . |
|
199 | - Console::text('♥', 'red') . |
|
196 | + Console::text(' Kristuff\AbuseIPDB ', 'darkgray'). |
|
197 | + Console::text(AbuseIPDBClient::VERSION, 'lightgray'). |
|
198 | + Console::text(' | Made with ', 'darkgray'). |
|
199 | + Console::text('♥', 'red'). |
|
200 | 200 | Console::text(' in France | © 2020-2021 Kristuff (https://github.com/kristuff)', 'darkgray') |
201 | 201 | ); |
202 | 202 | Console::log(); |
@@ -215,9 +215,9 @@ discard block |
||
215 | 215 | { |
216 | 216 | |
217 | 217 | // do not print null/blank values |
218 | - if (isset($value)){ |
|
219 | - $line = Console::text($text, 'white') . Console::text($value, $foregroundColor, $backgroundColor); |
|
220 | - if ($print && self::isDefaultOuput()){ |
|
218 | + if (isset($value)) { |
|
219 | + $line = Console::text($text, 'white').Console::text($value, $foregroundColor, $backgroundColor); |
|
220 | + if ($print && self::isDefaultOuput()) { |
|
221 | 221 | Console::log($line); |
222 | 222 | } |
223 | 223 | return $line; |
@@ -241,16 +241,16 @@ discard block |
||
241 | 241 | $scoreforegroundColor = 'white'; |
242 | 242 | $scoreBackgroundColor = 'green'; |
243 | 243 | |
244 | - if (intval($score) > 0 ){ |
|
244 | + if (intval($score) > 0) { |
|
245 | 245 | $scoreforegroundColor = 'black'; |
246 | 246 | $scoreBackgroundColor = 'yellow'; |
247 | 247 | } |
248 | - if (intval($score) > 50 ){ |
|
248 | + if (intval($score) > 50) { |
|
249 | 249 | $scoreforegroundColor = 'white'; |
250 | 250 | $scoreBackgroundColor = 'red'; |
251 | 251 | } |
252 | 252 | |
253 | - $badge = str_pad($score, 3, ' ',STR_PAD_LEFT); |
|
253 | + $badge = str_pad($score, 3, ' ', STR_PAD_LEFT); |
|
254 | 254 | return Console::text($padding.$badge.$padding, $scoreforegroundColor, $scoreBackgroundColor); |
255 | 255 | } |
256 | 256 | |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | * |
265 | 265 | * @return bool |
266 | 266 | */ |
267 | - protected static function hasErrors(object $response, bool $checkForEmpty = true ) |
|
267 | + protected static function hasErrors(object $response, bool $checkForEmpty = true) |
|
268 | 268 | { |
269 | 269 | return $checkForEmpty ? self::parseErrors($response) || self::checkForEmpty($response) : self::parseErrors($response); |
270 | 270 | } |
@@ -281,8 +281,8 @@ discard block |
||
281 | 281 | */ |
282 | 282 | private static function parseErrors(object $response) |
283 | 283 | { |
284 | - if (isset($response) && isset($response->errors)){ |
|
285 | - switch (self::$outputFormat){ |
|
284 | + if (isset($response) && isset($response->errors)) { |
|
285 | + switch (self::$outputFormat) { |
|
286 | 286 | case self::OUTPUT_DEFAULT: |
287 | 287 | self::printFormattedErrors($response); |
288 | 288 | break; |
@@ -311,24 +311,24 @@ discard block |
||
311 | 311 | protected static function printFormattedErrors(object $response) |
312 | 312 | { |
313 | 313 | // top error badge |
314 | - Console::log(' ' . Console::text(' ERROR ','white', 'red')); |
|
314 | + Console::log(' '.Console::text(' ERROR ', 'white', 'red')); |
|
315 | 315 | |
316 | 316 | $num = 0; |
317 | 317 | // errors is an array, could have more than one error.. |
318 | - foreach ($response->errors as $err){ |
|
318 | + foreach ($response->errors as $err) { |
|
319 | 319 | $num++; |
320 | 320 | |
321 | - Console::log(Console::text(' ✗', 'red') . self::printResult(' Number: ', $num, 'lightyellow','', false)); |
|
322 | - self::printResult(' Status: ', $err->status ?? null, 'lightyellow',''); |
|
321 | + Console::log(Console::text(' ✗', 'red').self::printResult(' Number: ', $num, 'lightyellow', '', false)); |
|
322 | + self::printResult(' Status: ', $err->status ?? null, 'lightyellow', ''); |
|
323 | 323 | |
324 | - if (!empty($err->source) && !empty($err->source->parameter)){ |
|
324 | + if (!empty($err->source) && !empty($err->source->parameter)) { |
|
325 | 325 | self::printResult(' Parameter: ', $err->source->parameter, 'lightyellow'); |
326 | 326 | } |
327 | 327 | self::printResult(' Title: ', $err->title ?? null, 'lightyellow'); |
328 | 328 | self::printResult(' Detail: ', $err->detail ?? null, 'lightyellow'); |
329 | 329 | |
330 | 330 | // separate errors |
331 | - if (count($response->errors) > 1){ |
|
331 | + if (count($response->errors) > 1) { |
|
332 | 332 | Console::log(' ---'); |
333 | 333 | } |
334 | 334 | } |
@@ -348,11 +348,11 @@ discard block |
||
348 | 348 | { |
349 | 349 | if (self::isDefaultOuput()) { |
350 | 350 | // ✗ |
351 | - Console::log(' ' . Console::text(' ERROR ','white', 'red')); |
|
351 | + Console::log(' '.Console::text(' ERROR ', 'white', 'red')); |
|
352 | 352 | Console::log( |
353 | - Console::text(' ✗', 'red') . |
|
354 | - Console::text(' Detail: ', 'white') . |
|
355 | - Console::text($error, 'lightyellow') . |
|
353 | + Console::text(' ✗', 'red'). |
|
354 | + Console::text(' Detail: ', 'white'). |
|
355 | + Console::text($error, 'lightyellow'). |
|
356 | 356 | Console::text('', 'white') |
357 | 357 | ); |
358 | 358 | Console::log(); |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | */ |
373 | 373 | protected static function validate(bool $condition, string $message, bool $print = true) |
374 | 374 | { |
375 | - if ( !$condition ){ |
|
375 | + if (!$condition) { |
|
376 | 376 | if ($print && self::isDefaultOuput()) { |
377 | 377 | Console::log(); |
378 | 378 | self::error($message); |
@@ -396,10 +396,10 @@ discard block |
||
396 | 396 | */ |
397 | 397 | protected static function getNumericParameter(array $arguments, string $shortArg, string $longArg, int $defaultValue) |
398 | 398 | { |
399 | - if (self::inArguments($arguments,$shortArg, $longArg)){ |
|
400 | - $val = self::getArgumentValue($arguments,$shortArg, $longArg); |
|
399 | + if (self::inArguments($arguments, $shortArg, $longArg)) { |
|
400 | + $val = self::getArgumentValue($arguments, $shortArg, $longArg); |
|
401 | 401 | |
402 | - if (!is_numeric($val)){ |
|
402 | + if (!is_numeric($val)) { |
|
403 | 403 | self::error("Invalid parameter: $longArg must be a numeric value."); |
404 | 404 | self::printFooter(); |
405 | 405 | Program::exit(1); |