Test Failed
Push — master ( 13dcda...44dfad )
by Antonio Carlos
04:33
created

Horizon::check()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2.5

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 6
ccs 2
cts 4
cp 0.5
crap 2.5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PragmaRX\Health\Checkers;
4
5
use Laravel\Horizon\Contracts\MasterSupervisorRepository;
6
7
class Horizon extends Base
8
{
9
    /**
10
     * Check resource.
11
     *
12
     * @return \PragmaRX\Health\Support\Result
13
     */
14 1
    public function check()
15
    {
16 1
        return $this->horizonIsRunning()
17
            ? $this->makeHealthyResult()
18
            : $this->makeResult(false, $this->target->getErrorMessage());
19
    }
20
21
    /**
22
     * Check if Horizon is up.
23
     *
24
     * @return bool
25
     */
26 1
    protected function horizonIsRunning()
27
    {
28 1
        if (!$masters = app(MasterSupervisorRepository::class)->all()) {
29
            return false;
30
        }
31
32
        return collect($masters)->contains(function ($master) {
33
            return $master->status === 'paused';
34
        })
35
            ? false
36
            : true;
37
    }
38
}
39