CheckPresenter::getNextRunDiffAttribute()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 0
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\ServerMonitor\Models\Presenters;
4
5
use Spatie\ServerMonitor\Models\Enums\CheckStatus;
6
7
trait CheckPresenter
8
{
9
    public function getStatusAsEmojiAttribute(): string
10
    {
11
        if ($this->status === CheckStatus::SUCCESS) {
0 ignored issues
show
Bug introduced by
The property status does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
12
            return '✅';
13
        }
14
15
        if ($this->status === CheckStatus::FAILED) {
16
            return '❌';
17
        }
18
19
        if ($this->status === CheckStatus::WARNING) {
20
            return '⚠️';
21
        }
22
23
        if ($this->status === CheckStatus::NOT_YET_CHECKED) {
24
            return '';
25
        }
26
27
        if (is_null($this->status)) {
28
            return '❓';
29
        }
30
31
        return '';
32
    }
33
34
    public function getSummaryAttribute(): string
35
    {
36
        return "{$this->status_as_emoji}  {$this->type}: {$this->last_run_message}";
0 ignored issues
show
Bug introduced by
The property status_as_emoji does not seem to exist. Did you mean status?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Bug introduced by
The property type does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
The property last_run_message does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
37
    }
38
39
    public function getLatestRunDiffAttribute(): string
40
    {
41
        if (! $this->last_ran_at) {
0 ignored issues
show
Bug introduced by
The property last_ran_at does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
42
            return 'Did not run yet';
43
        }
44
45
        return $this->last_ran_at->diffForHumans();
46
    }
47
48
    public function getNextRunDiffAttribute(): string
49
    {
50
        if (! $this->next_run_in_minutes) {
0 ignored issues
show
Bug introduced by
The property next_run_in_minutes does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
51
            return 'As soon as possible';
52
        }
53
54
        if (! $this->last_ran_at) {
55
            return 'As soon as possible';
56
        }
57
58
        $nextRun = $this->last_ran_at->addMinutes($this->next_run_in_minutes);
59
60
        if ($nextRun->isPast()) {
61
            return 'As soon as possible';
62
        }
63
64
        return $this->last_ran_at->addMinutes($this->next_run_in_minutes)->diffForHumans();
65
    }
66
}
67