StrategyFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 24
rs 10
c 0
b 0
f 0
ccs 0
cts 11
cp 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 15 3
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Webhook\Domain\Infrastructure\Strategy;
6
7
8
/**
9
 * Class StrategyFactory
10
 *
11
 * @package Webhook\Domain\Infrastructure\Strategy
12
 */
13
class StrategyFactory
14
{
15
    /**
16
     * @param string $name
17
     * @param array $options
18
     *
19
     * @return StrategyInterface
20
     */
21
    public static function create(string $name, array $options = []): StrategyInterface
22
    {
23
        if (false !== $class = StrategyRegistry::getClassByName($name)) {
24
            /** @var StrategyInterface $instance */
25
            $instance = new $class;
26
            if ($instance instanceof SetOptionsInterface) {
27
                $instance->setOptions($options);
28
            }
29
30
            return $instance;
31
32
        }
33
34
        throw new \RuntimeException('Unsupported strategy name.');
35
    }
36
}