TmuxUIStart::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 16
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Models\Settings;
6
use Blacklight\Tmux;
7
use Illuminate\Console\Command;
8
use Illuminate\Support\Facades\Process;
9
10
class TmuxUIStart extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'tmux-ui:start';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Start the processing of tmux scripts.';
25
26
    /**
27
     * Execute the console command.
28
     */
29
    public function handle(): void
30
    {
31
        $tmux = new Tmux;
32
        $tmux_session = Settings::settingValue('tmux_session') ?? 0;
33
34
        // Set running value to on.
35
        $tmux->startRunning();
36
37
        // check if session exists
38
        $session = Process::run("tmux list-session | grep $tmux_session");
39
        if ($session->exitCode() === 1) {
40
            $this->info('Starting the tmux server and monitor script');
41
            Process::forever()->tty()->run('php '.app()->/* @scrutinizer ignore-call */ path().'/../misc/update/tmux/run.php')->output();
42
        } else {
43
            $this->error("tmux session: '".$tmux_session."' is already running, aborting.");
44
            exit();
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...
45
        }
46
    }
47
}
48