AbstractRetryStrategyChain   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 1
dl 0
loc 87
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A hasNext() 0 4 1
A getNext() 0 4 1
A setNext() 0 4 1
A verify() 0 10 3
A delay() 0 10 3
A doVerify() 0 4 1
A doDelay() 0 4 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\Message\InternalRequestInterface;
15
16
/**
17
 * @author GeLo <[email protected]>
18
 */
19
abstract class AbstractRetryStrategyChain implements RetryStrategyChainInterface
20
{
21
    /**
22
     * @var RetryStrategyChainInterface
23
     */
24
    private $next;
25
26
    /**
27
     * @param RetryStrategyChainInterface|null $next
28
     */
29 378
    public function __construct(RetryStrategyChainInterface $next = null)
30
    {
31 378
        $this->setNext($next);
32 378
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 315
    public function hasNext()
38
    {
39 315
        return $this->next !== null;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 144
    public function getNext()
46
    {
47 144
        return $this->next;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 378
    public function setNext(RetryStrategyChainInterface $next = null)
54
    {
55 378
        $this->next = $next;
56 378
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 90
    public function verify(InternalRequestInterface $request)
62
    {
63 90
        $verify = $this->doVerify($request);
64
65 90
        if ($verify && $this->hasNext()) {
66 18
            return $this->next->verify($request);
67
        }
68
69 72
        return $verify;
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75 99
    public function delay(InternalRequestInterface $request)
76
    {
77 99
        $delay = $this->doDelay($request);
78
79 99
        if ($this->hasNext() && (($nextDelay = $this->next->delay($request)) > $delay)) {
80 9
            return $nextDelay;
81
        }
82
83 90
        return $delay;
84
    }
85
86
    /**
87
     * @param InternalRequestInterface $request
88
     *
89
     * @return bool
90
     */
91 63
    protected function doVerify(InternalRequestInterface $request)
92
    {
93 63
        return true;
94
    }
95
96
    /**
97
     * @param InternalRequestInterface $request
98
     *
99
     * @return int
100
     */
101 45
    protected function doDelay(InternalRequestInterface $request)
102
    {
103 45
        return 0;
104
    }
105
}
106