Factory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace ekinhbayar\GitAmp\Event;
4
5
use ekinhbayar\GitAmp\Exception\UnknownEvent;
6
7
class Factory
8
{
9
    /** @var array<string> */
10
    private array $specialRepositories = [];
11
12
    /**
13
     * @param array<string> $specialRepositories
14
     */
15 8
    public function __construct(array $specialRepositories)
16
    {
17 8
        $this->specialRepositories = $specialRepositories;
18 8
    }
19
20 4
    public function build(string $namespace, array $event): Event
21
    {
22 4
        $eventType = $namespace . '\\' . $event['type'];
23
24 4
        if (!$this->isValidType($eventType)) {
25 2
            throw new UnknownEvent($event['type']);
26
        }
27
28 2
        return new $eventType($event, $this->specialRepositories);
29
    }
30
31 4
    private function isValidType(string $type): bool
32
    {
33 4
        return \class_exists($type);
34
    }
35
}
36