CommonView::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace WebinoViewLib\Feature;
4
5
use WebinoConfigLib\Config;
6
use WebinoConfigLib\Feature\FeatureInterface;
7
use WebinoDomLib\Dom\Config\AbstractSpecConfig;
8
use WebinoDomLib\Dom\Config\SpecConfigAggregateInterface;
9
10
/**
11
 * Class CommonView
12
 */
13
class CommonView extends Config implements
14
    FeatureInterface,
15
    ViewConfigInterface
16
{
17
    /**
18
     * Config key
19
     */
20
    const COMMON = 'common';
21
22
    /**
23
     * @param array $config
24
     */
25
    public function __construct(array $config = [])
26
    {
27
        $spec = $this->createSpec($config);
28
        parent::__construct([[$this::VIEW => [$this::COMMON => $spec]]]);
29
    }
30
31
    private function createSpec(array $config, &$spec= [])
32
    {
33
        foreach ($config as $feature) {
34
35
            // TODO refactoring dependencies
36
            // if interface
37
            if (method_exists($feature, 'getDependencies')) {
38
                $spec = array_replace($spec, $this->createSpec($feature->getDependencies(), $spec));
39
            }
40
41
            if ($feature instanceof SpecConfigAggregateInterface) {
42
                $this->addFeature($feature);
0 ignored issues
show
Documentation introduced by
$feature is of type object<WebinoDomLib\Dom\...nfigAggregateInterface>, but the function expects a object<WebinoConfigLib\Feature\FeatureInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
43
                $feature = $feature->getSpecConfig();
44
            }
45
46
            if ($feature instanceof AbstractSpecConfig) {
47
                $spec[$feature->getName()] = $feature->toArray();
48
            }
49
        }
50
51
        return $spec;
52
    }
53
}
54