These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Spatie\ServerMonitor\Commands; |
||
4 | |||
5 | use Illuminate\Support\Collection; |
||
6 | use Spatie\ServerMonitor\Models\Host; |
||
7 | use Spatie\ServerMonitor\Models\Check; |
||
8 | |||
9 | class ListHosts extends BaseCommand |
||
10 | { |
||
11 | protected $signature = 'server-monitor:list-hosts |
||
12 | {--host= : Filter hosts by name} |
||
13 | {--check= : Filter checks by type}'; |
||
14 | |||
15 | protected $description = 'List all hosts with their checks'; |
||
16 | |||
17 | public function handle() |
||
18 | { |
||
19 | if ($this->determineHostModelClass()::count() === 0) { |
||
20 | return $this->info('There are no hosts configured'); |
||
21 | } |
||
22 | |||
23 | $this->table( |
||
24 | ['Host', 'Health', 'Checks'], |
||
25 | $this->getTableRows($this->determineHostModelClass()::all()) |
||
26 | ); |
||
27 | } |
||
28 | |||
29 | protected function getTableRows(Collection $hosts): array |
||
30 | { |
||
31 | if ($hostName = $this->option('host')) { |
||
32 | $hosts = $hosts->filter(function (Host $host) use ($hostName) { |
||
33 | return $host->name === $hostName; |
||
0 ignored issues
–
show
|
|||
34 | }); |
||
35 | } |
||
36 | |||
37 | return $hosts |
||
38 | ->map(function (Host $host) { |
||
39 | return [ |
||
40 | 'name' => $host->name, |
||
0 ignored issues
–
show
The property
name does not exist on object<Spatie\ServerMonitor\Models\Host> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property.
Loading history...
|
|||
41 | 'health' => $host->health_as_emoji, |
||
0 ignored issues
–
show
The property
health_as_emoji does not exist on object<Spatie\ServerMonitor\Models\Host> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property.
Loading history...
|
|||
42 | 'checks' => $this->getChecksSummary($host, $this->option('check')), |
||
43 | ]; |
||
44 | }) |
||
45 | ->toArray(); |
||
46 | } |
||
47 | |||
48 | protected function getChecksSummary(Host $host, ?string $typeFilter): string |
||
49 | { |
||
50 | return $host->checks |
||
0 ignored issues
–
show
The property
checks does not exist on object<Spatie\ServerMonitor\Models\Host> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property.
Loading history...
|
|||
51 | ->filter(function (Check $check) use ($typeFilter) { |
||
52 | if (is_null($typeFilter)) { |
||
53 | return true; |
||
54 | } |
||
55 | |||
56 | return $check->type === $typeFilter; |
||
0 ignored issues
–
show
The property
type does not exist on object<Spatie\ServerMonitor\Models\Check> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property.
Loading history...
|
|||
57 | }) |
||
58 | ->map(function (Check $check) { |
||
59 | return $check->summary; |
||
0 ignored issues
–
show
The property
summary does not exist on object<Spatie\ServerMonitor\Models\Check> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property.
Loading history...
|
|||
60 | }) |
||
61 | ->implode(PHP_EOL); |
||
62 | } |
||
63 | } |
||
64 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.