Passed
Pull Request — master (#53)
by Robin
04:58 queued 01:22
created

Begin   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 6
eloc 28
dl 0
loc 76
ccs 20
cts 25
cp 0.8
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 22 2
A setHomeDirectory() 0 15 4
1
<?php
2
3
namespace App\Commands;
4
5
use App\Exceptions\PorterSetupFailed;
6
use App\Support\Images\Organiser\Organiser as ImageOrganiser;
7
8
class Begin extends BaseCommand
9
{
10
    /**
11
     * The begin command may be run at any time, since it's needed to perform setup.
12
     *
13
     * @var bool
14
     */
15
    protected $porterMustBeSetUp = false;
16
17
    /**
18
     * The signature of the command.
19
     *
20
     * @var string
21
     */
22
    protected $signature = 'begin 
23
        {home? : The path of Porter\'s home directory (optional). Defaults to current directory.} 
24
        {--force : Force setup to run, even if it has already been run}';
25
26
    /**
27
     * The description of the command.
28
     *
29
     * @var string
30
     */
31
    protected $description = 'Run initial seeders and set up';
32
33
    /**
34
     * Execute the console command.
35
     *
36
     * @throws \Exception
37
     *
38
     * @return void
39
     */
40 2
    public function handle(): void
41
    {
42 2
        $this->line('================');
43 2
        $this->line('PREPARING PORTER');
44 2
        $this->line('================');
45 2
        $this->line('');
46
47
        try {
48 2
            $this->porterLibrary->setup($this->app, (bool) $this->option('force'));
0 ignored issues
show
Bug introduced by
It seems like $this->app can also be of type null; however, parameter $app of App\PorterLibrary::setUp() does only seem to accept Illuminate\Contracts\Foundation\Application, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

48
            $this->porterLibrary->setup(/** @scrutinizer ignore-type */ $this->app, (bool) $this->option('force'));
Loading history...
49
        } catch (PorterSetupFailed $e) {
50
            $this->alert($e->getMessage());
51
52
            return;
53
        }
54
55 2
        $this->info('Your Porter settings are stored in '.$this->porterLibrary->path());
56 2
        $this->info('');
57
58 2
        $this->setHomeDirectory();
59
60 2
        $this->info('Retrieving docker images');
61 2
        app(ImageOrganiser::class)->pullImages();
62 2
    }
63
64
    /**
65
     * Set the Porter home directory, prompting for input if necessary.
66
     *
67
     * @return void
68
     */
69 2
    protected function setHomeDirectory()
70
    {
71 2
        if ($this->argument('home') || $this->option('no-interaction')) {
72 2
            $home = realpath((string) $this->argument('home') ?: $this->cli->currentWorkingDirectory());
73
        } else {
74
            $this->comment('Please enter the root directory for your sites, or leave blank to use the current directory.');
75
            $home = $this->ask('', $this->cli->currentWorkingDirectory());
76
        }
77
78 2
        $this->info("Setting home to {$home}.");
79 2
        $this->comment('This is the root directory for your sites.');
80 2
        $this->comment("If this is incorrect, you can change it using the 'porter home' command.");
81 2
        $this->comment('');
82
83 2
        $this->callSilent('home', ['path' => $home]);
84 2
    }
85
}
86