Passed
Push — master ( ea72f9...4e305a )
by Pieter
06:03
created

Factory::build()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 6
1
<?php declare(strict_types = 1);
2
3
namespace ekinhbayar\GitAmp\Events;
4
5
class Factory
6
{
7
    public function build(array $event): Event
8
    {
9
        $eventType = 'ekinhbayar\GitAmp\Events\Type\\' . $event['type'];
10
11
        if (!$this->isValidType($eventType)) {
12
            throw new UnknownEventException($event['type']);
13
        }
14
15
        return new $eventType($event);
16
    }
17
18
    private function isValidType(string $type): bool
19
    {
20
        return class_exists($type);
21
    }
22
}
23