LimitedRetryStrategy::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Ivory Http Adapter package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\HttpAdapter\Event\Retry\Strategy;
13
14
use Ivory\HttpAdapter\Event\Retry\RetryInterface;
15
use Ivory\HttpAdapter\Message\InternalRequestInterface;
16
17
/**
18
 * @author GeLo <[email protected]>
19
 */
20
class LimitedRetryStrategy extends AbstractRetryStrategyChain
21
{
22
    /**
23
     * @var int
24
     */
25
    private $limit;
26
27
    /**
28
     * @param int                              $limit
29
     * @param RetryStrategyChainInterface|null $next
30
     */
31 72
    public function __construct($limit = 3, RetryStrategyChainInterface $next = null)
32
    {
33 72
        parent::__construct($next);
34
35 72
        $this->setLimit($limit);
36 72
    }
37
38
    /**
39
     * @return int
40
     */
41 36
    public function getLimit()
42
    {
43 36
        return $this->limit;
44
    }
45
46
    /**
47
     * @param int $limit
48
     */
49 72
    public function setLimit($limit)
50
    {
51 72
        $this->limit = $limit;
52 72
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 18
    protected function doVerify(InternalRequestInterface $request)
58
    {
59 18
        return $request->getParameter(RetryInterface::RETRY_COUNT) < $this->limit;
60
    }
61
}
62