Passed
Push — fix/radiobuttonstyling ( e57dd3...53f350 )
by Ben
15:46 queued 08:51
created

Monitor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Thinktomorrow\Chief\HealthMonitor;
6
7
use Thinktomorrow\Chief\HealthMonitor\Checks\HealthCheck;
8
use Thinktomorrow\Chief\HealthMonitor\Exceptions\InvalidClassException;
9
10
class Monitor
11
{
12
    private $checks = [
13
    ];
14
15
    public function __construct()
16
    {
17
        $this->checks = config('thinktomorrow.chief.healthMonitor', []);
18 32
    }
19
20 32
    public function check()
21 32
    {
22
        foreach ($this->checks as $check) {
23 32
            $checkInstance = app($check);
24 32
            
25 32
            if (! $checkInstance instanceof HealthCheck) {
26
                throw new InvalidClassException('Checks must implement Healthcheck interface.');
27 1
            }
28
29
            $notifiers = $checkInstance->notifiers();
30
31
            if (!$checkInstance->check()) {
32
                foreach ($notifiers as $notifier) {
33
                    app($notifier)->onFailure($checkInstance);
0 ignored issues
show
Bug introduced by
The method onFailure() does not exist on Illuminate\Contracts\Foundation\Application. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
                    app($notifier)->/** @scrutinizer ignore-call */ onFailure($checkInstance);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
                }
35
                return;
36
            } else {
37
                foreach ($notifiers as $notifier) {
38
                    app($notifier)->onSuccess($checkInstance);
0 ignored issues
show
Bug introduced by
The method onSuccess() does not exist on Illuminate\Contracts\Foundation\Application. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
                    app($notifier)->/** @scrutinizer ignore-call */ onSuccess($checkInstance);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
                }
40
            }
41
        }
42
    }
43
}
44