Passed
Push — master ( bff9c8...c1feec )
by Nils
02:07
created

HealthFoundationFactory::initChecks()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 12
nc 5
nop 2
dl 0
loc 23
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
namespace Leankoala\HealthFoundation\Config;
4
5
use Leankoala\HealthFoundation\Check\Check;
6
use Leankoala\HealthFoundation\HealthFoundation;
7
use PhmLabs\Components\Init\Init;
8
9
class HealthFoundationFactory
10
{
11
    public static function from($configArray)
12
    {
13
        $healthFoundation = new HealthFoundation();
14
15
        if (!array_key_exists('checks', $configArray)) {
16
            throw new \RuntimeException('The mandatory config element "checks" is missing.');
17
        }
18
19
        $healthFoundation = self::initChecks($configArray, $healthFoundation);
20
21
        return $healthFoundation;
22
    }
23
24
    /**
25
     * @param array $configArray
26
     *
27
     * @return HealthFoundation
28
     */
29
    private static function initChecks($configArray, HealthFoundation $healthFoundation)
30
    {
31
        foreach ($configArray['checks'] as $key => $checkArray) {
32
33
            /** @var Check $check */
34
            $check = Init::initialize($checkArray, 'check');
0 ignored issues
show
Unused Code introduced by
The call to PhmLabs\Components\Init\Init::initialize() has too many arguments starting with 'check'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
            /** @scrutinizer ignore-call */ 
35
            $check = Init::initialize($checkArray, 'check');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
35
36
            if (array_key_exists('description', $checkArray)) {
37
                $description = $checkArray['description'];
38
            } else {
39
                $description = "";
40
            }
41
42
            if (array_key_exists('identifier', $checkArray)) {
43
                $identifier = $checkArray['identifier'];
44
            } else {
45
                $identifier = $key;
46
            }
47
48
            $healthFoundation->registerCheck($check, $identifier, $description);
49
        }
50
51
        return $healthFoundation;
52
    }
53
}
54