StatusChecker   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 20
c 2
b 0
f 0
dl 0
loc 55
rs 10
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hasErrors() 0 10 3
A check() 0 4 2
A addCheck() 0 7 2
A addGroup() 0 6 2
A getResults() 0 3 1
1
<?php
2
namespace BretRZaun\StatusPage;
3
4
use BretRZaun\StatusPage\Check\CheckInterface;
5
use Psr\Log\LoggerAwareInterface;
6
use Psr\Log\LoggerAwareTrait;
7
8
class StatusChecker implements StatusCheckerInterface, LoggerAwareInterface
9
{
10
11
    use LoggerAwareTrait;
12
13
    /**
14
     * registered ungrouped checks
15
     * @var StatusCheckerGroup
16
     */
17
    protected $ungroupedChecks;
18
19
    /**
20
     * @var StatusCheckerGroup[]
21
     */
22
    protected $results = [];
23
24
    public function addCheck(CheckInterface $checker): void
25
    {
26
        if ($this->ungroupedChecks === null) {
27
            $this->ungroupedChecks = new StatusCheckerGroup('');
28
            $this->addGroup($this->ungroupedChecks);
29
        }
30
        $this->ungroupedChecks->addCheck($checker);
31
    }
32
33
    public function addGroup(StatusCheckerGroup $group): void
34
    {
35
        if ($this->logger) {
36
            $group->setLogger($this->logger);
37
        }
38
        $this->results[] = $group;
39
    }
40
41
    public function check(): void
42
    {
43
        foreach($this->results as $group) {
44
            $group->check();
45
        }
46
    }
47
48
    public function getResults(): array
49
    {
50
        return $this->results;
51
    }
52
53
    public function hasErrors(): bool
54
    {
55
        $error = false;
56
        foreach($this->results as $group) {
57
            if ($group->hasErrors()) {
58
                $error = true;
59
                break;
60
            }
61
        }
62
        return $error;
63
    }
64
}
65