Completed
Push — master ( e3d6d9...ead104 )
by Marcel
11:37
created

HorizonIsRunning::message()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace BeyondCode\SelfDiagnosis\Checks;
4
5
use BeyondCode\SelfDiagnosis\Checks\Check;
6
use Illuminate\Support\Facades\Artisan;
7
8
class HorizonIsRunning implements Check
9
{
10
    private $error = null;
11
12
    /**
13
     * The name of the check.
14
     *
15
     * @param array $config
16
     * @return string
17
     */
18
    public function name(array $config): string
19
    {
20
        return trans('self-diagnosis::checks.horizon_is_running.name');
21
    }
22
23
    /**
24
     * Perform the actual verification of this check.
25
     *
26
     * @param array $config
27
     * @return bool
28
     */
29
    public function check(array $config): bool
30
    {
31
        try {
32
            Artisan::call('horizon:status');
33
            $output = Artisan::output();
34
35
            return strstr($output, 'Horizon is running.');
36
        } catch (\Exception $e) {
37
            $this->error = $e->getMessage();
38
        }
39
40
        return false;
41
    }
42
43
    /**
44
     * The error message to display in case the check does not pass.
45
     *
46
     * @param array $config
47
     * @return string
48
     */
49
    public function message(array $config): string
50
    {
51
        if ($this->error !== null) {
52
            return trans('self-diagnosis::checks.horizon_is_running.message.unable_to_check', [
53
                'reason' => $this->error,
54
            ]);
55
        }
56
57
        return trans('self-diagnosis::checks.horizon_is_running.message.not_running');
58
    }
59
}
60