Passed
Branch develop (4ef38d)
by BENARD
03:50
created

CoreProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
dl 0
loc 23
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getStrategy() 0 9 3
A addStrategy() 0 3 1
1
<?php
2
3
namespace VideoGamesRecords\DwhBundle\DataProvider;
4
5
use VideoGamesRecords\DwhBundle\Contracts\Strategy\CoreStrategyInterface;
6
7
class CoreProvider
8
{
9
    /** @var CoreStrategyInterface[] */
10
    private array $strategies = [];
11
12
13
    public function getStrategy(string $name): CoreStrategyInterface
14
    {
15
        foreach ($this->strategies as $strategy) {
16
            if ($strategy->supports($name)) {
17
                return $strategy;
18
            }
19
        }
20
21
        throw new \DomainException(sprintf('Unable to find a strategy to type [%s]', $name));
22
    }
23
24
    /**
25
     * @param CoreStrategyInterface $strategy
26
     */
27
    public function addStrategy(CoreStrategyInterface $strategy): void
28
    {
29
        $this->strategies[] = $strategy;
30
    }
31
}
32