Conditions | 20 |
Paths | 6176 |
Total Lines | 280 |
Code Lines | 234 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
45 | function printLoader($introDelay = 75000, $printAll = true) |
||
46 | { |
||
47 | Console::newWindow(); |
||
48 | splash(); |
||
49 | Console::clear(); |
||
50 | splash(); |
||
51 | Console::clear(); |
||
52 | Console::log(); |
||
53 | Console::log(Console::text(" _ _ _ _ ", 'yellow').Console::text(' ', 'yellow').Console::text('', 'green') ); |
||
54 | Console::log(Console::text(" _ __ (_)__| |_ ___| | | ", 'yellow').Console::text(' ', 'yellow').Console::text('', 'green') ); |
||
55 | Console::log(Console::text(" | ' \| (_-< ' \/ -_) | | ", 'yellow').Console::text(' ', 'yellow').Console::text('', 'green') ); |
||
56 | Console::log(Console::text(" |_|_|_|_/__/_||_\___|_|_| ", 'yellow').Console::text('By ', 'yellow').Console::text("kr157uff", 'green') ); |
||
57 | Console::log(); |
||
58 | Console::log(' '.Console::text("-----------------------------------------------------------------", "green")); |
||
59 | Console::log(' '.Console::text("kristuff/mishell: A mini PHP library to build CLI app and reports", "green")); |
||
60 | Console::log(' '.Console::text('Made with ', 'green') . Console::text('♥', 'red'). |
||
61 | Console::text(' ', 'green'). |
||
62 | Console::text(" | © 2017-2024 kri157uff", "green")); |
||
63 | Console::log(' '.Console::text("-----------------------------------------------------------------", "green")); |
||
64 | Console::log(); |
||
65 | usleep($introDelay * random_int(7, 11)); |
||
66 | $new = Console::text("NEW", 'green', 'blink'); |
||
67 | $fullRowString = Console::pad('', Console::getColumns()); |
||
68 | $badgeOnline = Console::text(' ONLINE ', 'yellow', 'green'). ' '; |
||
69 | $badgeError = Console::text(' 💀 ERR ', 'yellow', 'red'); |
||
70 | $badgeOffline = Console::text(' BROKEN ', 'yellow', 'yellow'). ' '; |
||
71 | $badgeBroken = Console::text(' 😜 LIKELY NEED INTERNAL REWRITE ', 'yellow', 'red'); |
||
72 | $swu = Console::text('StandWith', 'yellow', 'blue').Console::text('Ukraine', 'blue', 'yellow'); |
||
73 | $copyright = Console::text(' [*]', 'green').Console::text(" © 2017-2024 ", 'yellow').Console::text('kri157uff', 'green').Console::text(' aka ', 'yellow').Console::text('Kristuff', 'green'); |
||
74 | $head1 = Console::text(' [*]', 'blue').Console::text(' Kr157uff/mishell ', 'yellow').Console::text(" v1.6 ", 'yellow', 'blue').' released '.$new.Console::text(' ', 'yellow'); |
||
75 | $progress = Console::text(' [*]', 'blue').Console::text(' This is another ', 'yellow').Console::text('fake', 'green', 'underlined').Console::text(' progress message (', 'yellow').Console::text('0%', 'green').Console::text(') completed', 'yellow'); |
||
76 | $progress1 = Console::text(' [*]', 'yellow').Console::text(' In fact I\'m already loaded for a while...', 'yellow'); |
||
77 | $twitter = Console::text(' [*]', 'blue').Console::text(' Twitter microservices status: ', 'yellow').$badgeOffline; |
||
78 | $weSWU = Console::text(' [*]', 'blue').Console::text(' We ', 'yellow').$swu; |
||
79 | $msg1 = Console::text(' [*]', 'blue'). Console::text(' Tortoise vs Hare Race will starting soon. Place your bets! ...', 'yellow'); |
||
80 | $msg2 = Console::text(' [*]', 'blue').Console::text(' 🐢 ', 'green').Console::text('Tortoise progress ... ', 'green'); |
||
81 | $msg3 = Console::text(' [*]', 'blue').Console::text(' 🐇 ', 'yellow').Console::text('Hare progress ... ', 'green'); |
||
82 | Console::log($head1); |
||
83 | usleep($introDelay * random_int(1, 4)); |
||
84 | Console::log(); |
||
85 | Console::log($copyright); |
||
86 | Console::log(); |
||
87 | usleep($introDelay * random_int(3, 5)); |
||
88 | Console::log($weSWU); |
||
89 | Console::log(); |
||
90 | usleep($introDelay * random_int(5, 7)); |
||
91 | Console::log($twitter); |
||
92 | Console::log(); |
||
93 | usleep($introDelay * random_int(1, 2)); |
||
94 | Console::log($msg1); |
||
95 | Console::log(); |
||
96 | Console::log($msg2); |
||
97 | Console::log(); |
||
98 | Console::log($msg3); |
||
99 | Console::log(); |
||
100 | usleep($introDelay * random_int(2, 4)); |
||
101 | Console::log($progress); |
||
102 | Console::log(); |
||
103 | Console::log($progress1); |
||
104 | Console::log(); |
||
105 | // |
||
106 | $harePurcent = 0; |
||
107 | $tortPurcent = 0; |
||
108 | $twitterStatus = [ |
||
109 | Console::text(' [*]', 'green').Console::text(' Twitter microservices status: ', 'yellow').$badgeOnline, |
||
110 | Console::text(' [*]', 'yellow').Console::text(' Twitter microservices status: ', 'yellow').$badgeOffline, |
||
111 | Console::text(' [*]', 'red') .Console::text(' Twitter microservices status: ', 'yellow'). $badgeError, |
||
112 | ]; |
||
113 | for ($i=1 ; $i<=100 ; $i++) { |
||
114 | $isOdd = ($i % 2 == 0); |
||
115 | |||
116 | $progress = Console::text(' [*]', 'blue').Console::text(' This is another ', 'yellow').Console::text('fake', 'green', 'bold', 'underlined').Console::text(' progress message (', 'yellow').Console::text($i .'%', 'green').Console::text(' completed)', 'yellow'); |
||
117 | $twitter = $twitterStatus[random_int(0, 2)]; |
||
118 | |||
119 | if ($i < 75 ){ |
||
120 | $isOdd && $tortPurcent++; |
||
121 | } else { |
||
122 | $twitter = Console::text(' [*]', 'red').Console::text(' Twitter microservices status: ', 'yellow').$badgeBroken; |
||
123 | $tortPurcent = min($tortPurcent + 3, 100); |
||
124 | } |
||
125 | if ($i == 100) { |
||
126 | Console::text(' [*]', 'red').Console::text(' Twitter microservices status: ', 'yellow').$badgeBroken; |
||
127 | } |
||
128 | $harePurcent++; |
||
129 | if ($i== 100){ |
||
130 | $tortColor = $tortPurcent >= $harePurcent ? 'green' : 'red' ; |
||
131 | $hareColor = $tortPurcent < $harePurcent ? 'green' : 'red' ; |
||
132 | } else { |
||
133 | $tortColor = $tortPurcent >= $harePurcent ? 'green' : 'yellow' ; |
||
134 | $hareColor = $tortPurcent < $harePurcent ? 'green' : 'yellow' ; |
||
135 | } |
||
136 | $msg1 = $i==100 ? |
||
137 | Console::text(' [*]', 'blue').Console::text(' Tortoise vs Hare Race - Final Results', 'yellow') : |
||
138 | Console::text(' [*]', 'blue').Console::text(' Tortoise vs Hare Race: ', 'yellow').Console::text(' RUNNING ', 'yellow', 'yellow'). ' ' ; |
||
139 | $msg2 = Console::text(' [*]', $i==100 ? $tortColor : 'blue').Console::text(' 🐢 ', 'green').Console::text('Tortoise progress: ', 'yellow').Console::progressBar($tortPurcent, $tortColor, $tortColor); |
||
140 | $msg3 = Console::text(' [*]', $i==100 ? $hareColor : 'blue').Console::text(' 🐇 ', 'yellow'). Console::text('Hare progress: ', 'yellow').Console::progressBar($harePurcent, $hareColor, $hareColor); |
||
141 | $msg2End = $tortPurcent == 100 ? ' '.Console::text('🏆 WINNER!!!', 'green') : ''; |
||
142 | $msgs = [ |
||
143 | $head1 |
||
144 | , |
||
145 | ' ', $copyright, |
||
146 | ' ', $weSWU, |
||
147 | ' ', $twitter, |
||
148 | ' ', $msg1, |
||
149 | ' ', $msg2.$msg2End, |
||
150 | ' ', $msg3, |
||
151 | ' ', $progress, |
||
152 | ' ', $progress1, |
||
153 | ' ', |
||
154 | ]; |
||
155 | |||
156 | // rewrite the last printed lines |
||
157 | Console::overwrite($msgs); |
||
158 | |||
159 | // wait for a while, so we see the animation |
||
160 | usleep($introDelay); |
||
161 | } |
||
162 | |||
163 | $apt1 = Console::text(' dpkg install nothing [ ', 'yellow').Console::progressBar(0, 'default', 'default','default', Console::getColumns() - 26, ' ', '.', false).Console::text(' ]', 'yellow'); |
||
164 | $apt2 = Console::pad(Console::text(' dpkg finished to install nothing ...', 'yellow'), Console::getColumns() -26); |
||
165 | $apt3 = ''; |
||
166 | $apt4 = Console::pad(Console::text(' it works on my machine ...', 'yellow'), Console::getColumns() -26); |
||
167 | $apt5 = ''; |
||
168 | $apt6 = Console::pad(Console::text(' failed to import new galaxy, we will retry later ...', 'red'), Console::getColumns() -26); |
||
169 | |||
170 | usleep($introDelay * random_int(2, 3)); |
||
171 | Console::log($apt1); |
||
172 | for ($i=1 ; $i<=100 ; $i++) { |
||
173 | $apt1 = Console::text(' dpkg install nothing [ ', 'yellow').Console::progressBar($i, 'default', 'default','default', Console::getColumns() - 26, ' ', '#', false).Console::text(' ]', 'yellow'); |
||
174 | Console::overwrite($apt1); |
||
175 | usleep($introDelay / 3); |
||
176 | } |
||
177 | Console::overwrite($apt2); |
||
178 | |||
179 | Console::log($apt3); |
||
180 | for ($i=1 ; $i<=100 ; $i++) { |
||
181 | $apt3 = Console::text(' dpkg purge nothing [ ', 'yellow').Console::progressBar($i, 'default', 'default','default', Console::getColumns() - 26, Console::text('.', 'yellow'), Console::text('#', 'green'), false).Console::text(' ]', 'yellow'); |
||
182 | Console::overwrite($apt3); |
||
183 | usleep($introDelay / 4); |
||
184 | } |
||
185 | Console::overwrite($apt4); |
||
186 | |||
187 | usleep($introDelay * random_int(2, 3)); |
||
188 | Console::log($apt5); |
||
189 | for ($i=1 ; $i<=100 ; $i++) { |
||
190 | $apt5 = Console::text(' importing new galaxy [ ', 'yellow').Console::progressBar($i, 'default', 'default','default', Console::getColumns() - 26, Console::text('.', 'yellow'), Console::text('!', 'red'), false).Console::text(' ]', 'yellow'); |
||
191 | Console::overwrite($apt5); |
||
192 | usleep($introDelay / 5 ); |
||
193 | } |
||
194 | Console::overwrite($apt6); |
||
195 | |||
196 | $magicTime = $printAll ? 122000 : false; |
||
197 | |||
198 | Console::log(' '.Console::text("- CRITICAL FAILURE -", 'yellow', 'red')); |
||
199 | usleep($magicTime ?? 556000); |
||
200 | Console::overwrite(Console::text(" just kidding ...", 'yellow')); |
||
201 | usleep($magicTime ?? 9155000); |
||
202 | Console::overwrite(Console::text(" demo complete", 'green')); |
||
203 | usleep($magicTime ?? 1355000); |
||
204 | Console::overwrite(Console::text(" oh wait! I forgot something 🤔", 'yellow')); |
||
205 | usleep($magicTime ?? 1355000); |
||
206 | |||
207 | if ($printAll) { |
||
208 | |||
209 | Console::overwrite($fullRowString); |
||
210 | Console::log( |
||
211 | Console::text(" →", 'yellow').Console::text(' → ', 'blue'). |
||
212 | Console::text(" →", 'yellow').Console::text(' → ', 'blue'). |
||
213 | Console::text(" →", 'yellow').Console::text(' → ', 'blue'). |
||
214 | Console::text(" →", 'yellow').Console::text(' → ', 'blue'). |
||
215 | $swu. |
||
216 | Console::text(" ←", 'yellow').Console::text(' ← ', 'blue'). |
||
217 | Console::text(" ←", 'yellow').Console::text(' ← ', 'blue'). |
||
218 | Console::text(" ←", 'yellow').Console::text(' ← ', 'blue'). |
||
219 | Console::text(" ←", 'yellow').Console::text(' ← ', 'blue') |
||
220 | ); |
||
221 | usleep($introDelay * 10); |
||
222 | |||
223 | Console::log(); |
||
224 | Console::log( Console::text(" also forgot to install Kr157uff-socials-links-2.0 package", 'yellow')); usleep(1355000); |
||
225 | Console::overwrite( Console::text(" Do you want to install Kr157uff-socials-links package? (634 Go)", 'yellow')); usleep(1355000); |
||
226 | Console::log( Console::text(" i readed in your mind and detected ", 'yellow').Console::text('YES OF COURSE', 'yellow').Console::text(" ...", 'yellow')); usleep($introDelay * 5); |
||
227 | Console::log( Console::text(" i never cheat ...", 'yellow')); usleep($introDelay * 5); |
||
228 | Console::log( Console::text(" okay sometimes ...", 'yellow')); |
||
229 | $socials = [ |
||
230 | ["name" => "Github", "user" => "kristuff ", "link" => "https://github.com/kristuff"], |
||
231 | ["name" => "Twitter", "user" => "@_kristuff ", "link" => "https://twitter.com/_kristuff"], |
||
232 | ["name" => "Mastodon", "user" => "@kristuff ", "link" => "https://infosec.exchange/@kristuff"], |
||
233 | ]; |
||
234 | |||
235 | $aptLink = Console::text(' unpacking Kr157uff-social-links-2.0-prod-test [ ', 'yellow').Console::progressBar(0, 'default', 'default','default', Console::getColumns() - 56, '.', Console::text('#', 'green'), false).Console::text(' ]', 'yellow'); |
||
236 | Console::log(); |
||
237 | Console::log(); |
||
238 | Console::log(); |
||
239 | Console::log($aptLink); |
||
240 | Console::log(); |
||
241 | |||
242 | $i = 0; |
||
243 | foreach ($socials as $social){ |
||
244 | $socialLog = Console::pad( |
||
245 | Console::text(' preparing to unpack ', 'yellow'). |
||
246 | Console::text('kristuff-'.$social['name'].'.deb', 'green'). |
||
247 | Console::text(' ...', 'yellow'), |
||
248 | Console::getColumns() - 12 |
||
249 | ) ; |
||
250 | $socialLog3 = Console::text( ' created symlink ', 'yellow'). |
||
251 | Console::text('/usr/bin/'.$social['user'], 'yellow'). |
||
252 | Console::text(' → ', 'yellow'). |
||
253 | Console::text($social['link'], 'lightblue', 'underlined'); |
||
254 | |||
255 | $socialLog2 = Console::text( ' unpacking ', 'yellow'). |
||
256 | Console::text('kristuff-'. $social['name'].'-prod-test~deb12u99', 'yellow'). |
||
257 | Console::text('-prod-test~deb12u99', 'green'). |
||
258 | Console::text(' ...', 'yellow'); |
||
259 | |||
260 | |||
261 | $aptLink = Console::text(' unpacking ', 'yellow'). |
||
262 | Console::text('kristuff-social-links_2.0-prod-test~deb12u99', 'yellow'). |
||
263 | Console::text(' [ ', 'yellow'). |
||
264 | Console::progressBar(round(($i+0.3)/(count($socials)*2)*100), 'default', 'default','default', Console::getColumns() - 64, '.', Console::text('#', 'green'), false).Console::text(' ]', 'yellow'); |
||
265 | |||
266 | Console::overwrite([$fullRowString,$fullRowString]); |
||
267 | Console::overwrite([$socialLog, $socialLog2]); |
||
268 | Console::log($socialLog3); |
||
269 | Console::log(); |
||
270 | Console::log($aptLink); |
||
271 | usleep($introDelay * random_int(2, 4)); |
||
272 | |||
273 | $i++; |
||
274 | $aptLink = Console::text(' unpacking ', 'yellow'). |
||
275 | Console::text('kristuff-social-links_2.0-prod-test~deb12u99', 'yellow'). |
||
276 | Console::text(' [ ', 'yellow'). |
||
277 | Console::progressBar(round($i+0.3/count($socials)*2*100), 'default', 'default','default', |
||
278 | Console::getColumns() - 64, '.', Console::text('#', 'green'), false). |
||
279 | Console::text(' ]', 'yellow'); |
||
280 | usleep($introDelay * random_int(2, 4)); |
||
281 | Console::overwrite([$fullRowString,$fullRowString]); |
||
282 | Console::overwrite([' ', $aptLink]); |
||
283 | $i++; |
||
284 | } |
||
285 | |||
286 | $aptLink = Console::text(' unpacking ', 'yellow'). |
||
287 | Console::text('kristuff-social-links_2.0-prod-test~deb12u99', 'yellow'). |
||
288 | Console::text(' [ ', 'yellow'). |
||
289 | Console::progressBar(100, 'default', 'default','default', |
||
290 | Console::getColumns() - 64, '.', Console::text('#', 'green'), false). |
||
291 | Console::text(' ]', 'yellow'); |
||
292 | |||
293 | Console::overwrite($aptLink); |
||
294 | usleep($introDelay * random_int(10, 50)); |
||
295 | |||
296 | Console::overwrite(Console::pad('', Console::getColumns())); |
||
297 | $aptLink = Console::text(' unpacking ', 'yellow'). |
||
298 | Console::text('kristuff-social-links_2.0-prod-test~deb12u99', 'yellow'). |
||
299 | Console::text(' completed ... ', 'yellow'). |
||
300 | |||
301 | Console::overwrite($fullRowString); |
||
302 | Console::log($aptLink); |
||
303 | Console::log(); |
||
304 | Console::log(Console::text(" _ _ _ _ ", 'yellow').Console::text(' ', 'yellow').Console::text('', 'green') ); |
||
305 | Console::log(Console::text(" _ __ (_)__| |_ ___| | | ", 'yellow').Console::text(' ', 'yellow').Console::text('', 'green') ); |
||
306 | Console::log(Console::text(" | ' \| (_-< ' \/ -_) | | ", 'yellow').Console::text(' ', 'yellow').Console::text('', 'green') ); |
||
307 | Console::log(Console::text(" |_|_|_|_/__/_||_\___|_|_| ", 'yellow').Console::text('By ', 'yellow').Console::text("kr157uff", 'green') ); |
||
308 | Console::log(' '.Console::text("-----------------------------------------------------------------", "green")); |
||
309 | Console::log(' '.Console::text("kr157uff/mishell: A mini PHP library to build CLI app and reports", "green")); |
||
310 | Console::log(' '.Console::text('Made with ', 'green') . Console::text('♥', 'red'). |
||
311 | Console::text(' in France', 'green'). |
||
312 | Console::text(" | © 2017-2024 kri157uff", "green")); |
||
313 | Console::log(' '.Console::text("-----------------------------------------------------------------", "green")); |
||
314 | Console::log(); |
||
315 | usleep(1200000); |
||
316 | usleep($introDelay * random_int(10, 50)); |
||
317 | Console::log(); |
||
318 | Console::log(Console::text(" If you don't have the time to read, you can replay this intro slowwwly. Hura!", 'yellow')); |
||
319 | Console::log(); |
||
320 | |||
321 | } |
||
322 | |||
323 | usleep($introDelay * random_int(20, 40)); |
||
324 | Console::restoreWindow(); |
||
325 | |||
684 | } |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.