Failed Conditions
Pull Request — master (#68)
by Keoghan
06:33
created

Open::handle()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 25
ccs 0
cts 17
cp 0
rs 9.7333
cc 4
nc 4
nop 0
crap 20
1
<?php
2
3
namespace App\Commands\Ngrok;
4
5
use App\Porter;
6
use App\Models\Site;
7
use App\Commands\BaseCommand;
8
9
class Open extends BaseCommand
10
{
11
    /**
12
     * The signature of the command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'ngrok';
17
18
    /**
19
     * The description of the command.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Open Node cli';
24
25
    /**
26
     * Execute the console command.
27
     *
28
     * @return void
29
     */
30
    public function handle(): void
31
    {
32
        $site = Site::resolveFromPathOrCurrentWorkingDirectory();
33
        $wasSecure = false;
34
35
        if ($site->secure) {
36
            $this->info('Removing SSL for site (required for free ngrok version)');
37
            $site->unsecure();
38
            $wasSecure = true;
39
        }
40
41
        app(Porter::class)->stop('ngrok');
42
43
        $this->dockerCompose
44
            ->runContainer('ngrok')
45
            ->append('ngrok http -host-header=rewrite -region=eu -bind-tls='.($wasSecure ? 'true' : 'false').' -inspect=false '.$site->url.':80')
46
            ->interactive()
47
            ->perform();
48
49
        if ($wasSecure) {
50
            $this->info('Restoring SSL for site');
51
            $site->secure();
52
        }
53
54
        app(Porter::class)->stop('ngrok');
55
    }
56
}
57