BootLoader   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 33
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A addBootstrapper() 0 9 2
A boot() 0 6 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