Passed
Pull Request — master (#980)
by butschster
08:08
created

RetryPolicy   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 6
dl 0
loc 20
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getRetryPolicy() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Queue\Attribute;
6
7
use Doctrine\Common\Annotations\Annotation\Attribute;
8
use Doctrine\Common\Annotations\Annotation\Attributes;
9
use Doctrine\Common\Annotations\Annotation\Target;
10
use Spiral\Attributes\NamedArgumentConstructor;
11
use Spiral\Queue\RetryPolicyInterface;
12
use Spiral\Queue\RetryPolicy as Policy;
13
14
/**
15
 * @Annotation
16
 * @NamedArgumentConstructor
17
 * @Target({"CLASS"})
18
 * @Attributes({
19
 *     @Attribute("maxAttempts", type="int"),
20
 *     @Attribute("delay", type="int"),
21
 *     @Attribute("multiplier", type="float"),
22
 * })
23
 */
24
#[\Attribute(\Attribute::TARGET_CLASS), NamedArgumentConstructor]
25
class RetryPolicy
26
{
27
    /**
28
     * @param 0|positive-int $maxAttempts
0 ignored issues
show
Documentation Bug introduced by
The doc comment 0|positive-int at position 0 could not be parsed: Unknown type name '0' at position 0 in 0|positive-int.
Loading history...
29
     * @param positive-int $delay in seconds.
30
     */
31 11
    public function __construct(
32
        protected readonly int $maxAttempts = 3,
33
        protected readonly int $delay = 1,
34
        protected readonly float $multiplier = 1
35
    ) {
36 11
    }
37
38 3
    public function getRetryPolicy(): RetryPolicyInterface
39
    {
40 3
        return new Policy(
41 3
            maxAttempts: $this->maxAttempts,
42 3
            delay: $this->delay,
43 3
            multiplier: $this->multiplier
44 3
        );
45
    }
46
}
47