RetryStrategyFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 27
ccs 13
cts 13
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 17 3
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\Messenger\Factory\Retry;
6
7
use function is_string;
8
use Psr\Container\ContainerInterface;
9
use Symfony\Component\Messenger\Retry\MultiplierRetryStrategy;
10
use Symfony\Component\Messenger\Retry\RetryStrategyInterface;
11
12
final class RetryStrategyFactory
13
{
14
    /** @var string */
15
    private $transportName;
16
17 3
    public function __construct(string $transportName)
18
    {
19 3
        $this->transportName = $transportName;
20 3
    }
21
22 3
    public function __invoke(ContainerInterface $container): RetryStrategyInterface
23
    {
24
        /** @var array $config */
25 3
        $config = $container->has('config') ? $container->get('config') : [];
26
27
        /** @var array|array<string, float|int>|string $retryConfig */
28 3
        $retryConfig = $config['messenger']['transports'][$this->transportName]['retry_strategy'] ?? [];
29
30 3
        if (is_string($retryConfig)) {
0 ignored issues
show
introduced by
The condition is_string($retryConfig) is always false.
Loading history...
31 2
            return $container->get($retryConfig);
32
        }
33
34 1
        return new MultiplierRetryStrategy(
35 1
            (int) ($retryConfig['max_retries'] ?? 3),
36 1
            (int) ($retryConfig['delay'] ?? 1000),
37 1
            (float) ($retryConfig['multiplier'] ?? 2.),
38 1
            (int) ($retryConfig['max_delay'] ?? 0)
39
        );
40
    }
41
}
42