Passed
Pull Request — main (#147)
by mohsen
15:30
created

HealthCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 17
c 1
b 0
f 1
dl 0
loc 44
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A handle() 0 12 1
1
<?php
2
3
namespace MohsenAbrishami\Stethoscope\Commands;
4
5
use Illuminate\Console\Command;
6
use MohsenAbrishami\Stethoscope\Events\TroubleOccurred;
7
use MohsenAbrishami\Stethoscope\Services\Cpu;
8
use MohsenAbrishami\Stethoscope\Services\storage;
9
use MohsenAbrishami\Stethoscope\Services\Memory;
10
use MohsenAbrishami\Stethoscope\Services\Network;
11
use MohsenAbrishami\Stethoscope\Services\WebServer;
12
13
class HealthCommand extends Command
14
{
15
    public function __construct(Cpu $cpu, Memory $memory, Network $network, WebServer $webServer, storage $storage)
16
    {
17
        parent::__construct();
18
19
        $this->cpu = $cpu;
0 ignored issues
show
Bug Best Practice introduced by
The property cpu does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
20
        $this->memory = $memory;
0 ignored issues
show
Bug Best Practice introduced by
The property memory does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
21
        $this->network = $network;
0 ignored issues
show
Bug Best Practice introduced by
The property network does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
22
        $this->webServer = $webServer;
0 ignored issues
show
Bug Best Practice introduced by
The property webServer does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
23
        $this->storage = $storage;
0 ignored issues
show
Bug Best Practice introduced by
The property storage does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
24
    }
25
26
    /**
27
     * The name and signature of the console command.
28
     *
29
     * @var string
30
     */
31
    protected $signature = 'stethoscope:health';
32
33
    /**
34
     * The console command description.
35
     *
36
     * @var string
37
     */
38
    protected $description = 'check server is up';
39
40
    /**
41
     * Execute the console command.
42
     *
43
     * @return int
44
     */
45
    public function handle()
46
    {
47
        $logs = [];
48
49
        $logs['signature'] = $this->signature;
50
        $logs['cpu'] = $this->cpu->check();
51
        $logs['memory'] = $this->memory->check();
52
        $logs['network'] = $this->network->check();
53
        $logs['storage'] = $this->storage->check();
54
        $logs['webServer'] = $this->webServer->check();
55
56
        TroubleOccurred::dispatch($logs);
57
    }
58
}
59