BootLoader::addBootstrapper()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace N1215\Tsukuyomi;
5
6
class BootLoader implements BootLoaderInterface
7
{
8
    /** @var BootstrapperInterface[] */
9
    private $bootstrappers;
10
11
    /**
12
     * @param string[] $bootstrapperClasses
13
     */
14 2
    public function __construct(array $bootstrapperClasses)
15
    {
16 2
        $this->bootstrappers = [];
17 2
        foreach($bootstrapperClasses as $bootstrapperClass) {
18 2
            $this->addBootstrapper($bootstrapperClass);
19
        }
20 1
    }
21
22 2
    private function addBootstrapper(string $bootstrapperClass)
23
    {
24 2
        $bootstrapper = new $bootstrapperClass();
25 2
        if (!$bootstrapper instanceof BootstrapperInterface) {
26 1
            throw new \InvalidArgumentException('bootstrapper must implement' . BootstrapperInterface::class . '.');
27
        }
28
29 1
        $this->bootstrappers[] = $bootstrapper;
30 1
    }
31
32 1
    public function boot(): void
33
    {
34 1
        foreach($this->bootstrappers as $bootstrapper) {
35 1
            $bootstrapper->bootstrap();
36
        }
37 1
    }
38
}
39