HorizonIsRunning::check()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 11
ccs 0
cts 7
cp 0
crap 6
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Longman\LaravelLodash\SelfDiagnosis\Checks;
6
7
use BeyondCode\SelfDiagnosis\Checks\Check;
8
use Laravel\Horizon\Contracts\MasterSupervisorRepository;
9
10
use function collect;
11
use function trans;
12
13
class HorizonIsRunning implements Check
14
{
15
    /**
16
     * @var \Laravel\Horizon\Contracts\MasterSupervisorRepository
17
     */
18
    private $supervisorRepository;
19
20
    public function __construct(MasterSupervisorRepository $supervisorRepository)
21
    {
22
        $this->supervisorRepository = $supervisorRepository;
23
    }
24
25
    public function name(array $config): string
26
    {
27
        return trans('lodash::checks.horizon_is_running.name');
28
    }
29
30
    public function check(array $config): bool
31
    {
32
        $masters = $this->supervisorRepository->all();
33
        if (! $masters) {
34
            return false;
35
        }
36
37
        return ! collect($masters)->contains(static function ($master) {
38
            return $master->status === 'paused';
39
        });
40
    }
41
42
    public function message(array $config): string
43
    {
44
        return trans('lodash::checks.horizon_is_running.message');
45
    }
46
}
47