Passed
Push — develop ( 4090f6...ac2b4d )
by BENARD
09:57
created

BadgeManager::getStrategy()   A

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