TopProvider   A
last analyzed

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 addStrategy() 0 3 1
A getStrategy() 0 9 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\DwhBundle\DataProvider;
6
7
use DomainException;
8
use VideoGamesRecords\DwhBundle\Contracts\Strategy\TopStrategyInterface;
9
10
class TopProvider
11
{
12
    /** @var TopStrategyInterface[] */
13
    private array $strategies = [];
14
15
16
    public function getStrategy(string $name): TopStrategyInterface
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 TopStrategyInterface $strategy
29
     */
30
    public function addStrategy(TopStrategyInterface $strategy): void
31
    {
32
        $this->strategies[] = $strategy;
33
    }
34
}
35