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

Nginx::handle()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 30
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 30
ccs 0
cts 20
cp 0
rs 9.584
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\Site;
7
use Symfony\Component\Finder\Finder;
8
9
class Nginx extends BaseCommand
10
{
11
    /**
12
     * The signature of the command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'site:nginx {site?}';
17
18
    /**
19
     * The description of the command.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Choose the NGiNX config template 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
        $currentNginxConf = $site->nginx_conf;
36
37
        $nginxFileLocations = collect(view()->getFinder()->getPaths())
38
            ->map(function ($location) {
39
                return $location.'/nginx';
40
            })->toArray();
41
42
        $types = collect(iterator_to_array(
43
            Finder::create()
44
                ->in($nginxFileLocations)
45
                ->directories()
46
        ))->mapWithKeys(function (\SplFileInfo $file) use ($currentNginxConf) {
47
            $conf = $file->getFilename();
48
            return [$conf => $conf . ($conf == $currentNginxConf ? ' (current)' : '')];
49
        })->sort()->toArray();
50
51
        $option = $this->menu(
0 ignored issues
show
Bug introduced by
The method menu() does not exist on App\Commands\Site\Nginx. 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

51
        $option = $this->/** @scrutinizer ignore-call */ menu(
Loading history...
52
            'Available Nginx Types',
53
            $types
54
        )->open();
55
56
        if (! $option) {
57
            return;
58
        }
59
60
        $site->setNginxType($option);
61
    }
62
}
63