Passed
Push — 0.5 ( 992a0c...ce220b )
by Ben
07:09
created

Monitor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Thinktomorrow\Chief\System\HealthMonitor;
6
7
use Thinktomorrow\Chief\System\HealthMonitor\Checks\HealthCheck;
8
use Thinktomorrow\Chief\System\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
    }
19
20
    public function check()
21
    {
22
        foreach ($this->checks as $check) {
23
            $checkInstance = app($check);
24
25
            if (!$checkInstance instanceof HealthCheck) {
26
                throw new InvalidClassException('Checks must implement Healthcheck interface.');
27
            }
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
36
                return;
37
            } else {
38
                foreach ($notifiers as $notifier) {
39
                    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

39
                    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...
40
                }
41
            }
42
        }
43
    }
44
}
45