Completed
Pull Request — master (#55)
by Pieter
04:20
created

Factory::build()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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