CoreProvider::getStrategy()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 9
rs 10
c 1
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\DwhBundle\DataProvider;
6
7
use DomainException;
8
use VideoGamesRecords\DwhBundle\Contracts\Strategy\CoreStrategyInterface;
9
10
class CoreProvider
11
{
12
    /** @var CoreStrategyInterface[] */
13
    private array $strategies = [];
14
15
16
    public function getStrategy(string $name): CoreStrategyInterface
17
    {
18
        foreach ($this->strategies as $strategy) {
19
            if ($strategy->supports($name)) {
20
                return $strategy;
21
            }
22
        }
23
24
        throw new DomainException(sprintf('Unable to find a strategy to type [%s]', $name));
25
    }
26
27
    /**
28
     * @param CoreStrategyInterface $strategy
29
     */
30
    public function addStrategy(CoreStrategyInterface $strategy): void
31
    {
32
        $this->strategies[] = $strategy;
33
    }
34
}
35