CheckRepository::allThatShouldRun()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
dl 6
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Spatie\ServerMonitor;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Spatie\ServerMonitor\Exceptions\InvalidConfiguration;
7
use Spatie\ServerMonitor\Models\Check;
8
9 View Code Duplication
class CheckRepository
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    public static function allThatShouldRun(): CheckCollection
12
    {
13
        $checks = self::query()->get()->filter->shouldRun();
14
15
        return new CheckCollection($checks);
16
    }
17
18
    protected static function query(): Builder
19
    {
20
        $modelClass = static::determineCheckModel();
21
22
        return $modelClass::enabled();
23
    }
24
25
    public static function determineCheckModel(): string
26
    {
27
        $monitorModel = config('server-monitor.check_model') ?? Check::class;
28
29
        if (! is_a($monitorModel, Check::class, true)) {
30
            throw InvalidConfiguration::checkModelIsNotValid($monitorModel);
31
        }
32
33
        return $monitorModel;
34
    }
35
}
36