CallbackRetryStrategy   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 2
cbo 1
dl 0
loc 97
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A hasVerifyCallback() 0 4 1
A getVerifyCallback() 0 4 1
A setVerifyCallback() 0 4 1
A hasDelayCallback() 0 4 1
A getDelayCallback() 0 4 1
A setDelayCallback() 0 4 1
A doVerify() 0 8 2
A doDelay() 0 8 2
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
class CallbackRetryStrategy extends AbstractRetryStrategyChain
20
{
21
    /**
22
     * @var callable|null
23
     */
24
    private $verifyCallback;
25
26
    /**
27
     * @var callable|null
28
     */
29
    private $delayCallback;
30
31
    /**
32
     * @param callable|null                    $verifyCallback
33
     * @param callable|null                    $delayCallback
34
     * @param RetryStrategyChainInterface|null $next
35
     */
36 72
    public function __construct($verifyCallback = null, $delayCallback = null, RetryStrategyChainInterface $next = null)
37
    {
38 72
        parent::__construct($next);
39
40 72
        $this->setVerifyCallback($verifyCallback);
41 72
        $this->setDelayCallback($delayCallback);
42 72
    }
43
44
    /**
45
     * @return bool
46
     */
47 45
    public function hasVerifyCallback()
48
    {
49 45
        return $this->verifyCallback !== null;
50
    }
51
52
    /**
53
     * @return callable|null
54
     */
55 27
    public function getVerifyCallback()
56
    {
57 27
        return $this->verifyCallback;
58
    }
59
60
    /**
61
     * @param callable|null $verifyCallback
62
     */
63 72
    public function setVerifyCallback($verifyCallback)
64
    {
65 72
        $this->verifyCallback = $verifyCallback;
66 72
    }
67
68
    /**
69
     * @return bool
70
     */
71 45
    public function hasDelayCallback()
72
    {
73 45
        return $this->delayCallback !== null;
74
    }
75
76
    /**
77
     * @return callable|null
78
     */
79 27
    public function getDelayCallback()
80
    {
81 27
        return $this->delayCallback;
82
    }
83
84
    /**
85
     * @param callable|null $delayCallback
86
     */
87 72
    public function setDelayCallback($delayCallback)
88
    {
89 72
        $this->delayCallback = $delayCallback;
90 72
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95 18
    protected function doVerify(InternalRequestInterface $request)
96
    {
97 18
        if ($this->hasVerifyCallback()) {
98 9
            return call_user_func($this->verifyCallback, $request);
99
        }
100
101 9
        return parent::doVerify($request);
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107 18
    protected function doDelay(InternalRequestInterface $request)
108
    {
109 18
        if ($this->hasDelayCallback()) {
110 9
            return call_user_func($this->delayCallback, $request);
111
        }
112
113 9
        return parent::doDelay($request);
114
    }
115
}
116