shutdown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 1
nc 1
nop 0
1
<?php
2
require_once __DIR__ .'/../vendor/autoload.php';
3
use Kristuff\Mishell\Console;  
4
5
// *open* new window
6
Console::newWindow();
7
8
declare(ticks = 1);                                      // Allow posix signal handling
9
pcntl_async_signals(true);
10
pcntl_signal(SIGINT,"shutdown");       
11
register_shutdown_function("shutdown");                 // Handle END of script
12
13
splash();
14
15
function shutdown(){
16
    //     echo "\033c";                                        // Clear terminal
17
    //     echo PHP_EOL;                                        // New line
18
    //Console::log();
19
    //Console::log('SIGINT signal detected, terminate script...');
20
    //system("tput cnorm && tput cup 0 0 && stty echo");   // Restore cursor default
21
    usleep(115000);
22
    Console::restoreWindow();
23
    exit(0);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
24
}
25
26
function splash()
27
{
28
29
    // get columns / lines and calculate middle
30
    $lines  = Console::getLines();
31
    $cols   = Console::getColumns();
32
    $middle = round($lines/2);
33
34
    for ($i= 1; $i <= $lines ; $i++){
35
        switch($i){
36
            case $middle -1:    Console::log(Console::pad("Stand With Ukraine <3", $cols, ' ', STR_PAD_BOTH), 'yellow', 'blue');    break;
37
            case $middle:       Console::log(Console::pad(' ', $cols, ' ', STR_PAD_BOTH), 'yellow', 'blue');                        break;
38
            case $middle +1:    Console::log(Console::pad(' ', $cols, ' ', STR_PAD_BOTH), 'blue', 'yellow');                        break;
39
            case $middle +2:    Console::log(Console::pad('Slava Ukraini', $cols, ' ', STR_PAD_BOTH), 'blue', 'yellow');            break;
40
            case $lines:        Console::print(Console::pad(' Wait a few seconds or hint Ctrl+C', $cols , ' ', STR_PAD_LEFT), 'blue', 'yellow');  break; // no new line here
41
            default:
42
                if ($i > $middle) {
43
                    Console::log(Console::pad(' ', $cols), 'blue', 'yellow');
44
                } else {
45
                    Console::log(Console::pad(' ', $cols), 'yellow', 'blue');
46
                }
47
        }
48
    }
49
50
    sleep(6);
51
52
    // restore previous window
53
    Console::restoreWindow();
54
55
}
56
57
58
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
59