Passed
Push — master ( ad7958...88028e )
by Alexander
03:19 queued 01:10
created

BootstrapGroup::bootstrap()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Horat1us\Yii;
6
7
use yii\base;
8
use yii\di;
9
10
/**
11
 * Class ComposeBootstrap
12
 * @package Horat1us\Yii
13
 */
14
class BootstrapGroup extends base\BaseObject implements base\BootstrapInterface
15
{
16
    /**
17
     * All of this bootstraps will be used.
18
     * @var array|string|base\BootstrapInterface references
19
     */
20
    public $items = [];
21
22
    /**
23
     * @param base\Application $app
24
     * @throws base\InvalidConfigException
25
     */
26 2
    public function bootstrap($app): void
27
    {
28 2
        foreach ($this->items as $reference) {
0 ignored issues
show
Bug introduced by
The expression $this->items of type array|string|object<yii\base\BootstrapInterface> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
29
            /** @var base\BootstrapInterface $bootstrap */
30 2
            $bootstrap = di\Instance::ensure($reference, base\BootstrapInterface::class);
31 1
            $bootstrap->bootstrap($app);
32
        }
33 1
    }
34
}
35