Completed
Pull Request — master (#306)
by Ben
35:27 queued 07:50
created

Monitor   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 7
eloc 15
c 3
b 1
f 0
dl 0
loc 29
ccs 15
cts 15
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A check() 0 19 6
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 33
    public function __construct()
16
    {
17 33
        $this->checks = config('thinktomorrow.chief.healthMonitor', []);
18 33
    }
19
20 33
    public function check()
21
    {
22 33
        foreach ($this->checks as $check) {
23 33
            $checkInstance = app($check);
24
            
25 33
            if (! $checkInstance instanceof HealthCheck) {
26 1
                throw new InvalidClassException('Checks must implement Healthcheck interface.');
27
            }
28
29 32
            $notifiers = $checkInstance->notifiers();
30
31 32
            if (!$checkInstance->check()) {
32 32
                foreach ($notifiers as $notifier) {
33 32
                    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 32
                return;
36
            } else {
37 1
                foreach ($notifiers as $notifier) {
38 1
                    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