@@ -65,13 +65,13 @@ discard block |
||
65 | 65 | self::printResult(Console::pad(' Reported addresses:', 23), $nbReports, 'lightyellow'); |
66 | 66 | $numberDiplayedReports = 0; |
67 | 67 | |
68 | - foreach ($response->data->reportedAddress as $report){ |
|
68 | + foreach ($response->data->reportedAddress as $report) { |
|
69 | 69 | $score = empty($report->abuseConfidenceScore) ? 0 : $report->abuseConfidenceScore; |
70 | 70 | $defaultColor = self::getScoreColor($score); // color based on score |
71 | 71 | |
72 | 72 | $line = Console::text(' →', $defaultColor); |
73 | 73 | $line .= self::printResult(' IP: ', $report->ipAddress, $defaultColor, '', false); |
74 | - $line .= self::printResult(' Country: ', $report->countryCode , $defaultColor, '', false); |
|
74 | + $line .= self::printResult(' Country: ', $report->countryCode, $defaultColor, '', false); |
|
75 | 75 | $line .= Console::text(' | Confidence score: ', 'white'); |
76 | 76 | $line .= self::getScoreBadge($score); |
77 | 77 | $line .= self::printResult(' Total reports: ', $report->numReports, $defaultColor, '', false); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | $line .= Console::text($numberDiplayedReports, 'lightyellow'); |
87 | 87 | $line .= Console::text('/', 'white'); |
88 | 88 | $line .= Console::text($nbReports, 'lightyellow'); |
89 | - $line .= Console::text($numberDiplayedReports > 1 ? ' IPs displayed)': ' IP displayed)', 'white'); |
|
89 | + $line .= Console::text($numberDiplayedReports > 1 ? ' IPs displayed)' : ' IP displayed)', 'white'); |
|
90 | 90 | Console::log($line); |
91 | 91 | break; |
92 | 92 | } |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | |
95 | 95 | } else { |
96 | 96 | // no reports |
97 | - $day = $maxAge > 1 ? 'in last '. $maxAge . ' days': ' today'; |
|
98 | - Console::log( Console::text(' ✓', 'green') . Console::text(' No IP reported ' . $day)); |
|
97 | + $day = $maxAge > 1 ? 'in last '.$maxAge.' days' : ' today'; |
|
98 | + Console::log(Console::text(' ✓', 'green').Console::text(' No IP reported '.$day)); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | } |
102 | 102 | \ No newline at end of file |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | |
172 | 172 | $line = Console::text(' →', $defaultColor); |
173 | 173 | $line .= self::printResult(' reported at: ', self::getDate($report->reportedAt), $defaultColor, '', false); |
174 | - // $line .= self::printResult(' by user: ', $report->reporterId, $defaultColor, '', false); |
|
174 | + // $line .= self::printResult(' by user: ', $report->reporterId, $defaultColor, '', false); |
|
175 | 175 | if (isset($report->reporterCountryCode) && isset($report->reporterCountryName)){ |
176 | 176 | $line .= Console::text(' from: ', 'white'); |
177 | 177 | $line .= self::printResult('', $report->reporterCountryCode, $defaultColor, '', false); |
@@ -206,5 +206,5 @@ discard block |
||
206 | 206 | } |
207 | 207 | } |
208 | 208 | return $categories; |
209 | - } |
|
209 | + } |
|
210 | 210 | } |
211 | 211 | \ No newline at end of file |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | protected static function printCheckScore(object $response): void |
41 | 41 | { |
42 | 42 | $score = empty($response->data->abuseConfidenceScore) ? 0 : $response->data->abuseConfidenceScore; |
43 | - $line = Console::text(Console::pad(' Confidence score:', 23), 'white') . self::getScoreBadge($score); |
|
43 | + $line = Console::text(Console::pad(' Confidence score:', 23), 'white').self::getScoreBadge($score); |
|
44 | 44 | Console::log($line); |
45 | 45 | } |
46 | 46 | |
@@ -59,26 +59,26 @@ discard block |
||
59 | 59 | // self::printResult(' isPublic', $response->data->isPublic, $defaultColor); |
60 | 60 | // self::printResult(' ipVersion', $response->data->ipVersion, $defaultColor); |
61 | 61 | |
62 | - $line = self::printResult(Console::pad(' Whitelisted:', 23), $response->data->isWhitelisted ? 'true': 'false', $color, '', false); |
|
62 | + $line = self::printResult(Console::pad(' Whitelisted:', 23), $response->data->isWhitelisted ? 'true' : 'false', $color, '', false); |
|
63 | 63 | $line .= $response->data->isWhitelisted ? Console::text(' ★', 'green') : ''; |
64 | 64 | Console::log($line); |
65 | 65 | |
66 | 66 | self::printResult(Console::pad(' Country code:', 23), $response->data->countryCode, $color); |
67 | 67 | |
68 | - if (!empty($response->data->countryName)){ |
|
68 | + if (!empty($response->data->countryName)) { |
|
69 | 69 | self::printResult(Console::pad(' Country name:', 23), $response->data->countryName, $color); |
70 | 70 | } |
71 | 71 | |
72 | 72 | self::printResult(Console::pad(' ISP:', 23), $response->data->isp, $color); |
73 | 73 | |
74 | - if ($response->data->usageType){ |
|
74 | + if ($response->data->usageType) { |
|
75 | 75 | $line = self::printResult(Console::pad(' Usage type:', 23), $response->data->usageType, $color, '', false); |
76 | 76 | $line .= $response->data->usageType === 'Reserved' ? Console::text(' ◆', 'green') : ''; |
77 | 77 | Console::log($line); |
78 | 78 | } |
79 | 79 | |
80 | 80 | $hostames = implode(', ', array_filter($response->data->hostnames)) ?? null; |
81 | - if (!empty($hostames)){ |
|
81 | + if (!empty($hostames)) { |
|
82 | 82 | self::printResult(Console::pad(' Hostname(s):', 23), $hostames, $color); |
83 | 83 | } |
84 | 84 | |
@@ -100,19 +100,19 @@ discard block |
||
100 | 100 | { |
101 | 101 | $nbReport = $response->data->totalReports && is_numeric($response->data->totalReports) ? intval($response->data->totalReports) : 0; |
102 | 102 | |
103 | - if ($nbReport > 0 ){ |
|
103 | + if ($nbReport > 0) { |
|
104 | 104 | $line = self::printResult(Console::pad(' Total reports:', 23), $nbReport, $color, '', false); |
105 | 105 | $line .= self::printResult(' from ', $response->data->numDistinctUsers, $color, '', false); |
106 | - $line .= Console::text($nbReport > 0 ? ' distinct users': ' user', 'white'); |
|
106 | + $line .= Console::text($nbReport > 0 ? ' distinct users' : ' user', 'white'); |
|
107 | 107 | Console::log($line); |
108 | 108 | |
109 | 109 | } else { |
110 | 110 | // no reports |
111 | - $day = $maxAge > 1 ? 'in last '. $maxAge . ' days': ' today'; |
|
112 | - Console::log( Console::text(' ✓', 'green') . Console::text(' Not reported ' . $day)); |
|
111 | + $day = $maxAge > 1 ? 'in last '.$maxAge.' days' : ' today'; |
|
112 | + Console::log(Console::text(' ✓', 'green').Console::text(' Not reported '.$day)); |
|
113 | 113 | } |
114 | 114 | |
115 | - if (!empty($response->data->lastReportedAt)){ |
|
115 | + if (!empty($response->data->lastReportedAt)) { |
|
116 | 116 | self::printResult(Console::pad(' Last reported at:', 23), self::getDate($response->data->lastReportedAt), $color); |
117 | 117 | } |
118 | 118 | } |
@@ -132,12 +132,12 @@ discard block |
||
132 | 132 | { |
133 | 133 | $nbLastReports = isset($response->data->reports) ? count($response->data->reports) : 0; |
134 | 134 | |
135 | - if ($nbLastReports > 0){ |
|
135 | + if ($nbLastReports > 0) { |
|
136 | 136 | Console::log(' Last reports:', 'white'); |
137 | 137 | $numberDiplayedReports = 0; |
138 | 138 | $defaultColor = 'lightyellow'; // reset color for last reports |
139 | 139 | |
140 | - foreach ($response->data->reports as $report){ |
|
140 | + foreach ($response->data->reports as $report) { |
|
141 | 141 | self::printLastReport($report); |
142 | 142 | $numberDiplayedReports++; |
143 | 143 | |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | $line .= Console::text($numberDiplayedReports, $defaultColor); |
147 | 147 | $line .= Console::text('/', 'white'); |
148 | 148 | $line .= Console::text($nbLastReports, $defaultColor); |
149 | - $line .= Console::text($numberDiplayedReports > 1 ? ' reports displayed)': ' report displayed)', 'white'); |
|
149 | + $line .= Console::text($numberDiplayedReports > 1 ? ' reports displayed)' : ' report displayed)', 'white'); |
|
150 | 150 | Console::log($line); |
151 | 151 | break; |
152 | 152 | } |
@@ -171,15 +171,15 @@ discard block |
||
171 | 171 | $line = Console::text(' →', $defaultColor); |
172 | 172 | $line .= self::printResult(' reported at: ', self::getDate($report->reportedAt), $defaultColor, '', false); |
173 | 173 | // $line .= self::printResult(' by user: ', $report->reporterId, $defaultColor, '', false); |
174 | - if (isset($report->reporterCountryCode) && isset($report->reporterCountryName)){ |
|
174 | + if (isset($report->reporterCountryCode) && isset($report->reporterCountryName)) { |
|
175 | 175 | $line .= Console::text(' from: ', 'white'); |
176 | 176 | $line .= self::printResult('', $report->reporterCountryCode, $defaultColor, '', false); |
177 | 177 | $line .= Console::text(' - ', 'white'); |
178 | 178 | $line .= self::printResult('', $report->reporterCountryName, $defaultColor, '', false); |
179 | 179 | } |
180 | - $line .= Console::text(' with categor' . (count($categories) > 1 ? "ies: " : "y: "), 'white'); |
|
180 | + $line .= Console::text(' with categor'.(count($categories) > 1 ? "ies: " : "y: "), 'white'); |
|
181 | 181 | foreach ($categories as $key => $cat) { |
182 | - $line .= Console::text($key==0 ? '' : ',' , 'white') . Console::text($cat, $defaultColor); |
|
182 | + $line .= Console::text($key == 0 ? '' : ',', 'white').Console::text($cat, $defaultColor); |
|
183 | 183 | } |
184 | 184 | Console::log($line); |
185 | 185 | } |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | private static function getLastReportsCategories(object $report): array |
197 | 197 | { |
198 | 198 | $categories = []; |
199 | - foreach (array_filter($report->categories) as $catId){ |
|
199 | + foreach (array_filter($report->categories) as $catId) { |
|
200 | 200 | $cat = ApiHandler::getCategoryNameById(strval($catId)); |
201 | 201 | if ($cat !== false) { |
202 | 202 | $categories[] = $cat; |
@@ -171,7 +171,7 @@ |
||
171 | 171 | */ |
172 | 172 | protected static function getNumericParameter(array $arguments, string $shortArg, string $longArg, int $defaultValue): int |
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)){ |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | */ |
57 | 57 | private static function parseErrors(?object $response = null): bool |
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): void |
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): void |
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): int |
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): void |
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'); |
@@ -219,11 +219,11 @@ discard block |
||
219 | 219 | */ |
220 | 220 | private static function getErrorDetail(object $error, string $field, ?string $parent = null): string |
221 | 221 | { |
222 | - if (!empty($parent)){ |
|
223 | - return !empty($error->$parent) && !empty($error->$parent->$field) ? ' ' . $field . ': ' . $error->$parent->$field : ''; |
|
222 | + if (!empty($parent)) { |
|
223 | + return !empty($error->$parent) && !empty($error->$parent->$field) ? ' '.$field.': '.$error->$parent->$field : ''; |
|
224 | 224 | } |
225 | 225 | |
226 | - return !empty($error->$field) ? ' ' . $field . ': ' . $error->$field : ''; |
|
226 | + return !empty($error->$field) ? ' '.$field.': '.$error->$field : ''; |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | protected static function checkForEmpty(?object $response = null): bool |
239 | 239 | { |
240 | 240 | // check for empty response ? |
241 | - if ( empty($response) || empty($response->data) ){ |
|
241 | + if (empty($response) || empty($response->data)) { |
|
242 | 242 | self::error('An unexpected error occurred.'); |
243 | 243 | return true; |
244 | 244 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | */ |
91 | 91 | protected static function inArguments(array $arguments, string $shortArg, string $longArg): bool |
92 | 92 | { |
93 | - return array_key_exists($shortArg, $arguments) || array_key_exists($longArg, $arguments); |
|
93 | + return array_key_exists($shortArg, $arguments) || array_key_exists($longArg, $arguments); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @param string $filePath The file's full path |
102 | 102 | * @param bool $throwError Throw error on true or silent process. Default is true |
103 | 103 | * |
104 | - * @return object|null |
|
104 | + * @return object|null |
|
105 | 105 | * @throws \Exception |
106 | 106 | * @throws \LogicException |
107 | 107 | */ |
@@ -109,10 +109,10 @@ discard block |
||
109 | 109 | { |
110 | 110 | // check file exists |
111 | 111 | if (!file_exists($filePath) || !is_file($filePath)){ |
112 | - if ($throwError) { |
|
112 | + if ($throwError) { |
|
113 | 113 | throw new \Exception('Config file not found'); |
114 | - } |
|
115 | - return null; |
|
114 | + } |
|
115 | + return null; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | // get and parse content |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | protected static function getScoreColor($score): string |
56 | 56 | { |
57 | 57 | $score = intval($score); |
58 | - return $score > 50 ? 'lightred' : ($score > 0 ? 'yellow' : 'green') ; |
|
58 | + return $score > 50 ? 'lightred' : ($score > 0 ? 'yellow' : 'green'); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | |
@@ -73,8 +73,7 @@ discard block |
||
73 | 73 | */ |
74 | 74 | protected static function getArgumentValue(array $arguments, string $shortArg, string $longArg): string |
75 | 75 | { |
76 | - return (array_key_exists($shortArg, $arguments) ? $arguments[$shortArg] : |
|
77 | - (array_key_exists($longArg, $arguments) ? $arguments[$longArg] : '')); |
|
76 | + return (array_key_exists($shortArg, $arguments) ? $arguments[$shortArg] : (array_key_exists($longArg, $arguments) ? $arguments[$longArg] : '')); |
|
78 | 77 | } |
79 | 78 | |
80 | 79 | /** |
@@ -108,7 +107,7 @@ discard block |
||
108 | 107 | protected static function loadJsonFile(string $filePath, bool $throwError = true): ?object |
109 | 108 | { |
110 | 109 | // check file exists |
111 | - if (!file_exists($filePath) || !is_file($filePath)){ |
|
110 | + if (!file_exists($filePath) || !is_file($filePath)) { |
|
112 | 111 | if ($throwError) { |
113 | 112 | throw new \Exception('Config file not found'); |
114 | 113 | } |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | protected static function printBulkReportDetail(string $fileName): void |
41 | 41 | { |
42 | 42 | Console::log( |
43 | - Console::text(' Bulk report for file: [', 'white') . |
|
44 | - Console::text($fileName, 'lightyellow') . |
|
43 | + Console::text(' Bulk report for file: [', 'white'). |
|
44 | + Console::text($fileName, 'lightyellow'). |
|
45 | 45 | Console::text('] done!', 'white') |
46 | 46 | ); |
47 | 47 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | $nbSavedReports = isset($response->data->savedReports) ? $response->data->savedReports : 0; |
62 | 62 | $savedColor = $nbSavedReports > 0 ? 'green' : 'red'; |
63 | 63 | $savedIcon = $nbSavedReports > 0 ? '✓' : '✗'; |
64 | - Console::log(Console::text(' ' . $savedIcon, $savedColor) . self::printResult(' Saved reports: ', $nbSavedReports, $savedColor, '', false)); |
|
64 | + Console::log(Console::text(' '.$savedIcon, $savedColor).self::printResult(' Saved reports: ', $nbSavedReports, $savedColor, '', false)); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -80,15 +80,15 @@ discard block |
||
80 | 80 | $errorColor = $nbErrorReports > 0 ? 'red' : 'green'; |
81 | 81 | $errorIcon = $nbErrorReports > 0 ? '✗' : '✓'; |
82 | 82 | |
83 | - Console::log(Console::text(' ' . $errorIcon, $errorColor) . self::printResult(' Invalid reports: ', $nbErrorReports, $errorColor, '', false)); |
|
83 | + Console::log(Console::text(' '.$errorIcon, $errorColor).self::printResult(' Invalid reports: ', $nbErrorReports, $errorColor, '', false)); |
|
84 | 84 | |
85 | - if ($nbErrorReports > 0){ |
|
85 | + if ($nbErrorReports > 0) { |
|
86 | 86 | $numberDiplayedReports = 0; |
87 | 87 | $defaultColor = 'lightyellow'; // reset color for last reports |
88 | 88 | |
89 | - foreach ($response->data->invalidReports as $report){ |
|
89 | + foreach ($response->data->invalidReports as $report) { |
|
90 | 90 | $input = $report->input ? escapeshellcmd($report->input) : ''; // in case on blank line, IP is null |
91 | - Console::log(Console::text(' →', 'red') . self::printResult(' Input: ', $input, $defaultColor, '', false)); |
|
91 | + Console::log(Console::text(' →', 'red').self::printResult(' Input: ', $input, $defaultColor, '', false)); |
|
92 | 92 | self::printResult(' Error: ', $report->error, $defaultColor); |
93 | 93 | self::printResult(' Line number: ', $report->rowNumber, $defaultColor); |
94 | 94 |
@@ -37,17 +37,17 @@ discard block |
||
37 | 37 | /** |
38 | 38 | * @var string |
39 | 39 | */ |
40 | - const OUTPUT_JSON = 'json'; |
|
40 | + const OUTPUT_JSON = 'json'; |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * @var string |
44 | 44 | */ |
45 | - const OUTPUT_DEFAULT = 'default'; |
|
45 | + const OUTPUT_DEFAULT = 'default'; |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * @var string |
49 | 49 | */ |
50 | - const OUTPUT_PLAINTEXT = 'plaintext'; |
|
50 | + const OUTPUT_PLAINTEXT = 'plaintext'; |
|
51 | 51 | |
52 | 52 | /** |
53 | 53 | * @var string $outputFormat |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | protected static function printTempMessage(): void |
93 | 93 | { |
94 | 94 | if (self::isDefaultOuput()) { |
95 | - Console::reLog(Console::text(' ? ', 'green') . Console::text('waiting for api response', 'white') . Console::text(' ... ', 'green')); |
|
95 | + Console::reLog(Console::text(' ? ', 'green').Console::text('waiting for api response', 'white').Console::text(' ... ', 'green')); |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | self::printLogo(); |
147 | 147 | |
148 | 148 | Console::log(); |
149 | - Console::log(Console::text(' Kristuff/AbuseIPDB Client version: ', 'darkgray') . Console::text(AbuseIPDBClient::VERSION, 'lightgray')); |
|
150 | - Console::log(Console::text(' Kristuff/AbuseIPDB Core version: ', 'darkgray') . Console::text(ApiHandler::VERSION, 'lightgray')); |
|
149 | + Console::log(Console::text(' Kristuff/AbuseIPDB Client version: ', 'darkgray').Console::text(AbuseIPDBClient::VERSION, 'lightgray')); |
|
150 | + Console::log(Console::text(' Kristuff/AbuseIPDB Core version: ', 'darkgray').Console::text(ApiHandler::VERSION, 'lightgray')); |
|
151 | 151 | Console::log(Console::text(' --------------------------------------------------', 'darkgray')); |
152 | 152 | Console::log(Console::text(' Released under the MIT licence', 'darkgray')); |
153 | - Console::log(Console::text(' Made with ', 'darkgray') . Console::text('♥', 'red') . Console::text(' in France', 'darkgray')); |
|
153 | + Console::log(Console::text(' Made with ', 'darkgray').Console::text('♥', 'red').Console::text(' in France', 'darkgray')); |
|
154 | 154 | Console::log( |
155 | 155 | Console::text(' © 2020-2021 Kristuff (', 'darkgray'). |
156 | 156 | Console::text('https://github.com/kristuff', 'darkgray', 'underlined'). |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | { |
173 | 173 | if (self::isDefaultOuput()) { |
174 | 174 | Console::log(); |
175 | - Console::log( Console::text(' Kristuff/AbuseIPDB-client ', 'darkgray') . Console::text(' ' . AbuseIPDBClient::VERSION . ' ', 'white', 'blue')); |
|
176 | - Console::log(Console::text(' Made with ', 'darkgray') . Console::text('♥', 'red') . Console::text(' in France', 'darkgray')); |
|
175 | + Console::log(Console::text(' Kristuff/AbuseIPDB-client ', 'darkgray').Console::text(' '.AbuseIPDBClient::VERSION.' ', 'white', 'blue')); |
|
176 | + Console::log(Console::text(' Made with ', 'darkgray').Console::text('♥', 'red').Console::text(' in France', 'darkgray')); |
|
177 | 177 | Console::log(Console::text(' © 2020-2021 Kristuff (', 'darkgray'). |
178 | 178 | Console::text('https://github.com/kristuff', 'darkgray', 'underlined'). |
179 | 179 | Console::text(')', 'darkgray') |
@@ -193,19 +193,19 @@ discard block |
||
193 | 193 | protected static function printFooter($requestTime = ''): void |
194 | 194 | { |
195 | 195 | if (self::isDefaultOuput()) { |
196 | - if (!empty($requestTime)){ |
|
196 | + if (!empty($requestTime)) { |
|
197 | 197 | $date_utc = new \DateTime("now", new \DateTimeZone("UTC")); |
198 | 198 | Console::log( |
199 | - Console::text(' Request time: ', 'darkgray') . Console::text($requestTime . 's', 'lightgray'). |
|
200 | - Console::text(' | UTC time: ', 'darkgray') . Console::text($date_utc->format('Y-m-d H:i:s'), 'lightgray') |
|
199 | + Console::text(' Request time: ', 'darkgray').Console::text($requestTime.'s', 'lightgray'). |
|
200 | + Console::text(' | UTC time: ', 'darkgray').Console::text($date_utc->format('Y-m-d H:i:s'), 'lightgray') |
|
201 | 201 | ); |
202 | 202 | } |
203 | 203 | Console::log(Console::text(' ------------------------------------------------------------------------------------------------------', 'darkgray')); |
204 | 204 | Console::log( |
205 | - Console::text(' Kristuff\AbuseIPDB ', 'darkgray') . |
|
206 | - Console::text(AbuseIPDBClient::VERSION, 'lightgray') . |
|
207 | - Console::text(' | Made with ', 'darkgray') . |
|
208 | - Console::text('♥', 'red') . |
|
205 | + Console::text(' Kristuff\AbuseIPDB ', 'darkgray'). |
|
206 | + Console::text(AbuseIPDBClient::VERSION, 'lightgray'). |
|
207 | + Console::text(' | Made with ', 'darkgray'). |
|
208 | + Console::text('♥', 'red'). |
|
209 | 209 | Console::text(' in France | © 2020-2021 Kristuff (https://github.com/kristuff)', 'darkgray') |
210 | 210 | ); |
211 | 211 | Console::log(); |
@@ -223,9 +223,9 @@ discard block |
||
223 | 223 | protected static function printResult($text, $value, string $foregroundColor = 'lightred', string $backgroundColor = '', bool $print = true): string |
224 | 224 | { |
225 | 225 | // do not print null/blank values |
226 | - if (isset($value)){ |
|
227 | - $line = Console::text($text, 'white') . Console::text($value, $foregroundColor, $backgroundColor); |
|
228 | - if ($print && self::isDefaultOuput()){ |
|
226 | + if (isset($value)) { |
|
227 | + $line = Console::text($text, 'white').Console::text($value, $foregroundColor, $backgroundColor); |
|
228 | + if ($print && self::isDefaultOuput()) { |
|
229 | 229 | Console::log($line); |
230 | 230 | } |
231 | 231 | return $line; |
@@ -249,16 +249,16 @@ discard block |
||
249 | 249 | $scoreforegroundColor = 'white'; |
250 | 250 | $scoreBackgroundColor = 'green'; |
251 | 251 | |
252 | - if (intval($score) > 0 ){ |
|
252 | + if (intval($score) > 0) { |
|
253 | 253 | $scoreforegroundColor = 'black'; |
254 | 254 | $scoreBackgroundColor = 'yellow'; |
255 | 255 | } |
256 | - if (intval($score) > 50 ){ |
|
256 | + if (intval($score) > 50) { |
|
257 | 257 | $scoreforegroundColor = 'white'; |
258 | 258 | $scoreBackgroundColor = 'red'; |
259 | 259 | } |
260 | 260 | |
261 | - $badge = str_pad(strval($score), 3, ' ',STR_PAD_LEFT); |
|
261 | + $badge = str_pad(strval($score), 3, ' ', STR_PAD_LEFT); |
|
262 | 262 | return Console::text($padding.$badge.$padding, $scoreforegroundColor, $scoreBackgroundColor); |
263 | 263 | } |
264 | 264 | } |
265 | 265 | \ No newline at end of file |
@@ -69,51 +69,51 @@ |
||
69 | 69 | Console::log(); |
70 | 70 | Console::log(' ' . Console::text('SYNOPSIS:', 'white', 'underline')); |
71 | 71 | Console::log(' ' . Console::text(' abuseipdb -C ') . |
72 | - Console::text('IP', 'yellow') . |
|
73 | - Console::text(' [-d ') . |
|
74 | - Console::text('DAYS', 'yellow') . |
|
75 | - Console::text('] [-v] [-l ') . |
|
76 | - Console::text('LIMIT', 'yellow') . |
|
77 | - Console::text('] [-o ') . |
|
78 | - Console::text('FORMAT', 'yellow') . |
|
79 | - Console::text(']')); |
|
72 | + Console::text('IP', 'yellow') . |
|
73 | + Console::text(' [-d ') . |
|
74 | + Console::text('DAYS', 'yellow') . |
|
75 | + Console::text('] [-v] [-l ') . |
|
76 | + Console::text('LIMIT', 'yellow') . |
|
77 | + Console::text('] [-o ') . |
|
78 | + Console::text('FORMAT', 'yellow') . |
|
79 | + Console::text(']')); |
|
80 | 80 | |
81 | 81 | Console::log(' ' . Console::text(' abuseipdb -K ') . |
82 | - Console::text('NETWORK', 'yellow') . |
|
83 | - Console::text(' [-d ') . |
|
84 | - Console::text('DAYS', 'yellow') . |
|
85 | - Console::text('] [-o ') . |
|
86 | - Console::text('FORMAT', 'yellow') . |
|
87 | - Console::text(']')); |
|
82 | + Console::text('NETWORK', 'yellow') . |
|
83 | + Console::text(' [-d ') . |
|
84 | + Console::text('DAYS', 'yellow') . |
|
85 | + Console::text('] [-o ') . |
|
86 | + Console::text('FORMAT', 'yellow') . |
|
87 | + Console::text(']')); |
|
88 | 88 | |
89 | 89 | Console::log(' ' . Console::text(' abuseipdb -R ') . |
90 | - Console::text('IP', 'yellow') . ' -c ' . |
|
91 | - Console::text('CATEGORIES', 'yellow') . ' -m ' . |
|
92 | - Console::text('MESSAGE', 'yellow') . |
|
93 | - Console::text(' [-o ') . |
|
94 | - Console::text('FORMAT', 'yellow') . |
|
95 | - Console::text(']')); |
|
90 | + Console::text('IP', 'yellow') . ' -c ' . |
|
91 | + Console::text('CATEGORIES', 'yellow') . ' -m ' . |
|
92 | + Console::text('MESSAGE', 'yellow') . |
|
93 | + Console::text(' [-o ') . |
|
94 | + Console::text('FORMAT', 'yellow') . |
|
95 | + Console::text(']')); |
|
96 | 96 | |
97 | 97 | Console::log(' ' . Console::text(' abuseipdb -V ') . |
98 | - Console::text('FILE', 'yellow') . |
|
99 | - Console::text(' [-o ') . |
|
100 | - Console::text('FORMAT', 'yellow') . |
|
101 | - Console::text(']')); |
|
98 | + Console::text('FILE', 'yellow') . |
|
99 | + Console::text(' [-o ') . |
|
100 | + Console::text('FORMAT', 'yellow') . |
|
101 | + Console::text(']')); |
|
102 | 102 | |
103 | 103 | Console::log(' ' . Console::text(' abuseipdb -E ') . |
104 | - Console::text('IP', 'yellow'). |
|
105 | - Console::text(' [-o ') . |
|
106 | - Console::text('FORMAT', 'yellow') . |
|
107 | - Console::text(']')); |
|
104 | + Console::text('IP', 'yellow'). |
|
105 | + Console::text(' [-o ') . |
|
106 | + Console::text('FORMAT', 'yellow') . |
|
107 | + Console::text(']')); |
|
108 | 108 | |
109 | 109 | Console::log(' ' . Console::text(' abuseipdb -B ') . |
110 | - Console::text('[-l ') . |
|
111 | - Console::text('LIMIT', 'yellow') . |
|
112 | - Console::text('] [-s ') . |
|
113 | - Console::text('SCORE', 'yellow') . |
|
114 | - Console::text('] [-o ') . |
|
115 | - Console::text('FORMAT', 'yellow') . |
|
116 | - Console::text(']')); |
|
110 | + Console::text('[-l ') . |
|
111 | + Console::text('LIMIT', 'yellow') . |
|
112 | + Console::text('] [-s ') . |
|
113 | + Console::text('SCORE', 'yellow') . |
|
114 | + Console::text('] [-o ') . |
|
115 | + Console::text('FORMAT', 'yellow') . |
|
116 | + Console::text(']')); |
|
117 | 117 | |
118 | 118 | Console::log(' ' . Console::text(' abuseipdb -L | -G | -h | --version')); |
119 | 119 |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | public static function start(array $arguments, string $confPath): void |
47 | 47 | { |
48 | 48 | // required at least one valid argument |
49 | - self::validate( !empty($arguments), 'No valid arguments given. Run abuseipdb --help to get help.'); |
|
49 | + self::validate(!empty($arguments), 'No valid arguments given. Run abuseipdb --help to get help.'); |
|
50 | 50 | self::$configPath = $confPath; |
51 | 51 | if (!self::parseCommand($arguments, $confPath)) { |
52 | 52 | self::error('Invalid arguments. Run abuseipdb --help to get help.'); |
@@ -67,58 +67,58 @@ discard block |
||
67 | 67 | protected static function printHelp(): void |
68 | 68 | { |
69 | 69 | Console::log(); |
70 | - Console::log(' ' . Console::text('SYNOPSIS:', 'white', 'underline')); |
|
71 | - Console::log(' ' . Console::text(' abuseipdb -C ') . |
|
72 | - Console::text('IP', 'yellow') . |
|
73 | - Console::text(' [-d ') . |
|
74 | - Console::text('DAYS', 'yellow') . |
|
75 | - Console::text('] [-v] [-l ') . |
|
76 | - Console::text('LIMIT', 'yellow') . |
|
77 | - Console::text('] [-o ') . |
|
78 | - Console::text('FORMAT', 'yellow') . |
|
70 | + Console::log(' '.Console::text('SYNOPSIS:', 'white', 'underline')); |
|
71 | + Console::log(' '.Console::text(' abuseipdb -C '). |
|
72 | + Console::text('IP', 'yellow'). |
|
73 | + Console::text(' [-d '). |
|
74 | + Console::text('DAYS', 'yellow'). |
|
75 | + Console::text('] [-v] [-l '). |
|
76 | + Console::text('LIMIT', 'yellow'). |
|
77 | + Console::text('] [-o '). |
|
78 | + Console::text('FORMAT', 'yellow'). |
|
79 | 79 | Console::text(']')); |
80 | 80 | |
81 | - Console::log(' ' . Console::text(' abuseipdb -K ') . |
|
82 | - Console::text('NETWORK', 'yellow') . |
|
83 | - Console::text(' [-d ') . |
|
84 | - Console::text('DAYS', 'yellow') . |
|
85 | - Console::text('] [-o ') . |
|
86 | - Console::text('FORMAT', 'yellow') . |
|
81 | + Console::log(' '.Console::text(' abuseipdb -K '). |
|
82 | + Console::text('NETWORK', 'yellow'). |
|
83 | + Console::text(' [-d '). |
|
84 | + Console::text('DAYS', 'yellow'). |
|
85 | + Console::text('] [-o '). |
|
86 | + Console::text('FORMAT', 'yellow'). |
|
87 | 87 | Console::text(']')); |
88 | 88 | |
89 | - Console::log(' ' . Console::text(' abuseipdb -R ') . |
|
90 | - Console::text('IP', 'yellow') . ' -c ' . |
|
91 | - Console::text('CATEGORIES', 'yellow') . ' -m ' . |
|
92 | - Console::text('MESSAGE', 'yellow') . |
|
93 | - Console::text(' [-o ') . |
|
94 | - Console::text('FORMAT', 'yellow') . |
|
89 | + Console::log(' '.Console::text(' abuseipdb -R '). |
|
90 | + Console::text('IP', 'yellow').' -c '. |
|
91 | + Console::text('CATEGORIES', 'yellow').' -m '. |
|
92 | + Console::text('MESSAGE', 'yellow'). |
|
93 | + Console::text(' [-o '). |
|
94 | + Console::text('FORMAT', 'yellow'). |
|
95 | 95 | Console::text(']')); |
96 | 96 | |
97 | - Console::log(' ' . Console::text(' abuseipdb -V ') . |
|
98 | - Console::text('FILE', 'yellow') . |
|
99 | - Console::text(' [-o ') . |
|
100 | - Console::text('FORMAT', 'yellow') . |
|
97 | + Console::log(' '.Console::text(' abuseipdb -V '). |
|
98 | + Console::text('FILE', 'yellow'). |
|
99 | + Console::text(' [-o '). |
|
100 | + Console::text('FORMAT', 'yellow'). |
|
101 | 101 | Console::text(']')); |
102 | 102 | |
103 | - Console::log(' ' . Console::text(' abuseipdb -E ') . |
|
103 | + Console::log(' '.Console::text(' abuseipdb -E '). |
|
104 | 104 | Console::text('IP', 'yellow'). |
105 | - Console::text(' [-o ') . |
|
106 | - Console::text('FORMAT', 'yellow') . |
|
105 | + Console::text(' [-o '). |
|
106 | + Console::text('FORMAT', 'yellow'). |
|
107 | 107 | Console::text(']')); |
108 | 108 | |
109 | - Console::log(' ' . Console::text(' abuseipdb -B ') . |
|
110 | - Console::text('[-l ') . |
|
111 | - Console::text('LIMIT', 'yellow') . |
|
112 | - Console::text('] [-s ') . |
|
113 | - Console::text('SCORE', 'yellow') . |
|
114 | - Console::text('] [-o ') . |
|
115 | - Console::text('FORMAT', 'yellow') . |
|
109 | + Console::log(' '.Console::text(' abuseipdb -B '). |
|
110 | + Console::text('[-l '). |
|
111 | + Console::text('LIMIT', 'yellow'). |
|
112 | + Console::text('] [-s '). |
|
113 | + Console::text('SCORE', 'yellow'). |
|
114 | + Console::text('] [-o '). |
|
115 | + Console::text('FORMAT', 'yellow'). |
|
116 | 116 | Console::text(']')); |
117 | 117 | |
118 | - Console::log(' ' . Console::text(' abuseipdb -L | -G | -h | --version')); |
|
118 | + Console::log(' '.Console::text(' abuseipdb -L | -G | -h | --version')); |
|
119 | 119 | |
120 | 120 | Console::log(); |
121 | - Console::log(' ' . Console::text('OPTIONS:', 'white', 'underline')); |
|
121 | + Console::log(' '.Console::text('OPTIONS:', 'white', 'underline')); |
|
122 | 122 | Console::log(); |
123 | 123 | Console::log(Console::text(' -h, --help', 'white')); |
124 | 124 | Console::log(' Prints the current help.', 'lightgray'); |
@@ -129,57 +129,57 @@ discard block |
||
129 | 129 | Console::log(Console::text(' -L, --list', 'white')); |
130 | 130 | Console::log(' Prints the list report categories.', 'lightgray'); |
131 | 131 | Console::log(); |
132 | - Console::log(Console::text(' -C, --check ', 'white') . Console::text('IP', 'yellow', 'underline')); |
|
132 | + Console::log(Console::text(' -C, --check ', 'white').Console::text('IP', 'yellow', 'underline')); |
|
133 | 133 | Console::log(' Performs a check request for the given IP address. A valid IPv4 or IPv6 address is required.', 'lightgray'); |
134 | 134 | Console::log(); |
135 | - Console::log(Console::text(' -K, --check-block ', 'white') . Console::text('NETWORK', 'yellow', 'underline')); |
|
135 | + Console::log(Console::text(' -K, --check-block ', 'white').Console::text('NETWORK', 'yellow', 'underline')); |
|
136 | 136 | Console::log(' Performs a check-block request for the given network. A valid subnet (v4 or v6) denoted with ', 'lightgray'); |
137 | 137 | Console::log(' CIDR notation is required.', 'lightgray'); |
138 | 138 | Console::log(); |
139 | - Console::log(Console::text(' -d, --days ', 'white') . Console::text('DAYS', 'yellow', 'underline')); |
|
139 | + Console::log(Console::text(' -d, --days ', 'white').Console::text('DAYS', 'yellow', 'underline')); |
|
140 | 140 | Console::log(' For a check or check-block request, defines the maxAgeDays. Min is 1, max is 365, default is 30.', 'lightgray'); |
141 | 141 | Console::log(); |
142 | - Console::log(Console::text(' -R, --report ', 'white') . Console::text('IP', 'yellow', 'underline')); |
|
142 | + Console::log(Console::text(' -R, --report ', 'white').Console::text('IP', 'yellow', 'underline')); |
|
143 | 143 | Console::log(' Performs a report request for the given IP address. A valid IPv4 or IPv6 address is required.', 'lightgray'); |
144 | 144 | Console::log(); |
145 | - Console::log(Console::text(' -V, --bulk-report ', 'white') . Console::text('FILE', 'yellow', 'underline')); |
|
145 | + Console::log(Console::text(' -V, --bulk-report ', 'white').Console::text('FILE', 'yellow', 'underline')); |
|
146 | 146 | Console::log(' Performs a bulk-report request sending a csv file. A valid file name or full path is required.', 'lightgray'); |
147 | 147 | Console::log(); |
148 | 148 | Console::log(Console::text(' -E, --clear ', 'white')); |
149 | 149 | Console::log(' Remove own reports for the given IP address. A valid IPv4 or IPv6 address is required.', 'lightgray'); |
150 | 150 | Console::log(); |
151 | - Console::log(Console::text(' -c, --categories ', 'white') . Console::text('CATEGORIES', 'yellow', 'underline')); |
|
151 | + Console::log(Console::text(' -c, --categories ', 'white').Console::text('CATEGORIES', 'yellow', 'underline')); |
|
152 | 152 | Console::log(' For a report request, defines the report category(ies). Categories must be separate by a comma.', 'lightgray'); |
153 | 153 | Console::log(' Some categories cannot be used alone. A category can be represented by its shortname or by its', 'lightgray'); |
154 | - Console::log(Console::text(' id. Use ','lightgray') . Console::text('abuseipdb -L', 'white') . Console::text(' to print the categories list.','lightgray')); |
|
154 | + Console::log(Console::text(' id. Use ', 'lightgray').Console::text('abuseipdb -L', 'white').Console::text(' to print the categories list.', 'lightgray')); |
|
155 | 155 | Console::log(); |
156 | - Console::log(Console::text(' -m, --message ', 'white') . Console::text('MESSAGE', 'yellow', 'underline')); |
|
156 | + Console::log(Console::text(' -m, --message ', 'white').Console::text('MESSAGE', 'yellow', 'underline')); |
|
157 | 157 | Console::log(' For a report request, defines the message to send with report. Message is required for all', 'lightgray'); |
158 | 158 | Console::log(' report requests.', 'lightgray'); |
159 | 159 | Console::log(); |
160 | 160 | Console::log(Console::text(' -B, --blacklist ', 'white')); |
161 | 161 | Console::log(' Performs a blacklist request. Default limit is 1000. This limit can ne changed with the', 'lightgray'); |
162 | - Console::log(' ' . Console::text('--limit', 'white') . Console::text(' parameter. ', 'lightgray')); |
|
162 | + Console::log(' '.Console::text('--limit', 'white').Console::text(' parameter. ', 'lightgray')); |
|
163 | 163 | Console::log(); |
164 | - Console::log(Console::text(' -l, --limit ', 'white') . Console::text('LIMIT', 'yellow', 'underline')); |
|
164 | + Console::log(Console::text(' -l, --limit ', 'white').Console::text('LIMIT', 'yellow', 'underline')); |
|
165 | 165 | Console::log(' For a blacklist request, defines the limit.', 'lightgray'); |
166 | 166 | Console::log(' For a check request with verbose flag, sets the max number of last reports displayed. Default is 10', 'lightgray'); |
167 | 167 | Console::log(' For a check-block request, sets the max number of IPs displayed. Default is 0 (no limit).', 'lightgray'); |
168 | 168 | Console::log(); |
169 | - Console::log(Console::text(' -o, --output ', 'white') . Console::text('FORMAT', 'yellow', 'underline')); |
|
169 | + Console::log(Console::text(' -o, --output ', 'white').Console::text('FORMAT', 'yellow', 'underline')); |
|
170 | 170 | Console::log(' Defines the output format for API requests. Default is a colorized report, possible formats are', 'lightgray'); |
171 | - Console::log(' '. Console::text('json', 'yellow', 'underline') . ' or ' . Console::text('plaintext', 'yellow', 'underline') . '. Plaintext option prints partial response (blacklist: IPs list, '); |
|
171 | + Console::log(' '.Console::text('json', 'yellow', 'underline').' or '.Console::text('plaintext', 'yellow', 'underline').'. Plaintext option prints partial response (blacklist: IPs list, '); |
|
172 | 172 | Console::log(' check or report: confidence score only, check-block: reported IPs list with confidence score, ', 'lightgray'); |
173 | 173 | Console::log(' bulk-report: number of saved reports, clear: number of deleted reports).', 'lightgray'); |
174 | 174 | Console::log(); |
175 | - Console::log(Console::text(' -s, --score ', 'white'). Console::text('SCORE', 'yellow', 'underline')); |
|
175 | + Console::log(Console::text(' -s, --score ', 'white').Console::text('SCORE', 'yellow', 'underline')); |
|
176 | 176 | Console::log(' For a blacklist request, sets the confidence score minimum. The confidence minimum ', 'lightgray'); |
177 | 177 | Console::log(' must be between 25 and 100. This parameter is subscriber feature (not honored otherwise, allways 100).', 'lightgray'); |
178 | 178 | Console::log(); |
179 | 179 | Console::log(Console::text(' -v, --verbose ', 'white')); |
180 | 180 | Console::log(' For a check request, display additional fields like the x last reports. This increases ', 'lightgray'); |
181 | 181 | Console::log(Console::text(' request time and response size. Max number of last reports displayed can be changed with the ', 'lightgray')); |
182 | - Console::log(' ' . Console::text('--limit', 'white') . Console::text(' parameter. ', 'lightgray')); |
|
182 | + Console::log(' '.Console::text('--limit', 'white').Console::text(' parameter. ', 'lightgray')); |
|
183 | 183 | Console::log(); |
184 | 184 | Console::log(Console::text(' --version', 'white')); |
185 | 185 | Console::log(' Prints the current version.', 'lightgray'); |
@@ -201,11 +201,11 @@ discard block |
||
201 | 201 | |
202 | 202 | self::printTitle(Console::text(' ► Current configuration ', 'darkgray')); |
203 | 203 | |
204 | - Console::log(Console::text(' api_key:[', 'white') . Console::text($conf['apiKey'], 'green') . Console::text(']', 'white')); |
|
204 | + Console::log(Console::text(' api_key:[', 'white').Console::text($conf['apiKey'], 'green').Console::text(']', 'white')); |
|
205 | 205 | Console::log(Console::text(' self_ips:', 'white')); |
206 | 206 | |
207 | 207 | foreach ($conf['selfIps'] as $ip) { |
208 | - Console::log(Console::text(' [', 'white') . Console::text($ip, 'green') . Console::text(']', 'white')); |
|
208 | + Console::log(Console::text(' [', 'white').Console::text($ip, 'green').Console::text(']', 'white')); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | Console::log(); |
@@ -226,10 +226,10 @@ discard block |
||
226 | 226 | |
227 | 227 | $categories = ApiHandler::getCategories(); |
228 | 228 | $rowHeaders = [ |
229 | - Console::text('ShortName', 'darkgray') => 15, |
|
230 | - Console::text('Id', 'darkgray') => 2, |
|
231 | - Console::text('Full name', 'darkgray') => 18, |
|
232 | - Console::text('Can be alone?', 'darkgray') => 15 |
|
229 | + Console::text('ShortName', 'darkgray') => 15, |
|
230 | + Console::text('Id', 'darkgray') => 2, |
|
231 | + Console::text('Full name', 'darkgray') => 18, |
|
232 | + Console::text('Can be alone?', 'darkgray') => 15 |
|
233 | 233 | ]; |
234 | 234 | Console::$verticalSeparator = ' '; |
235 | 235 | Console::$verticalInnerSeparator = ' '; |
@@ -239,17 +239,16 @@ discard block |
||
239 | 239 | |
240 | 240 | foreach ($categories as $cat) { |
241 | 241 | $id = Console::text($cat[1], 'white'); |
242 | - $standalone = $cat[3] ? Console::text('✓', 'green') . Console::text(' true ', 'lightgray') : |
|
243 | - Console::text('✗', 'red') . Console::text(' false', 'darkgray'); |
|
244 | - $shortName = Console::text($cat[0], 'white'); |
|
245 | - $fullName = Console::text($cat[2], 'lightgray'); |
|
242 | + $standalone = $cat[3] ? Console::text('✓', 'green').Console::text(' true ', 'lightgray') : Console::text('✗', 'red').Console::text(' false', 'darkgray'); |
|
243 | + $shortName = Console::text($cat[0], 'white'); |
|
244 | + $fullName = Console::text($cat[2], 'lightgray'); |
|
246 | 245 | |
247 | 246 | Console::log( |
248 | 247 | Console::TableRowStart(). |
249 | - Console::TableRowCell( $shortName , 15). |
|
250 | - Console::TableRowCell( $id , 2, Console::ALIGN_CENTER). |
|
251 | - Console::TableRowCell( $fullName , 18). |
|
252 | - Console::TableRowCell( $standalone , 15, Console::ALIGN_CENTER) |
|
248 | + Console::TableRowCell($shortName, 15). |
|
249 | + Console::TableRowCell($id, 2, Console::ALIGN_CENTER). |
|
250 | + Console::TableRowCell($fullName, 18). |
|
251 | + Console::TableRowCell($standalone, 15, Console::ALIGN_CENTER) |
|
253 | 252 | ); |
254 | 253 | } |
255 | 254 | //Console::log(Console::tableRowSeparator($rowHeaders), 'darkgray'); |
@@ -268,11 +267,11 @@ discard block |
||
268 | 267 | */ |
269 | 268 | protected static function reportIP(array $arguments): void |
270 | 269 | { |
271 | - $ip = self::getArgumentValue($arguments,'R', 'report'); |
|
272 | - $cats = self::getArgumentValue($arguments,'c', 'categories'); |
|
273 | - $message = self::getArgumentValue($arguments,'m', 'message'); |
|
270 | + $ip = self::getArgumentValue($arguments, 'R', 'report'); |
|
271 | + $cats = self::getArgumentValue($arguments, 'c', 'categories'); |
|
272 | + $message = self::getArgumentValue($arguments, 'm', 'message'); |
|
274 | 273 | |
275 | - self::printTitle(Console::text(' ► Report IP: ', 'darkgray') . Console::text(escapeshellcmd($ip), 'white')); |
|
274 | + self::printTitle(Console::text(' ► Report IP: ', 'darkgray').Console::text(escapeshellcmd($ip), 'white')); |
|
276 | 275 | self::printTempMessage(); |
277 | 276 | |
278 | 277 | // Peforms request |
@@ -283,7 +282,7 @@ discard block |
||
283 | 282 | self::clearTempMessage(); |
284 | 283 | |
285 | 284 | // check for errors / empty response |
286 | - if (self::hasErrors($report)){ |
|
285 | + if (self::hasErrors($report)) { |
|
287 | 286 | self::printFooter(); |
288 | 287 | Program::exit(1); |
289 | 288 | } |
@@ -292,14 +291,14 @@ discard block |
||
292 | 291 | $score = empty($report->data->abuseConfidenceScore) ? 0 : $report->data->abuseConfidenceScore; |
293 | 292 | $scoreColor = self::getScoreColor($score); |
294 | 293 | |
295 | - switch (self::$outputFormat){ |
|
294 | + switch (self::$outputFormat) { |
|
296 | 295 | case self::OUTPUT_JSON: |
297 | 296 | echo json_encode($report, JSON_PRETTY_PRINT); |
298 | 297 | break; |
299 | 298 | |
300 | 299 | case self::OUTPUT_DEFAULT: |
301 | 300 | Console::log( |
302 | - Console::text(' ✓', 'green').Console::text(' IP: [', 'white') . |
|
301 | + Console::text(' ✓', 'green').Console::text(' IP: [', 'white'). |
|
303 | 302 | Console::text($ip, $scoreColor).Console::text('] successfully reported', 'white') |
304 | 303 | ); |
305 | 304 | Console::log(Console::text(' Confidence score: ', 'white').self::getScoreBadge($score)); |
@@ -325,26 +324,26 @@ discard block |
||
325 | 324 | */ |
326 | 325 | protected static function bulkReport(array $arguments): void |
327 | 326 | { |
328 | - $fileName = self::getArgumentValue($arguments,'V', 'bulk-report'); |
|
327 | + $fileName = self::getArgumentValue($arguments, 'V', 'bulk-report'); |
|
329 | 328 | |
330 | - self::printTitle(Console::text(' ► Bulk report for file: ', 'darkgray') . Console::text(escapeshellcmd($fileName), 'white')); |
|
329 | + self::printTitle(Console::text(' ► Bulk report for file: ', 'darkgray').Console::text(escapeshellcmd($fileName), 'white')); |
|
331 | 330 | self::printTempMessage(); |
332 | 331 | |
333 | 332 | // Peforms request |
334 | 333 | $timeStart = microtime(true); |
335 | 334 | $response = self::$api->bulkReport($fileName)->getObject(); |
336 | 335 | $timeEnd = microtime(true); |
337 | - $time = $timeEnd - $timeStart; // request time |
|
336 | + $time = $timeEnd - $timeStart; // request time |
|
338 | 337 | self::clearTempMessage(); |
339 | 338 | |
340 | 339 | // check for errors / empty response |
341 | - if (self::hasErrors($response)){ |
|
340 | + if (self::hasErrors($response)) { |
|
342 | 341 | self::printFooter(); |
343 | 342 | Program::exit(1); |
344 | 343 | } |
345 | 344 | |
346 | 345 | // ✓ Done |
347 | - switch (self::$outputFormat){ |
|
346 | + switch (self::$outputFormat) { |
|
348 | 347 | case self::OUTPUT_JSON: |
349 | 348 | echo json_encode($response, JSON_PRETTY_PRINT); |
350 | 349 | break; |
@@ -359,7 +358,7 @@ discard block |
||
359 | 358 | |
360 | 359 | case self::OUTPUT_PLAINTEXT: |
361 | 360 | $nbSavedReports = isset($response->data->savedReports) ? $response->data->savedReports : 0; |
362 | - echo $nbSavedReports . PHP_EOL; |
|
361 | + echo $nbSavedReports.PHP_EOL; |
|
363 | 362 | break; |
364 | 363 | |
365 | 364 | } |
@@ -376,8 +375,8 @@ discard block |
||
376 | 375 | */ |
377 | 376 | protected static function clearIP(array $arguments): void |
378 | 377 | { |
379 | - $ip = self::getArgumentValue($arguments,'E', 'clear'); |
|
380 | - self::printTitle(Console::text(' ► Clear reports for IP: ', 'darkgray') . Console::text(escapeshellcmd($ip), 'white')); |
|
378 | + $ip = self::getArgumentValue($arguments, 'E', 'clear'); |
|
379 | + self::printTitle(Console::text(' ► Clear reports for IP: ', 'darkgray').Console::text(escapeshellcmd($ip), 'white')); |
|
381 | 380 | |
382 | 381 | // Peforms request |
383 | 382 | self::printTempMessage(); |
@@ -388,22 +387,22 @@ discard block |
||
388 | 387 | self::clearTempMessage(); |
389 | 388 | |
390 | 389 | // check for errors / empty response |
391 | - if (self::hasErrors($response)){ |
|
390 | + if (self::hasErrors($response)) { |
|
392 | 391 | self::printFooter($time); |
393 | 392 | Program::exit(1); |
394 | 393 | } |
395 | 394 | |
396 | 395 | // ✓ Done: print deleted report number |
397 | - switch (self::$outputFormat){ |
|
396 | + switch (self::$outputFormat) { |
|
398 | 397 | case self::OUTPUT_JSON: |
399 | 398 | echo json_encode($response, JSON_PRETTY_PRINT); |
400 | 399 | break; |
401 | 400 | |
402 | 401 | case self::OUTPUT_DEFAULT: |
403 | 402 | Console::log( |
404 | - Console::text(' ✓', 'green') . |
|
405 | - Console::text(' Successfull clear request for IP: [', 'white') . |
|
406 | - Console::text($ip, 'lightyellow') . |
|
403 | + Console::text(' ✓', 'green'). |
|
404 | + Console::text(' Successfull clear request for IP: [', 'white'). |
|
405 | + Console::text($ip, 'lightyellow'). |
|
407 | 406 | Console::text(']', 'white') |
408 | 407 | ); |
409 | 408 | self::printResult(' Deleted reports: ', $response->data->numReportsDeleted ?? 0, 'lightyellow'); |
@@ -412,7 +411,7 @@ discard block |
||
412 | 411 | break; |
413 | 412 | |
414 | 413 | case self::OUTPUT_PLAINTEXT: |
415 | - echo ($response->data->numReportsDeleted ?? 0) . PHP_EOL; |
|
414 | + echo ($response->data->numReportsDeleted ?? 0).PHP_EOL; |
|
416 | 415 | break; |
417 | 416 | |
418 | 417 | } |
@@ -432,8 +431,8 @@ discard block |
||
432 | 431 | self::printTitle(Console::text(' ► Get Blacklist ', 'darkgray')); |
433 | 432 | |
434 | 433 | $plainText = (self::$outputFormat === self::OUTPUT_PLAINTEXT); |
435 | - $limit = self::getNumericParameter($arguments,'l', 'limit', 1000); |
|
436 | - $scoreMin = self::getNumericParameter($arguments,'s', 'score', 100); |
|
434 | + $limit = self::getNumericParameter($arguments, 'l', 'limit', 1000); |
|
435 | + $scoreMin = self::getNumericParameter($arguments, 's', 'score', 100); |
|
437 | 436 | |
438 | 437 | self::printTempMessage(); |
439 | 438 | |
@@ -448,13 +447,13 @@ discard block |
||
448 | 447 | // response could be json on error, while plaintext flag is set |
449 | 448 | $decodedResponse = $response->getObject(); |
450 | 449 | |
451 | - if (self::hasErrors($decodedResponse, false)){ |
|
450 | + if (self::hasErrors($decodedResponse, false)) { |
|
452 | 451 | self::printFooter($time); |
453 | 452 | Program::exit(1); |
454 | 453 | } |
455 | 454 | |
456 | 455 | // ✓ Done: print deleted report number |
457 | - switch (self::$outputFormat){ |
|
456 | + switch (self::$outputFormat) { |
|
458 | 457 | case self::OUTPUT_JSON: |
459 | 458 | echo json_encode($decodedResponse, JSON_PRETTY_PRINT); |
460 | 459 | break; |
@@ -463,7 +462,7 @@ discard block |
||
463 | 462 | // print list |
464 | 463 | self::printResult(' List generated at: ', self::getDate($decodedResponse->meta->generatedAt), 'lightyellow', ''); |
465 | 464 | Console::log(); |
466 | - foreach ($decodedResponse->data as $report){ |
|
465 | + foreach ($decodedResponse->data as $report) { |
|
467 | 466 | $score = empty($report->abuseConfidenceScore) ? 0 : $report->abuseConfidenceScore; |
468 | 467 | $defaultColor = self::getScoreColor($score); |
469 | 468 | |
@@ -498,12 +497,12 @@ discard block |
||
498 | 497 | */ |
499 | 498 | protected static function checkBlock(array $arguments): void |
500 | 499 | { |
501 | - $network = self::getArgumentValue($arguments,'K', 'check-block'); |
|
500 | + $network = self::getArgumentValue($arguments, 'K', 'check-block'); |
|
502 | 501 | |
503 | - self::printTitle(Console::text(' ► Check network: ', 'darkgray') . Console::text(escapeshellcmd($network), 'white') . Console::text('', 'darkgray')); |
|
502 | + self::printTitle(Console::text(' ► Check network: ', 'darkgray').Console::text(escapeshellcmd($network), 'white').Console::text('', 'darkgray')); |
|
504 | 503 | |
505 | 504 | $maxAge = self::getNumericParameter($arguments, 'd', 'days', 30); |
506 | - $limit = self::getNumericParameter($arguments,'l', 'limit', 0); // 0 mean no limit |
|
505 | + $limit = self::getNumericParameter($arguments, 'l', 'limit', 0); // 0 mean no limit |
|
507 | 506 | |
508 | 507 | self::printTempMessage(); |
509 | 508 | |
@@ -514,19 +513,19 @@ discard block |
||
514 | 513 | self::clearTempMessage(); |
515 | 514 | |
516 | 515 | // check for errors / empty response |
517 | - if (self::hasErrors($check)){ |
|
516 | + if (self::hasErrors($check)) { |
|
518 | 517 | self::printFooter($time); |
519 | 518 | Program::exit(1); |
520 | 519 | } |
521 | 520 | |
522 | - switch (self::$outputFormat){ |
|
521 | + switch (self::$outputFormat) { |
|
523 | 522 | case self::OUTPUT_JSON: |
524 | 523 | echo json_encode($check, JSON_PRETTY_PRINT); |
525 | 524 | break; |
526 | 525 | |
527 | 526 | case self::OUTPUT_DEFAULT: |
528 | 527 | self::printCheckBlockDetail($check); |
529 | - self::printCheckBlockReportedIP($check,$maxAge,$limit); |
|
528 | + self::printCheckBlockReportedIP($check, $maxAge, $limit); |
|
530 | 529 | Console::log(); |
531 | 530 | self::printFooter($time); |
532 | 531 | break; |
@@ -535,8 +534,8 @@ discard block |
||
535 | 534 | $nbReports = isset($check->data->reportedAddress) ? count($check->data->reportedAddress) : 0; |
536 | 535 | if ($nbReports > 0) { |
537 | 536 | $numberDiplayedReports = 0; |
538 | - foreach ($check->data->reportedAddress as $report){ |
|
539 | - echo ($report->ipAddress) . ' ' . $report->abuseConfidenceScore . PHP_EOL; |
|
537 | + foreach ($check->data->reportedAddress as $report) { |
|
538 | + echo ($report->ipAddress).' '.$report->abuseConfidenceScore.PHP_EOL; |
|
540 | 539 | |
541 | 540 | // counter |
542 | 541 | $numberDiplayedReports++; |
@@ -560,14 +559,14 @@ discard block |
||
560 | 559 | */ |
561 | 560 | protected static function checkIP(array $arguments): void |
562 | 561 | { |
563 | - $ip = self::getArgumentValue($arguments,'C', 'check'); |
|
562 | + $ip = self::getArgumentValue($arguments, 'C', 'check'); |
|
564 | 563 | |
565 | - self::printTitle(Console::text(' ► Check IP: ', 'darkgray') . Console::text(escapeshellcmd($ip), 'white') . Console::text('', 'darkgray')); |
|
564 | + self::printTitle(Console::text(' ► Check IP: ', 'darkgray').Console::text(escapeshellcmd($ip), 'white').Console::text('', 'darkgray')); |
|
566 | 565 | |
567 | - $verbose = self::inArguments($arguments,'v', 'verbose'); |
|
566 | + $verbose = self::inArguments($arguments, 'v', 'verbose'); |
|
568 | 567 | $maxAge = self::getNumericParameter($arguments, 'd', 'days', 30); |
569 | - $maxReportsNumber = self::getNumericParameter($arguments,'l', 'limit', 10); |
|
570 | - $ip = self::getArgumentValue($arguments,'C', 'check'); |
|
568 | + $maxReportsNumber = self::getNumericParameter($arguments, 'l', 'limit', 10); |
|
569 | + $ip = self::getArgumentValue($arguments, 'C', 'check'); |
|
571 | 570 | |
572 | 571 | self::printTempMessage(); |
573 | 572 | $timeStart = microtime(true); |
@@ -577,7 +576,7 @@ discard block |
||
577 | 576 | self::clearTempMessage(); |
578 | 577 | |
579 | 578 | // check for errors / empty response |
580 | - if (self::hasErrors($check)){ |
|
579 | + if (self::hasErrors($check)) { |
|
581 | 580 | self::printFooter($time); |
582 | 581 | Program::exit(1); |
583 | 582 | } |
@@ -585,7 +584,7 @@ discard block |
||
585 | 584 | // score and data color (depending of abuseConfidenceScore) |
586 | 585 | $score = empty($check->data->abuseConfidenceScore) ? 0 : $check->data->abuseConfidenceScore; |
587 | 586 | |
588 | - switch (self::$outputFormat){ |
|
587 | + switch (self::$outputFormat) { |
|
589 | 588 | case self::OUTPUT_JSON: |
590 | 589 | echo json_encode($check, JSON_PRETTY_PRINT); |
591 | 590 | break; |
@@ -595,7 +594,7 @@ discard block |
||
595 | 594 | self::printCheckScore($check); |
596 | 595 | self::printCheckDetail($check, $defaultColor); |
597 | 596 | self::printCheckReports($check, $maxAge, $defaultColor); |
598 | - if ($verbose){ |
|
597 | + if ($verbose) { |
|
599 | 598 | self::printCheckLastReports($check, $maxReportsNumber); |
600 | 599 | } |
601 | 600 | Console::log(); |
@@ -603,7 +602,7 @@ discard block |
||
603 | 602 | break; |
604 | 603 | |
605 | 604 | case self::OUTPUT_PLAINTEXT: |
606 | - echo ($check->data->abuseConfidenceScore ?? 0) . PHP_EOL; |
|
605 | + echo ($check->data->abuseConfidenceScore ?? 0).PHP_EOL; |
|
607 | 606 | break; |
608 | 607 | |
609 | 608 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | /** |
37 | 37 | * @var string |
38 | 38 | */ |
39 | - const LONG_ARGUMENTS = ['output:', 'config', 'list', 'blacklist', 'check:', 'check-block:', 'days:', 'report:', 'categories:', 'message:', 'limit:', 'clear:',' bulk-report:', 'help', 'verbose', 'score:', 'version']; |
|
39 | + const LONG_ARGUMENTS = ['output:', 'config', 'list', 'blacklist', 'check:', 'check-block:', 'days:', 'report:', 'categories:', 'message:', 'limit:', 'clear:', ' bulk-report:', 'help', 'verbose', 'score:', 'version']; |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @var string |
@@ -57,22 +57,22 @@ discard block |
||
57 | 57 | * @var array |
58 | 58 | */ |
59 | 59 | protected static $basicCommands = [ |
60 | - ['h', 'help', 'printHelp'], |
|
61 | - ['version', 'version', 'printVersion'], // no short arg |
|
62 | - ['L', 'list', 'printCategories'], |
|
60 | + ['h', 'help', 'printHelp'], |
|
61 | + ['version', 'version', 'printVersion'], // no short arg |
|
62 | + ['L', 'list', 'printCategories'], |
|
63 | 63 | ]; |
64 | 64 | |
65 | 65 | /** |
66 | 66 | * @var array |
67 | 67 | */ |
68 | 68 | protected static $mainCommands = [ |
69 | - ['G', 'config', 'printConfig'], // require handler |
|
70 | - ['C', 'check', 'checkIP'], |
|
71 | - ['K', 'check-block', 'checkBlock'], |
|
72 | - ['R', 'report', 'reportIP'], |
|
73 | - ['V', 'bulk-report', 'bulkReport'], |
|
74 | - ['B', 'blacklist', 'getBlacklist'], |
|
75 | - ['E', 'clear', 'clearIP'], |
|
69 | + ['G', 'config', 'printConfig'], // require handler |
|
70 | + ['C', 'check', 'checkIP'], |
|
71 | + ['K', 'check-block', 'checkBlock'], |
|
72 | + ['R', 'report', 'reportIP'], |
|
73 | + ['V', 'bulk-report', 'bulkReport'], |
|
74 | + ['B', 'blacklist', 'getBlacklist'], |
|
75 | + ['E', 'clear', 'clearIP'], |
|
76 | 76 | ]; |
77 | 77 | |
78 | 78 | /** |
@@ -86,14 +86,14 @@ discard block |
||
86 | 86 | */ |
87 | 87 | protected static function parseCommand(array $arguments): bool |
88 | 88 | { |
89 | - foreach(self::$basicCommands as $cmd){ |
|
90 | - if (self::inArguments($arguments, $cmd[0], $cmd[1])){ |
|
89 | + foreach (self::$basicCommands as $cmd) { |
|
90 | + if (self::inArguments($arguments, $cmd[0], $cmd[1])) { |
|
91 | 91 | call_user_func(__NAMESPACE__.'\AbuseIPDBClient::'.$cmd[2], null); |
92 | 92 | return true; |
93 | 93 | } |
94 | 94 | } |
95 | - foreach(self::$mainCommands as $cmd){ |
|
96 | - if (self::inArguments($arguments, $cmd[0], $cmd[1])){ |
|
95 | + foreach (self::$mainCommands as $cmd) { |
|
96 | + if (self::inArguments($arguments, $cmd[0], $cmd[1])) { |
|
97 | 97 | self::createHandler(); |
98 | 98 | self::setOutputFormat($arguments); |
99 | 99 | call_user_func(__NAMESPACE__.'\AbuseIPDBClient::'.$cmd[2], $arguments); |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | $given = self::getArgumentValue($arguments, 'o', 'output') ?? 'default'; |
119 | 119 | $output = empty($given) ? 'default' : $given; |
120 | 120 | self::validate(in_array($output, ['default', 'json', 'plaintext']), 'Invalid output argument given.'); |
121 | - self::$outputFormat = $output ; |
|
121 | + self::$outputFormat = $output; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | protected static function createHandler(): void |
135 | 135 | { |
136 | 136 | try { |
137 | - $mainConfPath = self::$configPath . DIRECTORY_SEPARATOR . 'conf.ini'; |
|
138 | - $localConfPath = self::$configPath . DIRECTORY_SEPARATOR . 'local.ini'; |
|
137 | + $mainConfPath = self::$configPath.DIRECTORY_SEPARATOR.'conf.ini'; |
|
138 | + $localConfPath = self::$configPath.DIRECTORY_SEPARATOR.'local.ini'; |
|
139 | 139 | |
140 | 140 | // Check main file exists and is readable |
141 | 141 | // Even if a local file exists, main file must be here (throws ex otherwise) |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $selfIps = self::extractSelfIpsFromConf($mainConfigArray, $localConfigArray); |
146 | 146 | $apiKey = self::extractApiKeyFromConf($mainConfigArray, $localConfigArray); |
147 | 147 | |
148 | - self::$api = new QuietApiHandler($apiKey, $selfIps); |
|
148 | + self::$api = new QuietApiHandler($apiKey, $selfIps); |
|
149 | 149 | } catch (\Exception $e) { |
150 | 150 | self::error($e->getMessage()); |
151 | 151 | self::printFooter(); |
@@ -165,10 +165,10 @@ discard block |
||
165 | 165 | */ |
166 | 166 | protected static function extractSelfIpsFromConf(array $conf, array $localConf): array |
167 | 167 | { |
168 | - if (array_key_exists('self_ips', $localConf)){ |
|
168 | + if (array_key_exists('self_ips', $localConf)) { |
|
169 | 169 | return array_map('trim', explode(',', $localConf['self_ips'])); |
170 | 170 | } |
171 | - if (array_key_exists('self_ips', $conf)){ |
|
171 | + if (array_key_exists('self_ips', $conf)) { |
|
172 | 172 | return array_map('trim', explode(',', $conf['self_ips'])); |
173 | 173 | } |
174 | 174 | return []; |
@@ -187,15 +187,15 @@ discard block |
||
187 | 187 | { |
188 | 188 | $key = ''; |
189 | 189 | |
190 | - if (array_key_exists('api_key', $localConf)){ |
|
190 | + if (array_key_exists('api_key', $localConf)) { |
|
191 | 191 | $key = $localConf['api_key']; |
192 | 192 | } |
193 | 193 | |
194 | - if (empty($key) && array_key_exists('api_key', $conf)){ |
|
194 | + if (empty($key) && array_key_exists('api_key', $conf)) { |
|
195 | 195 | $key = $conf['api_key']; |
196 | 196 | } |
197 | 197 | |
198 | - if (empty($key)){ |
|
198 | + if (empty($key)) { |
|
199 | 199 | throw new \RuntimeException('Api key is missing.'); |
200 | 200 | } |
201 | 201 | |
@@ -215,21 +215,21 @@ discard block |
||
215 | 215 | */ |
216 | 216 | protected static function loadConfigFile(string $path, bool $mandatory = false): array |
217 | 217 | { |
218 | - if (file_exists($path) && is_file($path)){ |
|
218 | + if (file_exists($path) && is_file($path)) { |
|
219 | 219 | |
220 | 220 | // If main file or a local file is not readable then throws ex. |
221 | - if (!is_readable($path)){ |
|
221 | + if (!is_readable($path)) { |
|
222 | 222 | throw new \RuntimeException('The configuration file ['.$path.'] is not readable.'); |
223 | 223 | } |
224 | 224 | |
225 | - $conf = parse_ini_file($path, false); // load without sections... |
|
226 | - if ($conf === false){ |
|
225 | + $conf = parse_ini_file($path, false); // load without sections... |
|
226 | + if ($conf === false) { |
|
227 | 227 | throw new \RuntimeException('Unable to read configuration file ['.$path.'].'); |
228 | 228 | } |
229 | 229 | return $conf; |
230 | 230 | } |
231 | 231 | |
232 | - if ($mandatory){ |
|
232 | + if ($mandatory) { |
|
233 | 233 | throw new \RuntimeException('The configuration file ['.$path.'] does not exist.'); |
234 | 234 | } |
235 | 235 | return []; |