| @@ -91,6 +91,6 @@ | ||
| 91 | 91 | */ | 
| 92 | 92 | protected static function inArguments($arguments, $shortArg, $longArg) | 
| 93 | 93 |      { | 
| 94 | - return array_key_exists($shortArg, $arguments) || array_key_exists($longArg, $arguments); | |
| 94 | + return array_key_exists($shortArg, $arguments) || array_key_exists($longArg, $arguments); | |
| 95 | 95 | } | 
| 96 | 96 | } | 
| 97 | 97 | \ No newline at end of file | 
| @@ -56,7 +56,7 @@ discard block | ||
| 56 | 56 | protected static function getScoreColor($score) | 
| 57 | 57 |      { | 
| 58 | 58 | $score = intval($score); | 
| 59 | - return $score > 50 ? 'lightred' : ($score > 0 ? 'yellow' : 'green') ; | |
| 59 | + return $score > 50 ? 'lightred' : ($score > 0 ? 'yellow' : 'green'); | |
| 60 | 60 | } | 
| 61 | 61 | |
| 62 | 62 | |
| @@ -74,8 +74,7 @@ discard block | ||
| 74 | 74 | */ | 
| 75 | 75 | protected static function getArgumentValue(array $arguments, string $shortArg, string $longArg) | 
| 76 | 76 |      { | 
| 77 | - return (array_key_exists($shortArg, $arguments) ? $arguments[$shortArg] : | |
| 78 | - (array_key_exists($longArg, $arguments) ? $arguments[$longArg] : '')); | |
| 77 | + return (array_key_exists($shortArg, $arguments) ? $arguments[$shortArg] : (array_key_exists($longArg, $arguments) ? $arguments[$longArg] : '')); | |
| 79 | 78 | } | 
| 80 | 79 | |
| 81 | 80 | /** | 
| @@ -84,8 +84,8 @@ discard block | ||
| 84 | 84 | // required at least one valid argument | 
| 85 | 85 | self::validate( !empty($arguments), 'No valid arguments given. Run abuseipdb --help to get help.'); | 
| 86 | 86 | |
| 87 | - // prints help ? | |
| 88 | -         if (self::inArguments($arguments, 'h', 'help')){ | |
| 87 | + // prints help ? | |
| 88 | +            if (self::inArguments($arguments, 'h', 'help')){ | |
| 89 | 89 | self::printBanner(); | 
| 90 | 90 | self::printHelp(); | 
| 91 | 91 | exit(0); | 
| @@ -188,10 +188,10 @@ discard block | ||
| 188 | 188 | * | 
| 189 | 189 | * @access public | 
| 190 | 190 | * @static | 
| 191 | - * @param string $filePath The file's full path | |
| 192 | - * @param bool $throwError Throw error on true or silent process. Default is true | |
| 191 | + * @param string $filePath The file's full path | |
| 192 | + * @param bool $throwError Throw error on true or silent process. Default is true | |
| 193 | 193 | * | 
| 194 | - * @return object|null | |
| 194 | + * @return object|null | |
| 195 | 195 | * @throws \Exception | 
| 196 | 196 | * @throws \LogicException | 
| 197 | 197 | */ | 
| @@ -199,10 +199,10 @@ discard block | ||
| 199 | 199 |      { | 
| 200 | 200 | // check file exists | 
| 201 | 201 |          if (!file_exists($filePath) || !is_file($filePath)){ | 
| 202 | -           if ($throwError) { | |
| 202 | +            if ($throwError) { | |
| 203 | 203 |                  throw new \Exception('Config file not found'); | 
| 204 | - } | |
| 205 | - return null; | |
| 204 | + } | |
| 205 | + return null; | |
| 206 | 206 | } | 
| 207 | 207 | |
| 208 | 208 | // get and parse content | 
| @@ -272,38 +272,38 @@ discard block | ||
| 272 | 272 |      { | 
| 273 | 273 |          Console::log(' ' . Console::text('SYNOPSIS:', 'white', 'underline'));  | 
| 274 | 274 |          Console::log(' ' . Console::text('    abuseipdb -C ') .  | 
| 275 | -                           Console::text('ip', 'yellow') .  | |
| 276 | -                           Console::text(' [-d ') .  | |
| 277 | -                           Console::text('days', 'yellow') .  | |
| 278 | -                           Console::text('] [-v] [-l ') .  | |
| 279 | -                           Console::text('limit', 'yellow') .  | |
| 280 | -                           Console::text(']'));  | |
| 275 | +                            Console::text('ip', 'yellow') .  | |
| 276 | +                            Console::text(' [-d ') .  | |
| 277 | +                            Console::text('days', 'yellow') .  | |
| 278 | +                            Console::text('] [-v] [-l ') .  | |
| 279 | +                            Console::text('limit', 'yellow') .  | |
| 280 | +                            Console::text(']'));  | |
| 281 | 281 | |
| 282 | 282 |          Console::log(' ' . Console::text('    abuseipdb -K ') .  | 
| 283 | -                           Console::text('network', 'yellow') .  | |
| 284 | -                           Console::text(' [-d ') .  | |
| 285 | -                           Console::text('days', 'yellow') .  | |
| 286 | -                           Console::text(']'));  | |
| 283 | +                            Console::text('network', 'yellow') .  | |
| 284 | +                            Console::text(' [-d ') .  | |
| 285 | +                            Console::text('days', 'yellow') .  | |
| 286 | +                            Console::text(']'));  | |
| 287 | 287 | |
| 288 | 288 |          Console::log(' ' . Console::text('    abuseipdb -R ' . | 
| 289 | -                           Console::text('ip', 'yellow') . ' -c ' . | |
| 290 | -                           Console::text('categories', 'yellow') . ' -m ' . | |
| 291 | -                           Console::text('message', 'yellow')));  | |
| 289 | +                            Console::text('ip', 'yellow') . ' -c ' . | |
| 290 | +                            Console::text('categories', 'yellow') . ' -m ' . | |
| 291 | +                            Console::text('message', 'yellow')));  | |
| 292 | 292 | |
| 293 | 293 |          Console::log(' ' . Console::text('    abuseipdb -V ' . | 
| 294 | -                           Console::text('path', 'yellow'))); | |
| 294 | +                            Console::text('path', 'yellow'))); | |
| 295 | 295 | |
| 296 | 296 |          Console::log(' ' . Console::text('    abuseipdb -E ' . | 
| 297 | -                           Console::text('ip', 'yellow'))); | |
| 297 | +                            Console::text('ip', 'yellow'))); | |
| 298 | 298 | |
| 299 | 299 |          Console::log(' ' . Console::text('    abuseipdb -B ') .  | 
| 300 | -                           Console::text('[-l ') .  | |
| 301 | -                           Console::text('limit', 'yellow') .  | |
| 302 | -                           Console::text('] [-s ') .  | |
| 303 | -                           Console::text('score', 'yellow') .  | |
| 304 | -                           Console::text('] [-p ') .  | |
| 305 | -                           Console::text('', 'yellow') .  | |
| 306 | -                           Console::text(']'));  | |
| 300 | +                            Console::text('[-l ') .  | |
| 301 | +                            Console::text('limit', 'yellow') .  | |
| 302 | +                            Console::text('] [-s ') .  | |
| 303 | +                            Console::text('score', 'yellow') .  | |
| 304 | +                            Console::text('] [-p ') .  | |
| 305 | +                            Console::text('', 'yellow') .  | |
| 306 | +                            Console::text(']'));  | |
| 307 | 307 | |
| 308 | 308 |          Console::log(' ' . Console::text('    abuseipdb -L ')); | 
| 309 | 309 |          Console::log(' ' . Console::text('    abuseipdb -G ')); | 
| @@ -859,7 +859,7 @@ discard block | ||
| 859 | 859 | |
| 860 | 860 |                      $line  = Console::text('    →', $defaultColor); | 
| 861 | 861 |                      $line .= self::printResult(' reported at: ', self::getDate($lastReport->reportedAt), $defaultColor, '', false); | 
| 862 | -              //    $line .= self::printResult(' by user: ', $lastReport->reporterId, $defaultColor, '', false); | |
| 862 | +                //    $line .= self::printResult(' by user: ', $lastReport->reporterId, $defaultColor, '', false); | |
| 863 | 863 |                      if (isset($lastReport->reporterCountryCode) && isset($lastReport->reporterCountryName)){ | 
| 864 | 864 |                          $line .= Console::text(' from: ', 'white'); | 
| 865 | 865 |                          $line .= self::printResult('', $lastReport->reporterCountryCode, $defaultColor, '', false); | 
| @@ -38,7 +38,7 @@ discard block | ||
| 38 | 38 | /** | 
| 39 | 39 | * @var string | 
| 40 | 40 | */ | 
| 41 | - const LONG_ARGUMENTS = ['config', 'list', 'blacklist', 'check:', 'check-block:', 'days:', 'report:', 'categories:', 'message:', 'limit:', 'plaintext', 'clear:','bulk-report:', 'help', 'verbose', 'score:']; | |
| 41 | + const LONG_ARGUMENTS = ['config', 'list', 'blacklist', 'check:', 'check-block:', 'days:', 'report:', 'categories:', 'message:', 'limit:', 'plaintext', 'clear:', 'bulk-report:', 'help', 'verbose', 'score:']; | |
| 42 | 42 | |
| 43 | 43 | /** | 
| 44 | 44 | * @var string $version | 
| @@ -53,7 +53,7 @@ discard block | ||
| 53 | 53 | /** | 
| 54 | 54 | * @var string $keyPath | 
| 55 | 55 | */ | 
| 56 | - private static $keyPath = __DIR__ .'/../config/key.json'; | |
| 56 | + private static $keyPath = __DIR__.'/../config/key.json'; | |
| 57 | 57 | |
| 58 | 58 | /** | 
| 59 | 59 | * The entry point of our app | 
| @@ -67,10 +67,10 @@ discard block | ||
| 67 | 67 | public static function start($arguments) | 
| 68 | 68 |      { | 
| 69 | 69 | // get key path from current script location (supposed in a bin folder) | 
| 70 | - self::$keyPath = dirname(get_included_files()[0]) . '/../config/key.json'; | |
| 70 | + self::$keyPath = dirname(get_included_files()[0]).'/../config/key.json'; | |
| 71 | 71 | |
| 72 | 72 | // check for install | 
| 73 | - self::validate( self::checkForInstall(), 'Key file missing.'); | |
| 73 | + self::validate(self::checkForInstall(), 'Key file missing.'); | |
| 74 | 74 | |
| 75 | 75 | // Create a new instance of \ApiHandler with the given config file | 
| 76 | 76 |          try { | 
| @@ -82,59 +82,59 @@ discard block | ||
| 82 | 82 | } | 
| 83 | 83 | |
| 84 | 84 | // required at least one valid argument | 
| 85 | - self::validate( !empty($arguments), 'No valid arguments given. Run abuseipdb --help to get help.'); | |
| 85 | + self::validate(!empty($arguments), 'No valid arguments given. Run abuseipdb --help to get help.'); | |
| 86 | 86 | |
| 87 | 87 | // prints help ? | 
| 88 | -         if (self::inArguments($arguments, 'h', 'help')){ | |
| 88 | +         if (self::inArguments($arguments, 'h', 'help')) { | |
| 89 | 89 | self::printBanner(); | 
| 90 | 90 | self::printHelp(); | 
| 91 | 91 | exit(0); | 
| 92 | 92 | } | 
| 93 | 93 | |
| 94 | 94 | // prints config ? | 
| 95 | -        if (self::inArguments($arguments, 'G', 'config')){ | |
| 95 | +        if (self::inArguments($arguments, 'G', 'config')) { | |
| 96 | 96 | self::printConfig(); | 
| 97 | 97 | exit(0); | 
| 98 | 98 | } | 
| 99 | 99 | |
| 100 | 100 | // prints catgeories ? | 
| 101 | -        if (self::inArguments($arguments, 'L', 'list')){ | |
| 101 | +        if (self::inArguments($arguments, 'L', 'list')) { | |
| 102 | 102 | self::printCategories(); | 
| 103 | 103 | exit(0); | 
| 104 | 104 | } | 
| 105 | 105 | |
| 106 | 106 | // check request ? | 
| 107 | -        if (self::inArguments($arguments, 'C', 'check')){ | |
| 107 | +        if (self::inArguments($arguments, 'C', 'check')) { | |
| 108 | 108 | self::checkIP($arguments); | 
| 109 | 109 | exit(0); | 
| 110 | 110 | } | 
| 111 | 111 | |
| 112 | 112 | // check-block request ? | 
| 113 | -        if (self::inArguments($arguments, 'K', 'check-block')){ | |
| 113 | +        if (self::inArguments($arguments, 'K', 'check-block')) { | |
| 114 | 114 | self::checkBlock($arguments); | 
| 115 | 115 | exit(0); | 
| 116 | 116 | } | 
| 117 | 117 | |
| 118 | 118 | // report request ? | 
| 119 | -        if (self::inArguments($arguments, 'R', 'report')){ | |
| 119 | +        if (self::inArguments($arguments, 'R', 'report')) { | |
| 120 | 120 | self::reportIP($arguments); | 
| 121 | 121 | exit(0); | 
| 122 | 122 | } | 
| 123 | 123 | |
| 124 | 124 | // report request ? | 
| 125 | -        if (self::inArguments($arguments, 'V', 'bulk-report')){ | |
| 125 | +        if (self::inArguments($arguments, 'V', 'bulk-report')) { | |
| 126 | 126 | self::bulkReport($arguments); | 
| 127 | 127 | exit(0); | 
| 128 | 128 | } | 
| 129 | 129 | |
| 130 | 130 | // report request ? | 
| 131 | -        if (self::inArguments($arguments, 'B', 'blacklist')){ | |
| 131 | +        if (self::inArguments($arguments, 'B', 'blacklist')) { | |
| 132 | 132 | self::getBlacklist($arguments); | 
| 133 | 133 | exit(0); | 
| 134 | 134 | } | 
| 135 | 135 | |
| 136 | 136 | // report request ? | 
| 137 | -        if (self::inArguments($arguments, 'E', 'clear')){ | |
| 137 | +        if (self::inArguments($arguments, 'E', 'clear')) { | |
| 138 | 138 | self::clearIP($arguments); | 
| 139 | 139 | exit(0); | 
| 140 | 140 | } | 
| @@ -160,21 +160,21 @@ discard block | ||
| 160 | 160 | public static function fromConfigFile(string $configPath) | 
| 161 | 161 |      { | 
| 162 | 162 | // check file exists | 
| 163 | -        if (!file_exists($configPath) || !is_file($configPath)){ | |
| 164 | -            throw new \InvalidArgumentException('The file [' . $configPath . '] does not exist.'); | |
| 163 | +        if (!file_exists($configPath) || !is_file($configPath)) { | |
| 164 | +            throw new \InvalidArgumentException('The file ['.$configPath.'] does not exist.'); | |
| 165 | 165 | } | 
| 166 | 166 | |
| 167 | 167 | // check file is readable | 
| 168 | -        if (!is_readable($configPath)){ | |
| 169 | -            throw new InvalidPermissionException('The file [' . $configPath . '] is not readable.'); | |
| 168 | +        if (!is_readable($configPath)) { | |
| 169 | +            throw new InvalidPermissionException('The file ['.$configPath.'] is not readable.'); | |
| 170 | 170 | } | 
| 171 | 171 | |
| 172 | 172 | $keyConfig = self::loadJsonFile($configPath); | 
| 173 | 173 | $selfIps = []; | 
| 174 | 174 | |
| 175 | 175 | // Look for other optional config files in the same directory | 
| 176 | - $selfIpsConfigPath = pathinfo($configPath, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR . 'self_ips.json'; | |
| 177 | -        if (file_exists($selfIpsConfigPath)){ | |
| 176 | + $selfIpsConfigPath = pathinfo($configPath, PATHINFO_DIRNAME).DIRECTORY_SEPARATOR.'self_ips.json'; | |
| 177 | +        if (file_exists($selfIpsConfigPath)) { | |
| 178 | 178 | $selfIps = self::loadJsonFile($selfIpsConfigPath)->self_ips; | 
| 179 | 179 | } | 
| 180 | 180 | |
| @@ -198,7 +198,7 @@ discard block | ||
| 198 | 198 | protected static function loadJsonFile(string $filePath, bool $throwError = true) | 
| 199 | 199 |      { | 
| 200 | 200 | // check file exists | 
| 201 | -        if (!file_exists($filePath) || !is_file($filePath)){ | |
| 201 | +        if (!file_exists($filePath) || !is_file($filePath)) { | |
| 202 | 202 |             if ($throwError) { | 
| 203 | 203 |                  throw new \Exception('Config file not found'); | 
| 204 | 204 | } | 
| @@ -234,23 +234,23 @@ discard block | ||
| 234 | 234 | // not installed | 
| 235 | 235 | self::printBanner(); | 
| 236 | 236 |          Console::log(' Your config key file was not found. Do you want to create it? ', 'white'); | 
| 237 | -        $create =  Console::ask(' Press Y/y to create a config key file: ', 'white'); | |
| 237 | +        $create = Console::ask(' Press Y/y to create a config key file: ', 'white'); | |
| 238 | 238 | |
| 239 | 239 |          if ($create == 'Y' || $create == 'y') { | 
| 240 | -            $key =     Console::ask(' - Please enter your api key: ', 'white'); | |
| 241 | -            $create =  Console::ask(' A config file will be created in config/ directory. Press Y/y to continue: ', 'white'); | |
| 240 | +            $key = Console::ask(' - Please enter your api key: ', 'white'); | |
| 241 | +            $create = Console::ask(' A config file will be created in config/ directory. Press Y/y to continue: ', 'white'); | |
| 242 | 242 | |
| 243 | 243 |              if ($create == 'Y' || $create == 'y') { | 
| 244 | 244 | $data = json_encode(['api_key' => $key]); | 
| 245 | 245 | |
| 246 | -                if (file_put_contents(self::$keyPath, $data, LOCK_EX) === false){ | |
| 246 | +                if (file_put_contents(self::$keyPath, $data, LOCK_EX) === false) { | |
| 247 | 247 |                      self::error('An error occured during writing config file. Make sure to give the appropriate permissions do the config directory.'); | 
| 248 | 248 | return false; | 
| 249 | 249 | } | 
| 250 | 250 | |
| 251 | 251 | // successfull. print message and exit to prevent errors with no arguments | 
| 252 | 252 | Console::log(); | 
| 253 | -                Console::log(Console::text('  ✓ ', 'green') . Console::text('Your config file has been successfully created.', 'white')); | |
| 253 | +                Console::log(Console::text('  ✓ ', 'green').Console::text('Your config file has been successfully created.', 'white')); | |
| 254 | 254 |                  Console::log('    You can now use abuseipdb.', 'white'); | 
| 255 | 255 | Console::log(); | 
| 256 | 256 | exit(0); | 
| @@ -270,47 +270,47 @@ discard block | ||
| 270 | 270 | */ | 
| 271 | 271 | protected static function printHelp() | 
| 272 | 272 |      { | 
| 273 | -        Console::log(' ' . Console::text('SYNOPSIS:', 'white', 'underline'));  | |
| 274 | -        Console::log(' ' . Console::text('    abuseipdb -C ') .  | |
| 275 | -                           Console::text('ip', 'yellow') .  | |
| 276 | -                           Console::text(' [-d ') .  | |
| 277 | -                           Console::text('days', 'yellow') .  | |
| 278 | -                           Console::text('] [-v] [-l ') .  | |
| 279 | -                           Console::text('limit', 'yellow') .  | |
| 273 | +        Console::log(' '.Console::text('SYNOPSIS:', 'white', 'underline'));  | |
| 274 | +        Console::log(' '.Console::text('    abuseipdb -C ').  | |
| 275 | +                           Console::text('ip', 'yellow').  | |
| 276 | +                           Console::text(' [-d ').  | |
| 277 | +                           Console::text('days', 'yellow').  | |
| 278 | +                           Console::text('] [-v] [-l ').  | |
| 279 | +                           Console::text('limit', 'yellow').  | |
| 280 | 280 |                             Console::text(']'));  | 
| 281 | 281 | |
| 282 | -        Console::log(' ' . Console::text('    abuseipdb -K ') .  | |
| 283 | -                           Console::text('network', 'yellow') .  | |
| 284 | -                           Console::text(' [-d ') .  | |
| 285 | -                           Console::text('days', 'yellow') .  | |
| 282 | +        Console::log(' '.Console::text('    abuseipdb -K ').  | |
| 283 | +                           Console::text('network', 'yellow').  | |
| 284 | +                           Console::text(' [-d ').  | |
| 285 | +                           Console::text('days', 'yellow').  | |
| 286 | 286 |                             Console::text(']'));  | 
| 287 | 287 | |
| 288 | -        Console::log(' ' . Console::text('    abuseipdb -R ' . | |
| 289 | -                           Console::text('ip', 'yellow') . ' -c ' . | |
| 290 | -                           Console::text('categories', 'yellow') . ' -m ' . | |
| 288 | +        Console::log(' '.Console::text('    abuseipdb -R '. | |
| 289 | +                           Console::text('ip', 'yellow').' -c '. | |
| 290 | +                           Console::text('categories', 'yellow').' -m '. | |
| 291 | 291 |                             Console::text('message', 'yellow')));  | 
| 292 | 292 | |
| 293 | -        Console::log(' ' . Console::text('    abuseipdb -V ' . | |
| 293 | +        Console::log(' '.Console::text('    abuseipdb -V '. | |
| 294 | 294 |                             Console::text('path', 'yellow'))); | 
| 295 | 295 | |
| 296 | -        Console::log(' ' . Console::text('    abuseipdb -E ' . | |
| 296 | +        Console::log(' '.Console::text('    abuseipdb -E '. | |
| 297 | 297 |                             Console::text('ip', 'yellow'))); | 
| 298 | 298 | |
| 299 | -        Console::log(' ' . Console::text('    abuseipdb -B ') .  | |
| 300 | -                           Console::text('[-l ') .  | |
| 301 | -                           Console::text('limit', 'yellow') .  | |
| 302 | -                           Console::text('] [-s ') .  | |
| 303 | -                           Console::text('score', 'yellow') .  | |
| 304 | -                           Console::text('] [-p ') .  | |
| 305 | -                           Console::text('', 'yellow') .  | |
| 299 | +        Console::log(' '.Console::text('    abuseipdb -B ').  | |
| 300 | +                           Console::text('[-l ').  | |
| 301 | +                           Console::text('limit', 'yellow').  | |
| 302 | +                           Console::text('] [-s ').  | |
| 303 | +                           Console::text('score', 'yellow').  | |
| 304 | +                           Console::text('] [-p ').  | |
| 305 | +                           Console::text('', 'yellow').  | |
| 306 | 306 |                             Console::text(']'));  | 
| 307 | 307 | |
| 308 | -        Console::log(' ' . Console::text('    abuseipdb -L ')); | |
| 309 | -        Console::log(' ' . Console::text('    abuseipdb -G ')); | |
| 310 | -        Console::log(' ' . Console::text('    abuseipdb -h ')); | |
| 308 | +        Console::log(' '.Console::text('    abuseipdb -L ')); | |
| 309 | +        Console::log(' '.Console::text('    abuseipdb -G ')); | |
| 310 | +        Console::log(' '.Console::text('    abuseipdb -h ')); | |
| 311 | 311 | |
| 312 | 312 | Console::log(); | 
| 313 | -        Console::log(' ' . Console::text('OPTIONS:', 'white', 'underline'));  | |
| 313 | +        Console::log(' '.Console::text('OPTIONS:', 'white', 'underline'));  | |
| 314 | 314 | Console::log(); | 
| 315 | 315 |          Console::log(Console::text('   -h, --help', 'white'));  | 
| 316 | 316 |          Console::log('       Prints the current help. If given, all next arguments are ignored.', 'lightgray'); | 
| @@ -321,39 +321,39 @@ discard block | ||
| 321 | 321 |          Console::log(Console::text('   -L, --list', 'white'));  | 
| 322 | 322 |          Console::log('       Prints the list report categories. If given, all next arguments are ignored.', 'lightgray'); | 
| 323 | 323 | Console::log(); | 
| 324 | -        Console::log(Console::text('   -C, --check ', 'white') . Console::text('ip', 'yellow', 'underline'));  | |
| 324 | +        Console::log(Console::text('   -C, --check ', 'white').Console::text('ip', 'yellow', 'underline'));  | |
| 325 | 325 |          Console::log('       Performs a check request for the given IP address. A valid IPv4 or IPv6 address is required.', 'lightgray'); | 
| 326 | 326 | Console::log(); | 
| 327 | -        Console::log(Console::text('   -K, --check-block ', 'white') . Console::text('network', 'yellow', 'underline'));  | |
| 327 | +        Console::log(Console::text('   -K, --check-block ', 'white').Console::text('network', 'yellow', 'underline'));  | |
| 328 | 328 |          Console::log('       Performs a check-block request for the given network. A valid subnet (v4 or v6) denoted with ', 'lightgray'); | 
| 329 | 329 |          Console::log('       CIDR notation is required.', 'lightgray'); | 
| 330 | 330 | Console::log(); | 
| 331 | -        Console::log(Console::text('   -d, --days ', 'white') . Console::text('days', 'yellow', 'underline'));  | |
| 331 | +        Console::log(Console::text('   -d, --days ', 'white').Console::text('days', 'yellow', 'underline'));  | |
| 332 | 332 |          Console::log('       For a check or check-block request, defines the maxAgeDays. Min is 1, max is 365, default is 30.', 'lightgray'); | 
| 333 | 333 | Console::log(); | 
| 334 | -        Console::log(Console::text('   -R, --report ', 'white') . Console::text('ip', 'yellow', 'underline'));  | |
| 334 | +        Console::log(Console::text('   -R, --report ', 'white').Console::text('ip', 'yellow', 'underline'));  | |
| 335 | 335 |          Console::log('       Performs a report request for the given IP address. A valid IPv4 or IPv6 address is required.', 'lightgray'); | 
| 336 | 336 | Console::log(); | 
| 337 | -        Console::log(Console::text('   -V, --bulk-report ', 'white') . Console::text('path', 'yellow', 'underline'));  | |
| 337 | +        Console::log(Console::text('   -V, --bulk-report ', 'white').Console::text('path', 'yellow', 'underline'));  | |
| 338 | 338 |          Console::log('       Performs a bulk-report request sending a csv file. A valid file name or full path is required.', 'lightgray'); | 
| 339 | 339 | Console::log(); | 
| 340 | 340 |          Console::log(Console::text('   -E, --clear ', 'white'));  | 
| 341 | 341 |          Console::log('       Remove own reports for the given IP address. A valid IPv4 or IPv6 address is required.', 'lightgray'); | 
| 342 | 342 | Console::log(); | 
| 343 | -        Console::log(Console::text('   -c, --categories ', 'white') . Console::text('categories', 'yellow', 'underline'));  | |
| 343 | +        Console::log(Console::text('   -c, --categories ', 'white').Console::text('categories', 'yellow', 'underline'));  | |
| 344 | 344 |          Console::log('       For a report request, defines the report category(ies). Categories must be separate by a comma.', 'lightgray'); | 
| 345 | 345 |          Console::log('       Some categories cannot be used alone. A category can be represented by its shortname or by its', 'lightgray'); | 
| 346 | -        Console::log(Console::text('       id. Use ','lightgray')  . Console::text('abuseipdb -L', 'white') . Console::text(' to print the categories list.','lightgray')); | |
| 346 | +        Console::log(Console::text('       id. Use ', 'lightgray').Console::text('abuseipdb -L', 'white').Console::text(' to print the categories list.', 'lightgray')); | |
| 347 | 347 | Console::log(); | 
| 348 | -        Console::log(Console::text('   -m, --message ', 'white') . Console::text('message', 'yellow', 'underline'));  | |
| 348 | +        Console::log(Console::text('   -m, --message ', 'white').Console::text('message', 'yellow', 'underline'));  | |
| 349 | 349 |          Console::log('       For a report request, defines the message to send with report. Message is required for all', 'lightgray'); | 
| 350 | 350 |          Console::log('       report requests.', 'lightgray'); | 
| 351 | 351 | Console::log(); | 
| 352 | 352 |          Console::log(Console::text('   -B, --blacklist ', 'white'));  | 
| 353 | 353 |          Console::log('       Performs a blacklist request. Default limit is 1000. This limit can ne changed with the', 'lightgray'); | 
| 354 | -        Console::log('       ' . Console::text('--limit', 'white') . Console::text(' parameter. ', 'lightgray')); | |
| 354 | +        Console::log('       '.Console::text('--limit', 'white').Console::text(' parameter. ', 'lightgray')); | |
| 355 | 355 | Console::log(); | 
| 356 | -        Console::log(Console::text('   -l, --limit ', 'white') . Console::text('limit', 'yellow', 'underline'));  | |
| 356 | +        Console::log(Console::text('   -l, --limit ', 'white').Console::text('limit', 'yellow', 'underline'));  | |
| 357 | 357 |          Console::log('       For a blacklist request, defines the limit.', 'lightgray'); | 
| 358 | 358 |          Console::log('       For a check request with verbose flag, sets the max number of last reports displayed. Default is 10', 'lightgray'); | 
| 359 | 359 |          Console::log('       For a check-block request, sets the max number of IPs displayed. Default is 0 (no limit).', 'lightgray'); | 
| @@ -368,7 +368,7 @@ discard block | ||
| 368 | 368 |          Console::log(Console::text('   -v, --verbose ', 'white'));  | 
| 369 | 369 |          Console::log('       For a check request, display additional fields like the x last reports. This increases ', 'lightgray'); | 
| 370 | 370 |          Console::log(Console::text('       request time and response size. Max number of last reports displayed can be changed with the ', 'lightgray')); | 
| 371 | -        Console::log('       ' . Console::text('--limit', 'white') . Console::text(' parameter. ', 'lightgray')); | |
| 371 | +        Console::log('       '.Console::text('--limit', 'white').Console::text(' parameter. ', 'lightgray')); | |
| 372 | 372 | Console::log(); | 
| 373 | 373 | } | 
| 374 | 374 | |
| @@ -386,11 +386,11 @@ discard block | ||
| 386 | 386 | |
| 387 | 387 |          self::printTitle(Console::text('  ► Current configuration ', 'darkgray')); | 
| 388 | 388 | |
| 389 | -        Console::log(Console::text('  api_key:[', 'white') . Console::text($conf['apiKey'], 'green') . Console::text(']', 'white')); | |
| 389 | +        Console::log(Console::text('  api_key:[', 'white').Console::text($conf['apiKey'], 'green').Console::text(']', 'white')); | |
| 390 | 390 |          Console::log(Console::text('  self_ips:', 'white')); | 
| 391 | 391 | |
| 392 | 392 |          foreach ($conf['selfIps'] as $ip) { | 
| 393 | -            Console::log(Console::text('    [', 'white') . Console::text($ip, 'green') . Console::text(']', 'white'));    | |
| 393 | +            Console::log(Console::text('    [', 'white').Console::text($ip, 'green').Console::text(']', 'white'));    | |
| 394 | 394 | } | 
| 395 | 395 | |
| 396 | 396 | Console::log(); | 
| @@ -411,10 +411,10 @@ discard block | ||
| 411 | 411 | |
| 412 | 412 | $categories = self::$api->getCategories(); | 
| 413 | 413 | $rowHeaders = [ | 
| 414 | -            Console::text('ShortName',      'darkgray') => 15,  | |
| 415 | -            Console::text('Id',             'darkgray') => 2,  | |
| 416 | -            Console::text('Full name',      'darkgray') => 18, | |
| 417 | -            Console::text('Can be alone?',  'darkgray') => 15 | |
| 414 | +            Console::text('ShortName', 'darkgray') => 15,  | |
| 415 | +            Console::text('Id', 'darkgray') => 2,  | |
| 416 | +            Console::text('Full name', 'darkgray') => 18, | |
| 417 | +            Console::text('Can be alone?', 'darkgray') => 15 | |
| 418 | 418 | ]; | 
| 419 | 419 | Console::$verticalSeparator = ' '; | 
| 420 | 420 | Console::$verticalInnerSeparator = ' '; | 
| @@ -424,17 +424,16 @@ discard block | ||
| 424 | 424 | |
| 425 | 425 |          foreach ($categories as $cat) { | 
| 426 | 426 | $id = Console::text($cat[1], 'white'); | 
| 427 | -            $standalone = $cat[3] ? Console::text('✓', 'green') . Console::text(' true ', 'lightgray') :  | |
| 428 | -                                    Console::text('✗', 'red')   . Console::text(' false', 'darkgray'); | |
| 429 | - $shortName = Console::text($cat[0], 'white'); | |
| 430 | - $fullName = Console::text($cat[2], 'lightgray'); | |
| 427 | +            $standalone = $cat[3] ? Console::text('✓', 'green').Console::text(' true ', 'lightgray') : Console::text('✗', 'red').Console::text(' false', 'darkgray'); | |
| 428 | + $shortName = Console::text($cat[0], 'white'); | |
| 429 | + $fullName = Console::text($cat[2], 'lightgray'); | |
| 431 | 430 | |
| 432 | 431 | Console::log( | 
| 433 | 432 | Console::TableRowStart(). | 
| 434 | - Console::TableRowCell( $shortName , 15). | |
| 435 | - Console::TableRowCell( $id , 2, Console::ALIGN_CENTER). | |
| 436 | - Console::TableRowCell( $fullName , 18). | |
| 437 | - Console::TableRowCell( $standalone , 15, Console::ALIGN_CENTER) | |
| 433 | + Console::TableRowCell($shortName, 15). | |
| 434 | + Console::TableRowCell($id, 2, Console::ALIGN_CENTER). | |
| 435 | + Console::TableRowCell($fullName, 18). | |
| 436 | + Console::TableRowCell($standalone, 15, Console::ALIGN_CENTER) | |
| 438 | 437 | ); | 
| 439 | 438 | } | 
| 440 | 439 | //Console::log(Console::tableRowSeparator($rowHeaders), 'darkgray'); | 
| @@ -453,11 +452,11 @@ discard block | ||
| 453 | 452 | */ | 
| 454 | 453 | protected static function reportIP(array $arguments) | 
| 455 | 454 |      { | 
| 456 | - $ip = self::getArgumentValue($arguments,'R', 'report'); | |
| 457 | - $cats = self::getArgumentValue($arguments,'c', 'categories'); | |
| 458 | - $message = self::getArgumentValue($arguments,'m', 'message'); | |
| 455 | + $ip = self::getArgumentValue($arguments, 'R', 'report'); | |
| 456 | + $cats = self::getArgumentValue($arguments, 'c', 'categories'); | |
| 457 | + $message = self::getArgumentValue($arguments, 'm', 'message'); | |
| 459 | 458 | |
| 460 | -        self::printTitle(Console::text('  ► Report IP: ', 'darkgray') . Console::text(escapeshellcmd($ip), 'white')); | |
| 459 | +        self::printTitle(Console::text('  ► Report IP: ', 'darkgray').Console::text(escapeshellcmd($ip), 'white')); | |
| 461 | 460 | self::printTempMessage(); | 
| 462 | 461 | |
| 463 | 462 | // Peforms request | 
| @@ -468,7 +467,7 @@ discard block | ||
| 468 | 467 | self::clearTempMessage(); | 
| 469 | 468 | |
| 470 | 469 | // check for errors / empty response | 
| 471 | -        if (self::printErrors($report)){ | |
| 470 | +        if (self::printErrors($report)) { | |
| 472 | 471 | self::printFooter(); | 
| 473 | 472 | exit(1); | 
| 474 | 473 | } | 
| @@ -477,12 +476,12 @@ discard block | ||
| 477 | 476 | $score = empty($report->data->abuseConfidenceScore) ? 0 : $report->data->abuseConfidenceScore; | 
| 478 | 477 | $scoreColor = self::getScoreColor($score); | 
| 479 | 478 | Console::log( | 
| 480 | -            Console::text('   ✓', 'green') .  | |
| 481 | -            Console::text(' IP: [', 'white') . | |
| 482 | - Console::text($ip, $scoreColor) . | |
| 479 | +            Console::text('   ✓', 'green').  | |
| 480 | +            Console::text(' IP: [', 'white'). | |
| 481 | + Console::text($ip, $scoreColor). | |
| 483 | 482 |              Console::text('] successfully reported', 'white') | 
| 484 | 483 | ); | 
| 485 | -        Console::log(Console::text('     Confidence score: ', 'white') . self::getScoreBadge($score)); | |
| 484 | +        Console::log(Console::text('     Confidence score: ', 'white').self::getScoreBadge($score)); | |
| 486 | 485 | |
| 487 | 486 | Console::log(); | 
| 488 | 487 | self::printFooter($time); | 
| @@ -499,28 +498,28 @@ discard block | ||
| 499 | 498 | */ | 
| 500 | 499 | protected static function bulkReport(array $arguments) | 
| 501 | 500 |      { | 
| 502 | - $fileName = self::getArgumentValue($arguments,'V', 'bulk-report'); | |
| 501 | + $fileName = self::getArgumentValue($arguments, 'V', 'bulk-report'); | |
| 503 | 502 | |
| 504 | -        self::printTitle(Console::text('  ► Bulk report for file: ', 'darkgray') . Console::text(escapeshellcmd($fileName), 'white')); | |
| 503 | +        self::printTitle(Console::text('  ► Bulk report for file: ', 'darkgray').Console::text(escapeshellcmd($fileName), 'white')); | |
| 505 | 504 | self::printTempMessage(); | 
| 506 | 505 | |
| 507 | 506 | // Peforms request | 
| 508 | 507 | $timeStart = microtime(true); | 
| 509 | 508 | $response = self::$api->bulkReport($fileName)->getObject(); | 
| 510 | 509 | $timeEnd = microtime(true); | 
| 511 | - $time = $timeEnd - $timeStart; // request time | |
| 510 | + $time = $timeEnd - $timeStart; // request time | |
| 512 | 511 | self::clearTempMessage(); | 
| 513 | 512 | |
| 514 | 513 | // check for errors / empty response | 
| 515 | -        if (self::printErrors($response)){ | |
| 514 | +        if (self::printErrors($response)) { | |
| 516 | 515 | self::printFooter(); | 
| 517 | 516 | exit(1); | 
| 518 | 517 | } | 
| 519 | 518 | |
| 520 | 519 | // ✓ Done | 
| 521 | 520 | Console::log( | 
| 522 | -            Console::text('   Bulk report for file: [', 'white') . | |
| 523 | - Console::text($fileName, 'lightyellow') . | |
| 521 | +            Console::text('   Bulk report for file: [', 'white'). | |
| 522 | + Console::text($fileName, 'lightyellow'). | |
| 524 | 523 |              Console::text('] done!', 'white') | 
| 525 | 524 | ); | 
| 526 | 525 | |
| @@ -531,14 +530,14 @@ discard block | ||
| 531 | 530 | $savedIcon = $nbSavedReports > 0 ? '✓' : '✗'; | 
| 532 | 531 | $errorIcon = $nbErrorReports > 0 ? '✗' : '✓'; | 
| 533 | 532 | |
| 534 | -        Console::log(Console::text('   ' . $savedIcon, $savedColor) . self::printResult(' Saved reports:    ', $nbSavedReports, $savedColor, '', false)); | |
| 535 | -        Console::log(Console::text('   ' . $errorIcon, $errorColor) . self::printResult(' Invalid reports:  ', $nbErrorReports, $errorColor, '', false)); | |
| 533 | +        Console::log(Console::text('   '.$savedIcon, $savedColor).self::printResult(' Saved reports:    ', $nbSavedReports, $savedColor, '', false)); | |
| 534 | +        Console::log(Console::text('   '.$errorIcon, $errorColor).self::printResult(' Invalid reports:  ', $nbErrorReports, $errorColor, '', false)); | |
| 536 | 535 | |
| 537 | -        if ($nbErrorReports > 0){ | |
| 536 | +        if ($nbErrorReports > 0) { | |
| 538 | 537 | $numberDiplayedReports = 0; | 
| 539 | 538 | $defaultColor = 'lightyellow'; // reset color for last reports | 
| 540 | 539 | |
| 541 | -            foreach ($response->data->invalidReports as $report){ | |
| 540 | +            foreach ($response->data->invalidReports as $report) { | |
| 542 | 541 | $input = $report->input ? escapeshellcmd($report->input) : ''; // in case on blank line, IP is null | 
| 543 | 542 |                  $line  = Console::text('      →', 'red'); | 
| 544 | 543 |                  $line .= self::printResult(' Input:         ', $input, $defaultColor, '', false); | 
| @@ -565,29 +564,29 @@ discard block | ||
| 565 | 564 | */ | 
| 566 | 565 | protected static function clearIP(array $arguments) | 
| 567 | 566 |      { | 
| 568 | - $ip = self::getArgumentValue($arguments,'E', 'clear'); | |
| 567 | + $ip = self::getArgumentValue($arguments, 'E', 'clear'); | |
| 569 | 568 | |
| 570 | -        self::printTitle(Console::text('  ► Clear reports for IP: ', 'darkgray') . Console::text(escapeshellcmd($ip), 'white')); | |
| 569 | +        self::printTitle(Console::text('  ► Clear reports for IP: ', 'darkgray').Console::text(escapeshellcmd($ip), 'white')); | |
| 571 | 570 | |
| 572 | 571 | // Peforms request | 
| 573 | 572 | self::printTempMessage(); | 
| 574 | 573 | $timeStart = microtime(true); // request startime | 
| 575 | 574 | $response = self::$api->clearAddress($ip)->getObject(); | 
| 576 | - $timeEnd = microtime(true); // request end time | |
| 575 | + $timeEnd = microtime(true); // request end time | |
| 577 | 576 | $time = $timeEnd - $timeStart; // request time | 
| 578 | 577 | self::clearTempMessage(); | 
| 579 | 578 | |
| 580 | 579 | // check for errors / empty response | 
| 581 | -        if (self::printErrors($response)){ | |
| 580 | +        if (self::printErrors($response)) { | |
| 582 | 581 | self::printFooter($time); | 
| 583 | 582 | exit(1); | 
| 584 | 583 | } | 
| 585 | 584 | |
| 586 | 585 | // ✓ Done: print deleted report number | 
| 587 | 586 | Console::log( | 
| 588 | -            Console::text('   ✓', 'green') .  | |
| 589 | -            Console::text(' Successfull clear request for IP: [', 'white') . | |
| 590 | - Console::text($ip, 'lightyellow') . | |
| 587 | +            Console::text('   ✓', 'green').  | |
| 588 | +            Console::text(' Successfull clear request for IP: [', 'white'). | |
| 589 | + Console::text($ip, 'lightyellow'). | |
| 591 | 590 |              Console::text(']', 'white') | 
| 592 | 591 | ); | 
| 593 | 592 | |
| @@ -607,42 +606,42 @@ discard block | ||
| 607 | 606 | */ | 
| 608 | 607 | protected static function getBlacklist(array $arguments) | 
| 609 | 608 |      { | 
| 610 | - $plainText = self::inArguments($arguments,'p','plaintext'); | |
| 609 | + $plainText = self::inArguments($arguments, 'p', 'plaintext'); | |
| 611 | 610 | |
| 612 | -        if (!$plainText){ | |
| 611 | +        if (!$plainText) { | |
| 613 | 612 |              self::printTitle(Console::text('  ► Get Blacklist ', 'darkgray')); | 
| 614 | 613 | } | 
| 615 | 614 | |
| 616 | - $limit = self::getNumericParameter($arguments,'l', 'limit', 1000); | |
| 617 | - $scoreMin = self::getNumericParameter($arguments,'s', 'score', 100); | |
| 615 | + $limit = self::getNumericParameter($arguments, 'l', 'limit', 1000); | |
| 616 | + $scoreMin = self::getNumericParameter($arguments, 's', 'score', 100); | |
| 618 | 617 | |
| 619 | -        if (!$plainText){ | |
| 618 | +        if (!$plainText) { | |
| 620 | 619 | self::printTempMessage(); | 
| 621 | 620 | } | 
| 622 | 621 | |
| 623 | 622 | // do request | 
| 624 | - $timeStart = microtime(true); // request startime | |
| 625 | - $response = self::$api->blacklist($limit, $plainText, $scoreMin); // perform request | |
| 626 | - $timeEnd = microtime(true); // request end time | |
| 627 | - $time = $timeEnd - $timeStart; // request time | |
| 623 | + $timeStart = microtime(true); // request startime | |
| 624 | + $response = self::$api->blacklist($limit, $plainText, $scoreMin); // perform request | |
| 625 | + $timeEnd = microtime(true); // request end time | |
| 626 | + $time = $timeEnd - $timeStart; // request time | |
| 628 | 627 | |
| 629 | -        if (!$plainText){ | |
| 628 | +        if (!$plainText) { | |
| 630 | 629 | self::clearTempMessage(); | 
| 631 | 630 | } | 
| 632 | 631 | |
| 633 | 632 | // response could be json on error, while plaintext flag is set | 
| 634 | 633 | $decodedResponse = $response->getObject(); | 
| 635 | 634 | |
| 636 | -        if ($plainText && $response->hasError()){ | |
| 635 | +        if ($plainText && $response->hasError()) { | |
| 637 | 636 | exit(1); | 
| 638 | 637 | } | 
| 639 | 638 | |
| 640 | -        if (!$plainText && self::printErrors($decodedResponse)){ | |
| 639 | +        if (!$plainText && self::printErrors($decodedResponse)) { | |
| 641 | 640 | self::printFooter($time); | 
| 642 | 641 | exit(1); | 
| 643 | 642 | } | 
| 644 | 643 | |
| 645 | -        if ($plainText){ | |
| 644 | +        if ($plainText) { | |
| 646 | 645 | // echo response "as is" | 
| 647 | 646 | Console::log($response->getPlaintext()); | 
| 648 | 647 | |
| @@ -651,7 +650,7 @@ discard block | ||
| 651 | 650 |              self::printResult('  List generated at: ', self::getDate($decodedResponse->meta->generatedAt), 'lightyellow', ''); | 
| 652 | 651 | Console::log(); | 
| 653 | 652 | |
| 654 | -            foreach ($decodedResponse->data as $report){ | |
| 653 | +            foreach ($decodedResponse->data as $report) { | |
| 655 | 654 | $score = empty($report->abuseConfidenceScore) ? 0 : $report->abuseConfidenceScore; | 
| 656 | 655 | $defaultColor = self::getScoreColor($score); | 
| 657 | 656 | |
| @@ -680,12 +679,12 @@ discard block | ||
| 680 | 679 | */ | 
| 681 | 680 | protected static function checkBlock($arguments) | 
| 682 | 681 |      { | 
| 683 | - $network = self::getArgumentValue($arguments,'K', 'check-block'); | |
| 682 | + $network = self::getArgumentValue($arguments, 'K', 'check-block'); | |
| 684 | 683 | |
| 685 | -        self::printTitle(Console::text('  ► Check network: ', 'darkgray') . Console::text(escapeshellcmd($network), 'white') . Console::text('', 'darkgray')); | |
| 684 | +        self::printTitle(Console::text('  ► Check network: ', 'darkgray').Console::text(escapeshellcmd($network), 'white').Console::text('', 'darkgray')); | |
| 686 | 685 | |
| 687 | 686 | $maxAge = self::getNumericParameter($arguments, 'd', 'days', 30); | 
| 688 | - $limit = self::getNumericParameter($arguments,'l', 'limit', 0); // 0 mean no limit | |
| 687 | + $limit = self::getNumericParameter($arguments, 'l', 'limit', 0); // 0 mean no limit | |
| 689 | 688 | |
| 690 | 689 | self::printTempMessage(); | 
| 691 | 690 | |
| @@ -696,7 +695,7 @@ discard block | ||
| 696 | 695 | self::clearTempMessage(); | 
| 697 | 696 | |
| 698 | 697 | // check for errors / empty response | 
| 699 | -        if (self::printErrors($check)){ | |
| 698 | +        if (self::printErrors($check)) { | |
| 700 | 699 | self::printFooter($time); | 
| 701 | 700 | exit(1); | 
| 702 | 701 | } | 
| @@ -711,18 +710,18 @@ discard block | ||
| 711 | 710 | // print reported addresses | 
| 712 | 711 | $nbReports = isset($check->data->reportedAddress) ? count($check->data->reportedAddress) : 0; | 
| 713 | 712 | |
| 714 | -        if ($nbReports > 0){ | |
| 713 | +        if ($nbReports > 0) { | |
| 715 | 714 |              self::printResult(Console::pad('   Reported addresses:', 23), $nbReports, 'lightyellow'); | 
| 716 | 715 | $numberDiplayedReports = 0; | 
| 717 | 716 | $defaultColor = 'lightyellow'; // reset color for last reports | 
| 718 | 717 | |
| 719 | -            foreach ($check->data->reportedAddress as $report){ | |
| 718 | +            foreach ($check->data->reportedAddress as $report) { | |
| 720 | 719 | $score = empty($report->abuseConfidenceScore) ? 0 : $report->abuseConfidenceScore; | 
| 721 | 720 | $defaultColor = self::getScoreColor($score); // color based on score | 
| 722 | 721 | |
| 723 | 722 |                  $line  = Console::text('   →', $defaultColor); | 
| 724 | 723 |                  $line .= self::printResult(' IP: ', $report->ipAddress, $defaultColor, '', false); | 
| 725 | -                $line .= self::printResult(' Country: ', $report->countryCode , $defaultColor, '', false); | |
| 724 | +                $line .= self::printResult(' Country: ', $report->countryCode, $defaultColor, '', false); | |
| 726 | 725 |                  $line .= Console::text(' | Confidence score: ', 'white'); | 
| 727 | 726 | $line .= self::getScoreBadge($score); | 
| 728 | 727 |                  $line .= self::printResult(' Total reports: ', $report->numReports, $defaultColor, '', false); | 
| @@ -737,7 +736,7 @@ discard block | ||
| 737 | 736 | $line .= Console::text($numberDiplayedReports, 'lightyellow'); | 
| 738 | 737 |                      $line .= Console::text('/', 'white'); | 
| 739 | 738 | $line .= Console::text($nbReports, 'lightyellow'); | 
| 740 | - $line .= Console::text($numberDiplayedReports > 1 ? ' IPs displayed)': ' IP displayed)', 'white'); | |
| 739 | + $line .= Console::text($numberDiplayedReports > 1 ? ' IPs displayed)' : ' IP displayed)', 'white'); | |
| 741 | 740 | Console::log($line); | 
| 742 | 741 | break; | 
| 743 | 742 | } | 
| @@ -745,8 +744,8 @@ discard block | ||
| 745 | 744 | |
| 746 | 745 |          } else { | 
| 747 | 746 | // no reports | 
| 748 | - $day = $maxAge > 1 ? 'in last '. $maxAge . ' days': ' today'; | |
| 749 | -            Console::log( Console::text('    ✓', 'green') . Console::text(' No IP reported ' . $day)); | |
| 747 | + $day = $maxAge > 1 ? 'in last '.$maxAge.' days' : ' today'; | |
| 748 | +            Console::log(Console::text('    ✓', 'green').Console::text(' No IP reported '.$day)); | |
| 750 | 749 | } | 
| 751 | 750 | |
| 752 | 751 | // footer | 
| @@ -765,13 +764,13 @@ discard block | ||
| 765 | 764 | */ | 
| 766 | 765 | protected static function checkIP($arguments) | 
| 767 | 766 |      { | 
| 768 | - $ip = self::getArgumentValue($arguments,'C', 'check'); | |
| 767 | + $ip = self::getArgumentValue($arguments, 'C', 'check'); | |
| 769 | 768 | |
| 770 | -        self::printTitle(Console::text('  ► Check IP: ', 'darkgray') . Console::text(escapeshellcmd($ip), 'white') . Console::text('', 'darkgray')); | |
| 769 | +        self::printTitle(Console::text('  ► Check IP: ', 'darkgray').Console::text(escapeshellcmd($ip), 'white').Console::text('', 'darkgray')); | |
| 771 | 770 | |
| 772 | - $verbose = self::inArguments($arguments,'v', 'verbose'); | |
| 771 | + $verbose = self::inArguments($arguments, 'v', 'verbose'); | |
| 773 | 772 | $maxAge = self::getNumericParameter($arguments, 'd', 'days', 30); | 
| 774 | - $maxReportsNumber = self::getNumericParameter($arguments,'l', 'limit', 10); | |
| 773 | + $maxReportsNumber = self::getNumericParameter($arguments, 'l', 'limit', 10); | |
| 775 | 774 | |
| 776 | 775 | self::printTempMessage(); | 
| 777 | 776 | |
| @@ -782,7 +781,7 @@ discard block | ||
| 782 | 781 | self::clearTempMessage(); | 
| 783 | 782 | |
| 784 | 783 | // check for errors / empty response | 
| 785 | -        if (self::printErrors($check)){ | |
| 784 | +        if (self::printErrors($check)) { | |
| 786 | 785 | self::printFooter($time); | 
| 787 | 786 | exit(1); | 
| 788 | 787 | } | 
| @@ -796,26 +795,26 @@ discard block | ||
| 796 | 795 | |
| 797 | 796 |  //      self::printResult('   isPublic', $check->data->isPublic, $defaultColor); | 
| 798 | 797 |  //      self::printResult('   ipVersion', $check->data->ipVersion, $defaultColor); | 
| 799 | -        $line = self::printResult(Console::pad('   Whitelisted:', 23), $check->data->isWhitelisted ? 'true': 'false', $defaultColor, '', false); | |
| 798 | +        $line = self::printResult(Console::pad('   Whitelisted:', 23), $check->data->isWhitelisted ? 'true' : 'false', $defaultColor, '', false); | |
| 800 | 799 |          $line .= $check->data->isWhitelisted ? Console::text(' ★', 'green') : '';  | 
| 801 | 800 | Console::log($line); | 
| 802 | 801 | |
| 803 | 802 |          self::printResult(Console::pad('   Country code:', 23), $check->data->countryCode, $defaultColor); | 
| 804 | 803 | |
| 805 | -        if (!empty($check->data->countryName)){ | |
| 804 | +        if (!empty($check->data->countryName)) { | |
| 806 | 805 |              self::printResult(Console::pad('   Country name:', 23), $check->data->countryName, $defaultColor); | 
| 807 | 806 | } | 
| 808 | 807 | |
| 809 | 808 |          self::printResult(Console::pad('   ISP:', 23), $check->data->isp, $defaultColor); | 
| 810 | 809 | |
| 811 | -        if ($check->data->usageType){ | |
| 810 | +        if ($check->data->usageType) { | |
| 812 | 811 |              $line = self::printResult(Console::pad('   Usage type:', 23), $check->data->usageType, $defaultColor, '', false); | 
| 813 | 812 |              $line .= $check->data->usageType === 'Reserved' ? Console::text(' ◆', 'green') : ''; | 
| 814 | 813 | Console::log($line); | 
| 815 | 814 | } | 
| 816 | 815 | |
| 817 | 816 |          $hostames = implode(', ', array_filter($check->data->hostnames)) ?? null; | 
| 818 | -        if (!empty($hostames)){ | |
| 817 | +        if (!empty($hostames)) { | |
| 819 | 818 |              self::printResult(Console::pad('   Hostname(s):', 23), $hostames, $defaultColor); | 
| 820 | 819 | } | 
| 821 | 820 | |
| @@ -823,34 +822,34 @@ discard block | ||
| 823 | 822 | |
| 824 | 823 | $nbReport = $check->data->totalReports && is_numeric($check->data->totalReports) ? intval($check->data->totalReports) : 0; | 
| 825 | 824 | |
| 826 | -        if ($nbReport > 0 ){ | |
| 825 | +        if ($nbReport > 0) { | |
| 827 | 826 |              $line  = self::printResult(Console::pad('   Total reports:', 23), $nbReport, $defaultColor, '', false); | 
| 828 | 827 |              $line .= self::printResult(' from ', $check->data->numDistinctUsers, $defaultColor, '', false); | 
| 829 | - $line .= Console::text($nbReport > 0 ? ' distinct users': ' user', 'white'); | |
| 828 | + $line .= Console::text($nbReport > 0 ? ' distinct users' : ' user', 'white'); | |
| 830 | 829 | Console::log($line); | 
| 831 | 830 | |
| 832 | 831 |          } else { | 
| 833 | 832 | // no reports | 
| 834 | - $day = $maxAge > 1 ? 'in last '. $maxAge . ' days': ' today'; | |
| 835 | -            Console::log( Console::text('   ✓', 'green') . Console::text(' Not reported ' . $day)); | |
| 833 | + $day = $maxAge > 1 ? 'in last '.$maxAge.' days' : ' today'; | |
| 834 | +            Console::log(Console::text('   ✓', 'green').Console::text(' Not reported '.$day)); | |
| 836 | 835 | } | 
| 837 | 836 | |
| 838 | -        if (!empty($check->data->lastReportedAt)){ | |
| 837 | +        if (!empty($check->data->lastReportedAt)) { | |
| 839 | 838 |              self::printResult(Console::pad('   Last reported at:', 23), self::getDate($check->data->lastReportedAt), $defaultColor); | 
| 840 | 839 | } | 
| 841 | 840 | |
| 842 | 841 | // print last reports | 
| 843 | -        if ($verbose){ | |
| 842 | +        if ($verbose) { | |
| 844 | 843 | $nbLastReports = isset($check->data->reports) ? count($check->data->reports) : 0; | 
| 845 | 844 | |
| 846 | -            if ($nbLastReports > 0){ | |
| 845 | +            if ($nbLastReports > 0) { | |
| 847 | 846 |                  Console::log('   Last reports:', 'white'); | 
| 848 | 847 | $numberDiplayedReports = 0; | 
| 849 | 848 | $defaultColor = 'lightyellow'; // reset color for last reports | 
| 850 | 849 | |
| 851 | -                foreach ($check->data->reports as $lastReport){ | |
| 850 | +                foreach ($check->data->reports as $lastReport) { | |
| 852 | 851 | $categories = []; | 
| 853 | -                    foreach (array_filter($lastReport->categories) as $catId){ | |
| 852 | +                    foreach (array_filter($lastReport->categories) as $catId) { | |
| 854 | 853 | $cat = self::$api->getCategoryNamebyId($catId)[0]; | 
| 855 | 854 |                          if ($cat !== false) { | 
| 856 | 855 | $categories[] = $cat; | 
| @@ -860,15 +859,15 @@ discard block | ||
| 860 | 859 |                      $line  = Console::text('    →', $defaultColor); | 
| 861 | 860 |                      $line .= self::printResult(' reported at: ', self::getDate($lastReport->reportedAt), $defaultColor, '', false); | 
| 862 | 861 |                //    $line .= self::printResult(' by user: ', $lastReport->reporterId, $defaultColor, '', false); | 
| 863 | -                    if (isset($lastReport->reporterCountryCode) && isset($lastReport->reporterCountryName)){ | |
| 862 | +                    if (isset($lastReport->reporterCountryCode) && isset($lastReport->reporterCountryName)) { | |
| 864 | 863 |                          $line .= Console::text(' from: ', 'white'); | 
| 865 | 864 |                          $line .= self::printResult('', $lastReport->reporterCountryCode, $defaultColor, '', false); | 
| 866 | 865 |                          $line .= Console::text(' - ', 'white'); | 
| 867 | 866 |                          $line .= self::printResult('', $lastReport->reporterCountryName, $defaultColor, '', false); | 
| 868 | 867 | } | 
| 869 | -                    $line .= Console::text(' with categor' .  (count($categories) > 1 ? "ies: " : "y: "), 'white'); | |
| 868 | +                    $line .= Console::text(' with categor'.(count($categories) > 1 ? "ies: " : "y: "), 'white'); | |
| 870 | 869 |                      foreach ($categories as $key => $cat) { | 
| 871 | - $line .= Console::text($key==0 ? '' : ',' , 'white') . Console::text($cat, $defaultColor); | |
| 870 | + $line .= Console::text($key == 0 ? '' : ',', 'white').Console::text($cat, $defaultColor); | |
| 872 | 871 | } | 
| 873 | 872 | Console::log($line); | 
| 874 | 873 | |
| @@ -879,7 +878,7 @@ discard block | ||
| 879 | 878 | $line .= Console::text($numberDiplayedReports, $defaultColor); | 
| 880 | 879 |                          $line .= Console::text('/', 'white'); | 
| 881 | 880 | $line .= Console::text($nbLastReports, $defaultColor); | 
| 882 | - $line .= Console::text($numberDiplayedReports > 1 ? ' reports displayed)': ' report displayed)', 'white'); | |
| 881 | + $line .= Console::text($numberDiplayedReports > 1 ? ' reports displayed)' : ' report displayed)', 'white'); | |
| 883 | 882 | Console::log($line); | 
| 884 | 883 | break; | 
| 885 | 884 | } | 
| @@ -269,20 +269,20 @@ | ||
| 269 | 269 | } | 
| 270 | 270 | |
| 271 | 271 | /** | 
| 272 | - * Get numeric parameter and exit on error | |
| 273 | - * | |
| 274 | - * @access protected | |
| 275 | - * @static | |
| 276 | - * @param array $arguments | |
| 277 | - * @param string $shortArg The short argument name | |
| 278 | - * @param string $longArg The long argument name | |
| 279 | - * @param int $defaultValue | |
| 280 | - * | |
| 281 | - * @return int | |
| 282 | - */ | |
| 272 | + * Get numeric parameter and exit on error | |
| 273 | + * | |
| 274 | + * @access protected | |
| 275 | + * @static | |
| 276 | + * @param array $arguments | |
| 277 | + * @param string $shortArg The short argument name | |
| 278 | + * @param string $longArg The long argument name | |
| 279 | + * @param int $defaultValue | |
| 280 | + * | |
| 281 | + * @return int | |
| 282 | + */ | |
| 283 | 283 | protected static function getNumericParameter(array $arguments, string $shortArg, string $longArg, int $defaultValue) | 
| 284 | 284 |      { | 
| 285 | -         if (self::inArguments($arguments,$shortArg, $longArg)){ | |
| 285 | +            if (self::inArguments($arguments,$shortArg, $longArg)){ | |
| 286 | 286 | $val = self::getArgumentValue($arguments,$shortArg, $longArg); | 
| 287 | 287 | |
| 288 | 288 |              if (!is_numeric($val)){ | 
| @@ -60,7 +60,7 @@ discard block | ||
| 60 | 60 | */ | 
| 61 | 61 | protected static function printTempMessage() | 
| 62 | 62 |      { | 
| 63 | -        Console::reLog(Console::text('   ? ', 'green') . Console::text('waiting for api response', 'white') . Console::text(' ... ', 'green')); | |
| 63 | +        Console::reLog(Console::text('   ? ', 'green').Console::text('waiting for api response', 'white').Console::text(' ... ', 'green')); | |
| 64 | 64 | } | 
| 65 | 65 | |
| 66 | 66 | /** | 
| @@ -89,8 +89,8 @@ discard block | ||
| 89 | 89 | protected static function printBanner() | 
| 90 | 90 |      { | 
| 91 | 91 | Console::log(); | 
| 92 | -        Console::log( Console::text(' Kristuff\AbuseIPDB ', 'darkgray') . Console::text(' ' . AbuseIPDBClient::VERSION . ' ', 'white', 'blue'));  | |
| 93 | -        Console::log(Console::text(' Made with ', 'darkgray') . Console::text('♥', 'red') . Console::text(' in France', 'darkgray'));  | |
| 92 | +        Console::log(Console::text(' Kristuff\AbuseIPDB ', 'darkgray').Console::text(' '.AbuseIPDBClient::VERSION.' ', 'white', 'blue'));  | |
| 93 | +        Console::log(Console::text(' Made with ', 'darkgray').Console::text('♥', 'red').Console::text(' in France', 'darkgray'));  | |
| 94 | 94 |          Console::log(' © 2020-2021 Kristuff', 'darkgray');  | 
| 95 | 95 | Console::log(); | 
| 96 | 96 | } | 
| @@ -105,19 +105,19 @@ discard block | ||
| 105 | 105 | */ | 
| 106 | 106 | protected static function printFooter(string $requestTime = '') | 
| 107 | 107 |      { | 
| 108 | -        if (!empty($requestTime)){ | |
| 108 | +        if (!empty($requestTime)) { | |
| 109 | 109 |              $date_utc = new \DateTime("now", new \DateTimeZone("UTC")); | 
| 110 | 110 | Console::log( | 
| 111 | -                Console::text('  Request time: ', 'darkgray') . Console::text($requestTime . 's', 'lightgray').  | |
| 112 | -                Console::text(' | UTC time: ', 'darkgray') . Console::text($date_utc->format('Y-m-d H:i:s'), 'lightgray') | |
| 111 | +                Console::text('  Request time: ', 'darkgray').Console::text($requestTime.'s', 'lightgray').  | |
| 112 | +                Console::text(' | UTC time: ', 'darkgray').Console::text($date_utc->format('Y-m-d H:i:s'), 'lightgray') | |
| 113 | 113 | ); | 
| 114 | 114 | } | 
| 115 | 115 |          Console::log(Console::text('  ------------------------------------------------------------------------------------------------------', 'darkgray'));  | 
| 116 | 116 | Console::log( | 
| 117 | -            Console::text('  Kristuff\AbuseIPDB ', 'darkgray') .  | |
| 118 | - Console::text(AbuseIPDBClient::VERSION, 'lightgray') . | |
| 119 | -            Console::text(' | Made with ', 'darkgray') .  | |
| 120 | -            Console::text('♥', 'red') . | |
| 117 | +            Console::text('  Kristuff\AbuseIPDB ', 'darkgray').  | |
| 118 | + Console::text(AbuseIPDBClient::VERSION, 'lightgray'). | |
| 119 | +            Console::text(' | Made with ', 'darkgray').  | |
| 120 | +            Console::text('♥', 'red'). | |
| 121 | 121 |              Console::text(' in France | © 2020-2021 Kristuff (https://github.com/kristuff)', 'darkgray') | 
| 122 | 122 | ); | 
| 123 | 123 | Console::log(); | 
| @@ -134,9 +134,9 @@ discard block | ||
| 134 | 134 | protected static function printResult($text, $value, string $foregroundColor = 'lightred', string $backgroundColor = '', bool $print = true) | 
| 135 | 135 |      { | 
| 136 | 136 | // do not print null/blank values | 
| 137 | -        if (isset($value)){ | |
| 138 | - $line = Console::text($text, 'white') . Console::text($value, $foregroundColor, $backgroundColor); | |
| 139 | -            if ($print){ | |
| 137 | +        if (isset($value)) { | |
| 138 | + $line = Console::text($text, 'white').Console::text($value, $foregroundColor, $backgroundColor); | |
| 139 | +            if ($print) { | |
| 140 | 140 | Console::log($line); | 
| 141 | 141 | } | 
| 142 | 142 | return $line; | 
| @@ -160,16 +160,16 @@ discard block | ||
| 160 | 160 | $scoreforegroundColor = 'white'; | 
| 161 | 161 | $scoreBackgroundColor = 'green'; | 
| 162 | 162 | |
| 163 | -        if (intval($score) > 0 ){ | |
| 163 | +        if (intval($score) > 0) { | |
| 164 | 164 | $scoreforegroundColor = 'black'; | 
| 165 | 165 | $scoreBackgroundColor = 'yellow'; | 
| 166 | 166 | } | 
| 167 | -        if (intval($score) > 50 ){ | |
| 167 | +        if (intval($score) > 50) { | |
| 168 | 168 | $scoreforegroundColor = 'white'; | 
| 169 | 169 | $scoreBackgroundColor = 'red'; | 
| 170 | 170 | } | 
| 171 | 171 | |
| 172 | - $badge = str_pad($score, 3, ' ',STR_PAD_LEFT); | |
| 172 | + $badge = str_pad($score, 3, ' ', STR_PAD_LEFT); | |
| 173 | 173 | return Console::text($padding.$badge.$padding, $scoreforegroundColor, $scoreBackgroundColor); | 
| 174 | 174 | } | 
| 175 | 175 | |
| @@ -185,27 +185,27 @@ discard block | ||
| 185 | 185 | */ | 
| 186 | 186 | protected static function printErrors($response, bool $checkForEmpty = true) | 
| 187 | 187 |      { | 
| 188 | -        if (isset($response) && isset($response->errors)){ | |
| 188 | +        if (isset($response) && isset($response->errors)) { | |
| 189 | 189 | |
| 190 | 190 | // top error badge | 
| 191 | -            Console::log('  ' .   Console::text(' ERROR ','white', 'red')); | |
| 191 | +            Console::log('  '.Console::text(' ERROR ', 'white', 'red')); | |
| 192 | 192 | |
| 193 | 193 | $num = 0; | 
| 194 | 194 | // errors is an array, could have more than one error.. | 
| 195 | -            foreach ($response->errors as $err){ | |
| 195 | +            foreach ($response->errors as $err) { | |
| 196 | 196 | $num++; | 
| 197 | 197 | |
| 198 | -                Console::log(Console::text('   ✗', 'red') .  self::printResult(' Number:    ', $num, 'lightyellow','', false)); | |
| 199 | -                self::printResult('     Status:    ', $err->status ?? null, 'lightyellow','');     | |
| 198 | +                Console::log(Console::text('   ✗', 'red').self::printResult(' Number:    ', $num, 'lightyellow', '', false)); | |
| 199 | +                self::printResult('     Status:    ', $err->status ?? null, 'lightyellow', '');     | |
| 200 | 200 | |
| 201 | -                if (!empty($err->source) && !empty($err->source->parameter)){ | |
| 201 | +                if (!empty($err->source) && !empty($err->source->parameter)) { | |
| 202 | 202 |                      self::printResult('     Parameter: ', $err->source->parameter, 'lightyellow');     | 
| 203 | 203 | } | 
| 204 | 204 |                  self::printResult('     Title:     ', $err->title ?? null, 'lightyellow');     | 
| 205 | 205 |                  self::printResult('     Detail:    ', $err->detail ?? null, 'lightyellow');     | 
| 206 | 206 | |
| 207 | 207 | // separate errors | 
| 208 | -                if (count($response->errors) > 1){ | |
| 208 | +                if (count($response->errors) > 1) { | |
| 209 | 209 |                      Console::log('   ---'); | 
| 210 | 210 | } | 
| 211 | 211 | |
| @@ -215,7 +215,7 @@ discard block | ||
| 215 | 215 | } | 
| 216 | 216 | |
| 217 | 217 | // check for empty response ? | 
| 218 | -        if ( $checkForEmpty && ( empty($response) || empty($response->data)) ){ | |
| 218 | +        if ($checkForEmpty && (empty($response) || empty($response->data))) { | |
| 219 | 219 |              self::error('An unexpected error occurred.'); | 
| 220 | 220 | return true; | 
| 221 | 221 | } | 
| @@ -235,11 +235,11 @@ discard block | ||
| 235 | 235 | protected static function error($error) | 
| 236 | 236 |      { | 
| 237 | 237 | // ✗ | 
| 238 | -        Console::log('  ' .   Console::text(' ERROR ','white', 'red')); | |
| 238 | +        Console::log('  '.Console::text(' ERROR ', 'white', 'red')); | |
| 239 | 239 | Console::log( | 
| 240 | -            Console::text('   ✗', 'red') .  | |
| 241 | -            Console::text(' Detail:    ', 'white') .  | |
| 242 | - Console::text($error, 'lightyellow') . | |
| 240 | +            Console::text('   ✗', 'red').  | |
| 241 | +            Console::text(' Detail:    ', 'white').  | |
| 242 | + Console::text($error, 'lightyellow'). | |
| 243 | 243 |              Console::text('', 'white') | 
| 244 | 244 | ); | 
| 245 | 245 | Console::log(); | 
| @@ -258,7 +258,7 @@ discard block | ||
| 258 | 258 | */ | 
| 259 | 259 | protected static function validate(bool $condition, string $message, bool $print = true) | 
| 260 | 260 |      { | 
| 261 | -        if ( !$condition ){ | |
| 261 | +        if (!$condition) { | |
| 262 | 262 |              if ($print) { | 
| 263 | 263 | Console::log(); | 
| 264 | 264 | self::error($message); | 
| @@ -282,10 +282,10 @@ discard block | ||
| 282 | 282 | */ | 
| 283 | 283 | protected static function getNumericParameter(array $arguments, string $shortArg, string $longArg, int $defaultValue) | 
| 284 | 284 |      { | 
| 285 | -         if (self::inArguments($arguments,$shortArg, $longArg)){ | |
| 286 | - $val = self::getArgumentValue($arguments,$shortArg, $longArg); | |
| 285 | +         if (self::inArguments($arguments, $shortArg, $longArg)) { | |
| 286 | + $val = self::getArgumentValue($arguments, $shortArg, $longArg); | |
| 287 | 287 | |
| 288 | -            if (!is_numeric($val)){ | |
| 288 | +            if (!is_numeric($val)) { | |
| 289 | 289 |                  self::error("Invalid parameter: $longArg must be a numeric value."); | 
| 290 | 290 | self::printFooter(); | 
| 291 | 291 | exit(1); |