Factory   A
last analyzed

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