ListSites::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 18
ccs 0
cts 12
cp 0
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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 ListSites extends BaseCommand
10
{
11
    /**
12
     * The signature of the command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'site:list';
17
18
    /**
19
     * The description of the command.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'List available sites';
24
25
    /**
26
     * Execute the console command.
27
     *
28
     * @return void
29
     */
30
    public function handle(): void
31
    {
32
        $headers = ['Name', 'PHP Version', 'NGiNX Template', 'Url'];
33
34
        $sites = Site::with('php_version')
35
            ->orderBy('name', 'asc')
36
            ->get()
37
            ->map(function ($site) {
38
                return [
39
                    $site->name,
40
                    $site->php_version->version_number,
41
                    $site->nginx_conf,
42
                    $site->scheme.$site->url,
43
                ];
44
            });
45
46
        $this->table($headers, $sites);
47
        $this->info('The default PHP version is '.PHPVersion::defaultVersion()->version_number);
48
    }
49
}
50