Completed
Pull Request — master (#10)
by
unknown
11:04
created

ResolverStrategyService::getStrategy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Lamoda\QueueBundle\Service;
5
6
use Lamoda\QueueBundle\Strategy\Delay\DelayStrategyInterface;
7
8
class ResolverStrategyService
9
{
10
    public const DEFAULT_STRATEGY = 'default_delay_strategy';
11
12
    /**
13
     * @var array
14
     */
15
    protected $handlers;
16
17
    /**
18
     * @var array
19
     */
20
    protected $queuesConfiguration;
21
22 1
    public function __construct(iterable $handlers, array $queuesConfiguration = [])
23
    {
24 1
        $this->handlers            = iterator_to_array($handlers);
25 1
        $this->queuesConfiguration = $queuesConfiguration;
26 1
    }
27
28 1
    public function getStrategy(string $queueName): DelayStrategyInterface
29
    {
30 1
        $strategyKey = $this->queuesConfiguration[$queueName] ?? self::DEFAULT_STRATEGY;
31
32 1
        return $this->handlers[$strategyKey];
33
    }
34
}
35