@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | protected static function printCheckScore(object $response): void |
40 | 40 | { |
41 | 41 | $score = empty($response->data->abuseConfidenceScore) ? 0 : $response->data->abuseConfidenceScore; |
42 | - $line = Console::text(Console::pad(' Confidence score:', 23), 'white') . self::getScoreBadge($score); |
|
42 | + $line = Console::text(Console::pad(' Confidence score:', 23), 'white').self::getScoreBadge($score); |
|
43 | 43 | Console::log($line); |
44 | 44 | } |
45 | 45 | |
@@ -58,26 +58,26 @@ discard block |
||
58 | 58 | // self::printResult(' isPublic', $response->data->isPublic, $defaultColor); |
59 | 59 | // self::printResult(' ipVersion', $response->data->ipVersion, $defaultColor); |
60 | 60 | |
61 | - $line = self::printResult(Console::pad(' Whitelisted:', 23), $response->data->isWhitelisted ? 'true': 'false', $color, '', false); |
|
61 | + $line = self::printResult(Console::pad(' Whitelisted:', 23), $response->data->isWhitelisted ? 'true' : 'false', $color, '', false); |
|
62 | 62 | $line .= $response->data->isWhitelisted ? Console::text(' ★', 'green') : ''; |
63 | 63 | Console::log($line); |
64 | 64 | |
65 | 65 | self::printResult(Console::pad(' Country code:', 23), $response->data->countryCode, $color); |
66 | 66 | |
67 | - if (!empty($response->data->countryName)){ |
|
67 | + if (!empty($response->data->countryName)) { |
|
68 | 68 | self::printResult(Console::pad(' Country name:', 23), $response->data->countryName, $color); |
69 | 69 | } |
70 | 70 | |
71 | 71 | self::printResult(Console::pad(' ISP:', 23), $response->data->isp, $color); |
72 | 72 | |
73 | - if ($response->data->usageType){ |
|
73 | + if ($response->data->usageType) { |
|
74 | 74 | $line = self::printResult(Console::pad(' Usage type:', 23), $response->data->usageType, $color, '', false); |
75 | 75 | $line .= $response->data->usageType === 'Reserved' ? Console::text(' ◆', 'green') : ''; |
76 | 76 | Console::log($line); |
77 | 77 | } |
78 | 78 | |
79 | 79 | $hostames = implode(', ', array_filter($response->data->hostnames)) ?? null; |
80 | - if (!empty($hostames)){ |
|
80 | + if (!empty($hostames)) { |
|
81 | 81 | self::printResult(Console::pad(' Hostname(s):', 23), $hostames, $color); |
82 | 82 | } |
83 | 83 | |
@@ -99,28 +99,28 @@ discard block |
||
99 | 99 | { |
100 | 100 | $nbReport = $response->data->totalReports && is_numeric($response->data->totalReports) ? intval($response->data->totalReports) : 0; |
101 | 101 | |
102 | - if ($nbReport > 0 ){ |
|
102 | + if ($nbReport > 0) { |
|
103 | 103 | $line = self::printResult(Console::pad(' Total reports:', 23), $nbReport, $color, '', false); |
104 | 104 | $line .= self::printResult(' from ', $response->data->numDistinctUsers, $color, '', false); |
105 | - $line .= Console::text($nbReport > 0 ? ' distinct users': ' user', 'white'); |
|
105 | + $line .= Console::text($nbReport > 0 ? ' distinct users' : ' user', 'white'); |
|
106 | 106 | Console::log($line); |
107 | 107 | |
108 | 108 | } else { |
109 | 109 | // no reports |
110 | - $period = $maxAge > 1 ? 'in last '. $maxAge . ' days': ' today'; |
|
111 | - if (empty($response->data->lastReportedAt)){ |
|
112 | - Console::log( Console::text(' ✓', 'green') . Console::text(' Not reported ' . $period)); |
|
110 | + $period = $maxAge > 1 ? 'in last '.$maxAge.' days' : ' today'; |
|
111 | + if (empty($response->data->lastReportedAt)) { |
|
112 | + Console::log(Console::text(' ✓', 'green').Console::text(' Not reported '.$period)); |
|
113 | 113 | |
114 | 114 | } else { |
115 | 115 | // in some case, we have no reports but lastReportedAt in not empty (when deleting reports for example) |
116 | 116 | // maybe a bug or cache in api |
117 | 117 | // In this case Set total 0 and let print lastReportedAt |
118 | - $line = self::printResult(Console::pad(' Total reports:', 23), $nbReport, $color, '', false); |
|
118 | + $line = self::printResult(Console::pad(' Total reports:', 23), $nbReport, $color, '', false); |
|
119 | 119 | Console::log($line); |
120 | 120 | } |
121 | 121 | } |
122 | 122 | |
123 | - if (!empty($response->data->lastReportedAt)){ |
|
123 | + if (!empty($response->data->lastReportedAt)) { |
|
124 | 124 | self::printResult(Console::pad(' Last reported at:', 23), self::getDate($response->data->lastReportedAt), $color); |
125 | 125 | } |
126 | 126 | } |
@@ -140,12 +140,12 @@ discard block |
||
140 | 140 | { |
141 | 141 | $nbLastReports = isset($response->data->reports) ? count($response->data->reports) : 0; |
142 | 142 | |
143 | - if ($nbLastReports > 0){ |
|
143 | + if ($nbLastReports > 0) { |
|
144 | 144 | Console::log(' Last reports:', 'white'); |
145 | 145 | $numberDiplayedReports = 0; |
146 | 146 | $defaultColor = 'lightyellow'; // reset color for last reports |
147 | 147 | |
148 | - foreach ($response->data->reports as $report){ |
|
148 | + foreach ($response->data->reports as $report) { |
|
149 | 149 | self::printLastReport($report); |
150 | 150 | $numberDiplayedReports++; |
151 | 151 | |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | $line .= Console::text($numberDiplayedReports, $defaultColor); |
155 | 155 | $line .= Console::text('/', 'white'); |
156 | 156 | $line .= Console::text($nbLastReports, $defaultColor); |
157 | - $line .= Console::text($numberDiplayedReports > 1 ? ' reports displayed)': ' report displayed)', 'white'); |
|
157 | + $line .= Console::text($numberDiplayedReports > 1 ? ' reports displayed)' : ' report displayed)', 'white'); |
|
158 | 158 | Console::log($line); |
159 | 159 | break; |
160 | 160 | } |
@@ -179,15 +179,15 @@ discard block |
||
179 | 179 | $line = Console::text(' →', $defaultColor); |
180 | 180 | $line .= self::printResult(' reported at: ', self::getDate($report->reportedAt), $defaultColor, '', false); |
181 | 181 | // $line .= self::printResult(' by user: ', $report->reporterId, $defaultColor, '', false); |
182 | - if (isset($report->reporterCountryCode) && isset($report->reporterCountryName)){ |
|
182 | + if (isset($report->reporterCountryCode) && isset($report->reporterCountryName)) { |
|
183 | 183 | $line .= Console::text(' from: ', 'white'); |
184 | 184 | $line .= self::printResult('', $report->reporterCountryCode, $defaultColor, '', false); |
185 | 185 | $line .= Console::text(' - ', 'white'); |
186 | 186 | $line .= self::printResult('', $report->reporterCountryName, $defaultColor, '', false); |
187 | 187 | } |
188 | - $line .= Console::text(' with categor' . (count($categories) > 1 ? "ies: " : "y: "), 'white'); |
|
188 | + $line .= Console::text(' with categor'.(count($categories) > 1 ? "ies: " : "y: "), 'white'); |
|
189 | 189 | foreach ($categories as $key => $cat) { |
190 | - $line .= Console::text($key==0 ? '' : ',' , 'white') . Console::text($cat, $defaultColor); |
|
190 | + $line .= Console::text($key == 0 ? '' : ',', 'white').Console::text($cat, $defaultColor); |
|
191 | 191 | } |
192 | 192 | Console::log($line); |
193 | 193 | } |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | private static function getLastReportsCategories(object $report): array |
205 | 205 | { |
206 | 206 | $categories = []; |
207 | - foreach (array_filter($report->categories) as $catId){ |
|
207 | + foreach (array_filter($report->categories) as $catId) { |
|
208 | 208 | $cat = ApiHandler::getCategoryNameById(strval($catId)); |
209 | 209 | if ($cat !== false) { |
210 | 210 | $categories[] = $cat; |
@@ -36,17 +36,17 @@ discard block |
||
36 | 36 | /** |
37 | 37 | * @var string |
38 | 38 | */ |
39 | - const OUTPUT_JSON = 'json'; |
|
39 | + const OUTPUT_JSON = 'json'; |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @var string |
43 | 43 | */ |
44 | - const OUTPUT_DEFAULT = 'default'; |
|
44 | + const OUTPUT_DEFAULT = 'default'; |
|
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @var string |
48 | 48 | */ |
49 | - const OUTPUT_PLAINTEXT = 'plaintext'; |
|
49 | + const OUTPUT_PLAINTEXT = 'plaintext'; |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * @var string $outputFormat |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | protected static function printTempMessage(): void |
92 | 92 | { |
93 | 93 | if (self::isDefaultOuput()) { |
94 | - Console::reLog(Console::text(' ? ', 'green') . Console::text('waiting for api response', 'white') . Console::text(' ... ', 'green')); |
|
94 | + Console::reLog(Console::text(' ? ', 'green').Console::text('waiting for api response', 'white').Console::text(' ... ', 'green')); |
|
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | self::printLogo(); |
146 | 146 | |
147 | 147 | Console::log(); |
148 | - Console::log(Console::text(' Kristuff/AbuseIPDB Client version: ', 'darkgray') . Console::text(AbuseIPDBClient::VERSION, 'lightgray')); |
|
149 | - Console::log(Console::text(' Kristuff/AbuseIPDB Core version: ', 'darkgray') . Console::text(ApiHandler::VERSION, 'lightgray')); |
|
148 | + Console::log(Console::text(' Kristuff/AbuseIPDB Client version: ', 'darkgray').Console::text(AbuseIPDBClient::VERSION, 'lightgray')); |
|
149 | + Console::log(Console::text(' Kristuff/AbuseIPDB Core version: ', 'darkgray').Console::text(ApiHandler::VERSION, 'lightgray')); |
|
150 | 150 | Console::log(Console::text(' Released under the MIT licence', 'darkgray')); |
151 | - Console::log(Console::text(' Made with ', 'darkgray') . Console::text('♥', 'red') . Console::text(' in France', 'darkgray')); |
|
151 | + Console::log(Console::text(' Made with ', 'darkgray').Console::text('♥', 'red').Console::text(' in France', 'darkgray')); |
|
152 | 152 | Console::log( |
153 | 153 | Console::text(' © 2020-2022 Kristuff (', 'darkgray'). |
154 | 154 | Console::text('https://github.com/kristuff', 'darkgray', 'underlined'). |
@@ -170,8 +170,8 @@ discard block |
||
170 | 170 | { |
171 | 171 | if (self::isDefaultOuput()) { |
172 | 172 | Console::log(); |
173 | - Console::log( Console::text(' Kristuff/AbuseIPDB-client ', 'darkgray') . Console::text(' ' . AbuseIPDBClient::VERSION . ' ', 'white', 'blue')); |
|
174 | - Console::log(Console::text(' Made with ', 'darkgray') . Console::text('♥', 'red') . Console::text(' in France', 'darkgray')); |
|
173 | + Console::log(Console::text(' Kristuff/AbuseIPDB-client ', 'darkgray').Console::text(' '.AbuseIPDBClient::VERSION.' ', 'white', 'blue')); |
|
174 | + Console::log(Console::text(' Made with ', 'darkgray').Console::text('♥', 'red').Console::text(' in France', 'darkgray')); |
|
175 | 175 | Console::log(Console::text(' © 2020-2022 Kristuff (', 'darkgray'). |
176 | 176 | Console::text('https://github.com/kristuff', 'darkgray', 'underlined'). |
177 | 177 | Console::text(')', 'darkgray') |
@@ -191,19 +191,19 @@ discard block |
||
191 | 191 | protected static function printFooter($requestTime = ''): void |
192 | 192 | { |
193 | 193 | if (self::isDefaultOuput()) { |
194 | - if (!empty($requestTime)){ |
|
194 | + if (!empty($requestTime)) { |
|
195 | 195 | $date_utc = new \DateTime("now", new \DateTimeZone("UTC")); |
196 | 196 | Console::log( |
197 | - Console::text(' Request time: ', 'darkgray') . Console::text($requestTime . 's', 'lightgray'). |
|
198 | - Console::text(' | UTC time: ', 'darkgray') . Console::text($date_utc->format('Y-m-d H:i:s'), 'lightgray') |
|
197 | + Console::text(' Request time: ', 'darkgray').Console::text($requestTime.'s', 'lightgray'). |
|
198 | + Console::text(' | UTC time: ', 'darkgray').Console::text($date_utc->format('Y-m-d H:i:s'), 'lightgray') |
|
199 | 199 | ); |
200 | 200 | } |
201 | 201 | Console::log(Console::text(' ------------------------------------------------------------------------------------------------------', 'darkgray')); |
202 | 202 | Console::log( |
203 | - Console::text(' Kristuff\AbuseIPDB ', 'darkgray') . |
|
204 | - Console::text(AbuseIPDBClient::VERSION, 'lightgray') . |
|
205 | - Console::text(' | Made with ', 'darkgray') . |
|
206 | - Console::text('♥', 'red') . |
|
203 | + Console::text(' Kristuff\AbuseIPDB ', 'darkgray'). |
|
204 | + Console::text(AbuseIPDBClient::VERSION, 'lightgray'). |
|
205 | + Console::text(' | Made with ', 'darkgray'). |
|
206 | + Console::text('♥', 'red'). |
|
207 | 207 | Console::text(' in France | © 2020-2022 Kristuff (https://github.com/kristuff)', 'darkgray') |
208 | 208 | ); |
209 | 209 | Console::log(); |
@@ -221,9 +221,9 @@ discard block |
||
221 | 221 | protected static function printResult($text, $value, string $foregroundColor = 'lightred', string $backgroundColor = '', bool $print = true): string |
222 | 222 | { |
223 | 223 | // do not print null/blank values |
224 | - if (isset($value)){ |
|
225 | - $line = Console::text($text, 'white') . Console::text($value, $foregroundColor, $backgroundColor); |
|
226 | - if ($print && self::isDefaultOuput()){ |
|
224 | + if (isset($value)) { |
|
225 | + $line = Console::text($text, 'white').Console::text($value, $foregroundColor, $backgroundColor); |
|
226 | + if ($print && self::isDefaultOuput()) { |
|
227 | 227 | Console::log($line); |
228 | 228 | } |
229 | 229 | return $line; |
@@ -247,16 +247,16 @@ discard block |
||
247 | 247 | $scoreforegroundColor = 'white'; |
248 | 248 | $scoreBackgroundColor = 'green'; |
249 | 249 | |
250 | - if (intval($score) > 0 ){ |
|
250 | + if (intval($score) > 0) { |
|
251 | 251 | $scoreforegroundColor = 'black'; |
252 | 252 | $scoreBackgroundColor = 'yellow'; |
253 | 253 | } |
254 | - if (intval($score) > 50 ){ |
|
254 | + if (intval($score) > 50) { |
|
255 | 255 | $scoreforegroundColor = 'white'; |
256 | 256 | $scoreBackgroundColor = 'red'; |
257 | 257 | } |
258 | 258 | |
259 | - $badge = str_pad(strval($score), 3, ' ',STR_PAD_LEFT); |
|
259 | + $badge = str_pad(strval($score), 3, ' ', STR_PAD_LEFT); |
|
260 | 260 | return Console::text($padding.$badge.$padding, $scoreforegroundColor, $scoreBackgroundColor); |
261 | 261 | } |
262 | 262 | } |
263 | 263 | \ No newline at end of file |