@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | protected static function printTempMessage() |
| 82 | 82 | { |
| 83 | 83 | if (self::isDefaultOuput()) { |
| 84 | - Console::reLog(Console::text(' ? ', 'green') . Console::text('waiting for api response', 'white') . Console::text(' ... ', 'green')); |
|
| 84 | + Console::reLog(Console::text(' ? ', 'green').Console::text('waiting for api response', 'white').Console::text(' ... ', 'green')); |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | self::printLogo(); |
| 140 | 140 | |
| 141 | 141 | Console::log(); |
| 142 | - Console::log(Console::text(' Kristuff/AbuseIPDB Client version: ', 'darkgray') . Console::text(AbuseIPDBClient::VERSION, 'lightgray')); |
|
| 143 | - Console::log(Console::text(' Kristuff/AbuseIPDB Core version: ', 'darkgray') . Console::text(ApiHandler::VERSION, 'lightgray')); |
|
| 142 | + Console::log(Console::text(' Kristuff/AbuseIPDB Client version: ', 'darkgray').Console::text(AbuseIPDBClient::VERSION, 'lightgray')); |
|
| 143 | + Console::log(Console::text(' Kristuff/AbuseIPDB Core version: ', 'darkgray').Console::text(ApiHandler::VERSION, 'lightgray')); |
|
| 144 | 144 | Console::log(Console::text(' --------------------------------------------------', 'darkgray')); |
| 145 | 145 | Console::log(Console::text(' Released under the MIT licence', 'darkgray')); |
| 146 | - Console::log(Console::text(' Made with ', 'darkgray') . Console::text('♥', 'red') . Console::text(' in France', 'darkgray')); |
|
| 146 | + Console::log(Console::text(' Made with ', 'darkgray').Console::text('♥', 'red').Console::text(' in France', 'darkgray')); |
|
| 147 | 147 | Console::log( |
| 148 | 148 | Console::text(' © 2020-2021 Kristuff (', 'darkgray'). |
| 149 | 149 | Console::text('https://github.com/kristuff', 'darkgray', 'underlined'). |
@@ -165,8 +165,8 @@ discard block |
||
| 165 | 165 | { |
| 166 | 166 | if (self::isDefaultOuput()) { |
| 167 | 167 | Console::log(); |
| 168 | - Console::log( Console::text(' Kristuff\AbuseIPDB ', 'darkgray') . Console::text(' ' . AbuseIPDBClient::VERSION . ' ', 'white', 'blue')); |
|
| 169 | - Console::log(Console::text(' Made with ', 'darkgray') . Console::text('♥', 'red') . Console::text(' in France', 'darkgray')); |
|
| 168 | + Console::log(Console::text(' Kristuff\AbuseIPDB ', 'darkgray').Console::text(' '.AbuseIPDBClient::VERSION.' ', 'white', 'blue')); |
|
| 169 | + Console::log(Console::text(' Made with ', 'darkgray').Console::text('♥', 'red').Console::text(' in France', 'darkgray')); |
|
| 170 | 170 | Console::log(' © 2020-2021 Kristuff', 'darkgray'); |
| 171 | 171 | Console::log(); |
| 172 | 172 | } |
@@ -183,19 +183,19 @@ discard block |
||
| 183 | 183 | protected static function printFooter(string $requestTime = '') |
| 184 | 184 | { |
| 185 | 185 | if (self::isDefaultOuput()) { |
| 186 | - if (!empty($requestTime)){ |
|
| 186 | + if (!empty($requestTime)) { |
|
| 187 | 187 | $date_utc = new \DateTime("now", new \DateTimeZone("UTC")); |
| 188 | 188 | Console::log( |
| 189 | - Console::text(' Request time: ', 'darkgray') . Console::text($requestTime . 's', 'lightgray'). |
|
| 190 | - Console::text(' | UTC time: ', 'darkgray') . Console::text($date_utc->format('Y-m-d H:i:s'), 'lightgray') |
|
| 189 | + Console::text(' Request time: ', 'darkgray').Console::text($requestTime.'s', 'lightgray'). |
|
| 190 | + Console::text(' | UTC time: ', 'darkgray').Console::text($date_utc->format('Y-m-d H:i:s'), 'lightgray') |
|
| 191 | 191 | ); |
| 192 | 192 | } |
| 193 | 193 | Console::log(Console::text(' ------------------------------------------------------------------------------------------------------', 'darkgray')); |
| 194 | 194 | Console::log( |
| 195 | - Console::text(' Kristuff\AbuseIPDB ', 'darkgray') . |
|
| 196 | - Console::text(AbuseIPDBClient::VERSION, 'lightgray') . |
|
| 197 | - Console::text(' | Made with ', 'darkgray') . |
|
| 198 | - Console::text('♥', 'red') . |
|
| 195 | + Console::text(' Kristuff\AbuseIPDB ', 'darkgray'). |
|
| 196 | + Console::text(AbuseIPDBClient::VERSION, 'lightgray'). |
|
| 197 | + Console::text(' | Made with ', 'darkgray'). |
|
| 198 | + Console::text('♥', 'red'). |
|
| 199 | 199 | Console::text(' in France | © 2020-2021 Kristuff (https://github.com/kristuff)', 'darkgray') |
| 200 | 200 | ); |
| 201 | 201 | Console::log(); |
@@ -214,9 +214,9 @@ discard block |
||
| 214 | 214 | { |
| 215 | 215 | |
| 216 | 216 | // do not print null/blank values |
| 217 | - if (isset($value)){ |
|
| 218 | - $line = Console::text($text, 'white') . Console::text($value, $foregroundColor, $backgroundColor); |
|
| 219 | - if ($print && self::isDefaultOuput()){ |
|
| 217 | + if (isset($value)) { |
|
| 218 | + $line = Console::text($text, 'white').Console::text($value, $foregroundColor, $backgroundColor); |
|
| 219 | + if ($print && self::isDefaultOuput()) { |
|
| 220 | 220 | Console::log($line); |
| 221 | 221 | } |
| 222 | 222 | return $line; |
@@ -240,16 +240,16 @@ discard block |
||
| 240 | 240 | $scoreforegroundColor = 'white'; |
| 241 | 241 | $scoreBackgroundColor = 'green'; |
| 242 | 242 | |
| 243 | - if (intval($score) > 0 ){ |
|
| 243 | + if (intval($score) > 0) { |
|
| 244 | 244 | $scoreforegroundColor = 'black'; |
| 245 | 245 | $scoreBackgroundColor = 'yellow'; |
| 246 | 246 | } |
| 247 | - if (intval($score) > 50 ){ |
|
| 247 | + if (intval($score) > 50) { |
|
| 248 | 248 | $scoreforegroundColor = 'white'; |
| 249 | 249 | $scoreBackgroundColor = 'red'; |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - $badge = str_pad($score, 3, ' ',STR_PAD_LEFT); |
|
| 252 | + $badge = str_pad($score, 3, ' ', STR_PAD_LEFT); |
|
| 253 | 253 | return Console::text($padding.$badge.$padding, $scoreforegroundColor, $scoreBackgroundColor); |
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | \ No newline at end of file |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | */ |
| 172 | 172 | protected static function getNumericParameter(array $arguments, string $shortArg, string $longArg, int $defaultValue) |
| 173 | 173 | { |
| 174 | - if (self::inArguments($arguments,$shortArg, $longArg)){ |
|
| 174 | + if (self::inArguments($arguments,$shortArg, $longArg)){ |
|
| 175 | 175 | $val = self::getArgumentValue($arguments,$shortArg, $longArg); |
| 176 | 176 | |
| 177 | 177 | if (!is_numeric($val)){ |
@@ -185,14 +185,14 @@ discard block |
||
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
| 188 | - * Check and print errors in API response. Null response object is considered as no errors |
|
| 189 | - * |
|
| 190 | - * @access protected |
|
| 191 | - * @static |
|
| 192 | - * @param object $response |
|
| 193 | - * |
|
| 194 | - * @return void |
|
| 195 | - */ |
|
| 188 | + * Check and print errors in API response. Null response object is considered as no errors |
|
| 189 | + * |
|
| 190 | + * @access protected |
|
| 191 | + * @static |
|
| 192 | + * @param object $response |
|
| 193 | + * |
|
| 194 | + * @return void |
|
| 195 | + */ |
|
| 196 | 196 | protected static function printPlainTextErrors(object $response) |
| 197 | 197 | { |
| 198 | 198 | foreach ($response->errors as $err){ |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * |
| 40 | 40 | * @return bool |
| 41 | 41 | */ |
| 42 | - protected static function hasErrors(object $response, bool $checkForEmpty = true ) |
|
| 42 | + protected static function hasErrors(object $response, bool $checkForEmpty = true) |
|
| 43 | 43 | { |
| 44 | 44 | return $checkForEmpty ? self::parseErrors($response) || self::checkForEmpty($response) : self::parseErrors($response); |
| 45 | 45 | } |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | private static function parseErrors(object $response) |
| 58 | 58 | { |
| 59 | - if (isset($response) && isset($response->errors)){ |
|
| 60 | - switch (self::$outputFormat){ |
|
| 59 | + if (isset($response) && isset($response->errors)) { |
|
| 60 | + switch (self::$outputFormat) { |
|
| 61 | 61 | case self::OUTPUT_DEFAULT: |
| 62 | 62 | self::printFormattedErrors($response); |
| 63 | 63 | break; |
@@ -86,24 +86,24 @@ discard block |
||
| 86 | 86 | protected static function printFormattedErrors(object $response) |
| 87 | 87 | { |
| 88 | 88 | // top error badge |
| 89 | - Console::log(' ' . Console::text(' ERROR ','white', 'red')); |
|
| 89 | + Console::log(' '.Console::text(' ERROR ', 'white', 'red')); |
|
| 90 | 90 | |
| 91 | 91 | $num = 0; |
| 92 | 92 | // errors is an array, could have more than one error.. |
| 93 | - foreach ($response->errors as $err){ |
|
| 93 | + foreach ($response->errors as $err) { |
|
| 94 | 94 | $num++; |
| 95 | 95 | |
| 96 | - Console::log(Console::text(' ✗', 'red') . self::printResult(' Number: ', $num, 'lightyellow','', false)); |
|
| 97 | - self::printResult(' Status: ', $err->status ?? null, 'lightyellow',''); |
|
| 96 | + Console::log(Console::text(' ✗', 'red').self::printResult(' Number: ', $num, 'lightyellow', '', false)); |
|
| 97 | + self::printResult(' Status: ', $err->status ?? null, 'lightyellow', ''); |
|
| 98 | 98 | |
| 99 | - if (!empty($err->source) && !empty($err->source->parameter)){ |
|
| 99 | + if (!empty($err->source) && !empty($err->source->parameter)) { |
|
| 100 | 100 | self::printResult(' Parameter: ', $err->source->parameter, 'lightyellow'); |
| 101 | 101 | } |
| 102 | 102 | self::printResult(' Title: ', $err->title ?? null, 'lightyellow'); |
| 103 | 103 | self::printResult(' Detail: ', $err->detail ?? null, 'lightyellow'); |
| 104 | 104 | |
| 105 | 105 | // separate errors |
| 106 | - if (count($response->errors) > 1){ |
|
| 106 | + if (count($response->errors) > 1) { |
|
| 107 | 107 | Console::log(' ---'); |
| 108 | 108 | } |
| 109 | 109 | } |
@@ -123,11 +123,11 @@ discard block |
||
| 123 | 123 | { |
| 124 | 124 | if (self::isDefaultOuput()) { |
| 125 | 125 | // ✗ |
| 126 | - Console::log(' ' . Console::text(' ERROR ','white', 'red')); |
|
| 126 | + Console::log(' '.Console::text(' ERROR ', 'white', 'red')); |
|
| 127 | 127 | Console::log( |
| 128 | - Console::text(' ✗', 'red') . |
|
| 129 | - Console::text(' Detail: ', 'white') . |
|
| 130 | - Console::text($error, 'lightyellow') . |
|
| 128 | + Console::text(' ✗', 'red'). |
|
| 129 | + Console::text(' Detail: ', 'white'). |
|
| 130 | + Console::text($error, 'lightyellow'). |
|
| 131 | 131 | Console::text('', 'white') |
| 132 | 132 | ); |
| 133 | 133 | Console::log(); |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | protected static function validate(bool $condition, string $message, bool $print = true) |
| 149 | 149 | { |
| 150 | - if ( !$condition ){ |
|
| 150 | + if (!$condition) { |
|
| 151 | 151 | if ($print && self::isDefaultOuput()) { |
| 152 | 152 | Console::log(); |
| 153 | 153 | self::error($message); |
@@ -171,10 +171,10 @@ discard block |
||
| 171 | 171 | */ |
| 172 | 172 | protected static function getNumericParameter(array $arguments, string $shortArg, string $longArg, int $defaultValue) |
| 173 | 173 | { |
| 174 | - if (self::inArguments($arguments,$shortArg, $longArg)){ |
|
| 175 | - $val = self::getArgumentValue($arguments,$shortArg, $longArg); |
|
| 174 | + if (self::inArguments($arguments, $shortArg, $longArg)) { |
|
| 175 | + $val = self::getArgumentValue($arguments, $shortArg, $longArg); |
|
| 176 | 176 | |
| 177 | - if (!is_numeric($val)){ |
|
| 177 | + if (!is_numeric($val)) { |
|
| 178 | 178 | self::error("Invalid parameter: $longArg must be a numeric value."); |
| 179 | 179 | self::printFooter(); |
| 180 | 180 | Program::exit(1); |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | */ |
| 196 | 196 | protected static function printPlainTextErrors(object $response) |
| 197 | 197 | { |
| 198 | - foreach ($response->errors as $err){ |
|
| 198 | + foreach ($response->errors as $err) { |
|
| 199 | 199 | $text = 'Error: '; |
| 200 | 200 | $text .= self::getErrorDetail($err, 'title'); |
| 201 | 201 | $text .= self::getErrorDetail($err, 'statuts'); |
@@ -218,11 +218,11 @@ discard block |
||
| 218 | 218 | */ |
| 219 | 219 | private static function getErrorDetail(object $error, string $field, ?string $parent = null) |
| 220 | 220 | { |
| 221 | - if (!empty($parent)){ |
|
| 222 | - return !empty($error->$parent) && !empty($error->$parent->$field) ? ' ' . $field . ': ' . $error->$parent->$field : ''; |
|
| 221 | + if (!empty($parent)) { |
|
| 222 | + return !empty($error->$parent) && !empty($error->$parent->$field) ? ' '.$field.': '.$error->$parent->$field : ''; |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - return !empty($error->$field) ? ' ' . $field . ': ' . $error->$field : ''; |
|
| 225 | + return !empty($error->$field) ? ' '.$field.': '.$error->$field : ''; |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | protected static function checkForEmpty(object $response) |
| 238 | 238 | { |
| 239 | 239 | // check for empty response ? |
| 240 | - if ( empty($response) || empty($response->data) ){ |
|
| 240 | + if (empty($response) || empty($response->data)) { |
|
| 241 | 241 | self::error('An unexpected error occurred.'); |
| 242 | 242 | return true; |
| 243 | 243 | } |