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

StatusChecker::addGroup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace BretRZaun\StatusPage;
3
4
use BretRZaun\StatusPage\Check\AbstractCheck;
5
6
class StatusChecker implements StatusCheckerInterface
7
{
8
    /**
9
     * registered ungrouped checks
10
     * @var StatusCheckerGroup[]
11
     */
12
    protected $ungroupedChecks;
13
14
    /**
15
     * @var StatusCheckerGroup[]
16
     */
17
    protected $results = array();
18
19
    public function addCheck(AbstractCheck $checker)
20
    {
21
        if (!$this->ungroupedChecks) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->ungroupedChecks of type BretRZaun\StatusPage\StatusCheckerGroup[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
22
            $this->ungroupedChecks = new StatusCheckerGroup('');
0 ignored issues
show
Documentation Bug introduced by
It seems like new \BretRZaun\StatusPage\StatusCheckerGroup('') of type object<BretRZaun\StatusPage\StatusCheckerGroup> is incompatible with the declared type array<integer,object<Bre...ge\StatusCheckerGroup>> of property $ungroupedChecks.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
23
            $this->results[] = $this->ungroupedChecks;
24
        }
25
        $this->ungroupedChecks->addCheck($checker);
26
    }
27
28
    public function addGroup(StatusCheckerGroup $group)
29
    {
30
        $this->results[] = $group;
31
    }
32
33
    public function check()
34
    {
35
        foreach($this->results as $group) {
36
            $group->check();
37
        }
38
    }
39
40
    public function getResults(): array
41
    {
42
        return $this->results;
43
    }
44
45
    public function hasErrors(): bool
46
    {
47
        $error = false;
48
        foreach($this->results as $group) {
49
            if ($group->hasErrors()) {
50
                $error = true;
51
                break;
52
            }
53
        }
54
        return $error;
55
    }
56
}
57