BadgeManager   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
c 1
b 0
f 0
dl 0
loc 23
rs 10

2 Methods

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