UseSet::handle()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 28
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 28
ccs 0
cts 16
cp 0
rs 9.7
c 0
b 0
f 0
cc 4
nc 3
nop 0
crap 20
1
<?php
2
3
namespace App\Commands\Images;
4
5
use App\Commands\BaseCommand;
6
use App\Models\Setting;
7
use App\Support\Contracts\ImageSetRepository;
8
use Illuminate\Support\Facades\Artisan;
9
10
class UseSet extends BaseCommand
11
{
12
    /**
13
     * The signature of the command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'images:set {--show}';
18
19
    /**
20
     * The description of the command.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Change the set of container images use';
25
26
    /**
27
     * Execute the console command.
28
     *
29
     * @return void
30
     */
31
    public function handle(): void
32
    {
33
        $current = $this->porter->getDockerImageSet()->getName();
34
35
        if ($this->option('show')) {
36
            $this->info('The current image set is: '.$current);
37
38
            return;
39
        }
40
41
        $sets = app(ImageSetRepository::class)
42
            ->availableImageSets()
43
            ->mapWithKeys(function ($set) use ($current) {
44
                return [$set => $set.($current == $set ? ' (current)' : '')];
45
            })->toArray();
46
47
        $option = $this->menu(
48
            'Available Image Sets',
49
            $sets
50
        )->open();
51
52
        if (!$option) {
53
            return;
54
        }
55
56
        Setting::updateOrCreate('docker_image_set', $option);
57
58
        Artisan::call('make-files');
59
    }
60
}
61