Completed
Push — main ( dc0cbe...02ba7b )
by mohsen
14s queued 13s
created

MonitorCommand::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
namespace MohsenAbrishami\Stethoscope\Commands;
4
5
use Illuminate\Console\Command;
6
use MohsenAbrishami\Stethoscope\LogRecord\Facades\Record;
7
use MohsenAbrishami\Stethoscope\Services\Cpu;
8
use MohsenAbrishami\Stethoscope\Services\HardDisk;
9
use MohsenAbrishami\Stethoscope\Services\Memory;
10
use MohsenAbrishami\Stethoscope\Services\Network;
11
use MohsenAbrishami\Stethoscope\Services\WebServer;
12
13
class MonitorCommand extends Command
14
{
15
    public function __construct(Cpu $cpu, Memory $memory, Network $network, WebServer $webServer, HardDisk $hardDisk)
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->hardDisk = $hardDisk;
0 ignored issues
show
Bug Best Practice introduced by
The property hardDisk 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
    /**
28
     * The name and signature of the console command.
29
     *
30
     * @var string
31
     */
32
    protected $signature = 'stethoscope:monitor';
33
34
    /**
35
     * The console command description.
36
     *
37
     * @var string
38
     */
39
    protected $description = 'monitor memory usage, cpu usage, network connection and nginx status';
40
41
    /**
42
     * Execute the console command.
43
     *
44
     * @return int
45
     */
46
    public function handle()
47
    {
48
        $cpuUsage = $this->cpu->check();
49
        $memoryUsage = $this->memory->check();
50
        $networkStatus = $this->network->check();
51
        $webServerStatuses = $this->webServer->check();
52
        $hardDiskFreeSpace = $this->hardDisk->check();
53
54
        Record::record($cpuUsage, $memoryUsage, $networkStatus, $webServerStatuses, $hardDiskFreeSpace);
0 ignored issues
show
Bug introduced by
$webServerStatuses of type array is incompatible with the type boolean expected by parameter $webServerStatuses of MohsenAbrishami\Stethosc...acades\Record::record(). ( Ignorable by Annotation )

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

54
        Record::record($cpuUsage, $memoryUsage, $networkStatus, /** @scrutinizer ignore-type */ $webServerStatuses, $hardDiskFreeSpace);
Loading history...
Bug introduced by
$hardDiskFreeSpace of type string is incompatible with the type boolean expected by parameter $hardDiskFreeSpace of MohsenAbrishami\Stethosc...acades\Record::record(). ( Ignorable by Annotation )

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

54
        Record::record($cpuUsage, $memoryUsage, $networkStatus, $webServerStatuses, /** @scrutinizer ignore-type */ $hardDiskFreeSpace);
Loading history...
Bug introduced by
$memoryUsage of type string is incompatible with the type integer expected by parameter $memoryUsage of MohsenAbrishami\Stethosc...acades\Record::record(). ( Ignorable by Annotation )

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

54
        Record::record($cpuUsage, /** @scrutinizer ignore-type */ $memoryUsage, $networkStatus, $webServerStatuses, $hardDiskFreeSpace);
Loading history...
Bug introduced by
$networkStatus of type string is incompatible with the type boolean expected by parameter $networkStatus of MohsenAbrishami\Stethosc...acades\Record::record(). ( Ignorable by Annotation )

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

54
        Record::record($cpuUsage, $memoryUsage, /** @scrutinizer ignore-type */ $networkStatus, $webServerStatuses, $hardDiskFreeSpace);
Loading history...
Bug introduced by
$cpuUsage of type string is incompatible with the type integer expected by parameter $cpuUsage of MohsenAbrishami\Stethosc...acades\Record::record(). ( Ignorable by Annotation )

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

54
        Record::record(/** @scrutinizer ignore-type */ $cpuUsage, $memoryUsage, $networkStatus, $webServerStatuses, $hardDiskFreeSpace);
Loading history...
55
    }
56
}
57