Test Failed
Branch feature__set_up_scrutinizer (ea6624)
by Robin
06:04 queued 02:46
created

Php::handle()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 19
ccs 0
cts 12
cp 0
rs 9.8666
c 0
b 0
f 0
cc 3
nc 2
nop 0
crap 12
1
<?php
2
3
namespace App\Commands\Site;
4
5
use App\Commands\BaseCommand;
6
use App\Models\PhpVersion;
7
use App\Models\Site;
8
9
class Php extends BaseCommand
10
{
11
    /**
12
     * The signature of the command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'site:php {site?}';
17
18
    /**
19
     * The description of the command.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Choose the PHP version for a site';
24
25
    /**
26
     * Execute the console command.
27
     *
28
     * @return void
29
     * @throws \Exception
30
     */
31
    public function handle(): void
32
    {
33
        $site = Site::resolveFromPathOrCurrentWorkingDirectoryOrFail($this->argument('site'));
34
35
        $currentVersion = $site->php_version->version_number;
36
37
        $option = $this->menu(
0 ignored issues
show
Bug introduced by
The method menu() does not exist on App\Commands\Site\Php. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

37
        $option = $this->/** @scrutinizer ignore-call */ menu(
Loading history...
38
            'Available PHP versions',
39
            PhpVersion::pluck('version_number', 'id')
40
                ->map(function ($version) use ($currentVersion) {
41
                    return $version . ($version == $currentVersion ? ' (current)' : '');
42
                })->toArray()
43
        )->open();
44
45
        if (! $option) {
46
            return;
47
        }
48
49
        $site->setPhpVersion($option);
50
    }
51
}
52