Completed
Push — master ( 7ded52...1a27ef )
by Freek
02:07
created

throttleFailingNotificationsForMinutes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Spatie\ServerMonitor\CheckDefinitions;
4
5
use Exception;
6
use Spatie\ServerMonitor\Models\Check;
7
use Symfony\Component\Process\Process;
8
9
abstract class CheckDefinition
10
{
11
    /** @var \Spatie\ServerMonitor\Models\Check */
12
    protected $check;
13
14
    /**
15
     * @param \Spatie\ServerMonitor\Models\Check $check
16
     *
17
     * @return $this
18
     */
19
    public function setCheck(Check $check)
20
    {
21
        $this->check = $check;
22
23
        return $this;
24
    }
25
26
    public function getCommand(): string
27
    {
28
        return $this->command;
0 ignored issues
show
Bug introduced by
The property command 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...
29
    }
30
31
    public function handleFinishedProcess(Process $process)
32
    {
33
        $this->check->storeProcessOutput($process);
34
35
        try {
36
            if (! $process->isSuccessful()) {
37
                $this->handleFailedProcess($process);
38
39
                return;
40
            }
41
42
            $this->handleSuccessfulProcess($process);
43
        } catch (Exception $exception) {
44
            $this->check->failed('Exception occurred: '.$exception->getMessage());
45
        }
46
    }
47
48
    abstract public function handleSuccessfulProcess(Process $process);
49
50
    public function handleFailedProcess(Process $process)
51
    {
52
        $this->check->failed("failed to run: {$process->getErrorOutput()}");
53
    }
54
55
    public function throttleFailingNotificationsForMinutes(): int
56
    {
57
        return config('server-monitor.notifications.throttle_failing_notifications_for_minutes');
58
    }
59
60
    abstract public function performNextRunInMinutes(): int;
61
}
62