Completed
Push — master ( 858c23...0b09f6 )
by Freek
01:40
created

HostRepository::query()   A

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 Spatie\ServerMonitor\Models\Host;
6
use Illuminate\Database\Eloquent\Builder;
7
use Illuminate\Database\Eloquent\Collection;
8
use Spatie\ServerMonitor\Exceptions\InvalidConfiguration;
9
10 View Code Duplication
class HostRepository
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...
11
{
12
    public static function all(): Collection
13
    {
14
        $hosts = self::query()->get();
15
16
        return $hosts;
17
    }
18
19
    protected static function query(): Builder
20
    {
21
        $modelClass = static::determineHostModel();
22
23
        return $modelClass::query();
24
    }
25
26
    /**
27
     * Determine the host model class name.
28
     *
29
     * @return string
30
     *
31
     * @throws \Spatie\ServerMonitor\Exceptions\InvalidConfiguration
32
     */
33
    public static function determineHostModel(): string
34
    {
35
        $hostModel = config('server-monitor.host_model') ?? Host::class;
36
37
        if (! is_a($hostModel, Host::class, true)) {
38
            throw InvalidConfiguration::hostModelIsNotValid($hostModel);
39
        }
40
41
        return $hostModel;
42
    }
43
}
44