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

Factory::__construct()   A

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
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