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

Factory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 27
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 9 2
A __construct() 0 3 1
A isValidType() 0 3 1
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