Completed
Push — master ( 6c6dd7...a2efe6 )
by Bret R.
11s
created

StatusCheckerGroup   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 76
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getTitle() 0 4 1
A addCheck() 0 4 1
A check() 0 6 2
A getResults() 0 4 1
A hasErrors() 0 11 3
1
<?php
2
namespace BretRZaun\StatusPage;
3
4
use BretRZaun\StatusPage\Check\AbstractCheck;
5
6
class StatusCheckerGroup
7
{
8
    /** @var string */
9
    protected $title;
10
11
    /** @var AbstractCheck[] */
12
    protected $checks = [];
13
14
    /** @var Result[] */
15
    protected $results = array();
16
17
18
    /**
19
     * StatusCheckerGroup constructor.
20
     * @param string $title
21
     */
22
    public function __construct(string $title)
23
    {
24
        $this->title = $title;
25
    }
26
27
    /**
28
     * @return string
29
     */
30
    public function getTitle(): string
31
    {
32
        return $this->title;
33
    }
34
35
    /**
36
     * Adds check to the group.
37
     *
38
     * @param AbstractCheck $checker
39
     */
40
    public function addCheck(AbstractCheck $checker)
41
    {
42
        $this->checks[] = $checker;
43
    }
44
45
    /**
46
     * Runs all added checks.
47
     */
48
    public function check()
49
    {
50
        foreach($this->checks as $checker) {
51
            $this->results[] = $checker->check();
52
        }
53
    }
54
55
    /**
56
     * Returns results of all run checks.
57
     *
58
     * @return Result[]
59
     */
60
    public function getResults(): array
61
    {
62
        return $this->results;
63
    }
64
65
    /**
66
     * Returns if there is an erroneous result in this group.
67
     *
68
     * @return bool
69
     */
70
    public function hasErrors(): bool
71
    {
72
        $error = false;
73
        foreach($this->results as $result) {
74
            if (!$result->getSuccess()) {
75
                $error = true;
76
                break;
77
            }
78
        }
79
        return $error;
80
    }
81
}
82