Completed
Push — master ( 29dd4a...211d70 )
by Joseph
11:41
created

UploadResponse::getNextCheckDelay()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace STS\StorageConnect;
4
5
use STS\Backoff\Backoff;
6
use STS\Backoff\Strategies\PolynomialStrategy;
7
8
class UploadResponse
9
{
10
    /**
11
     * @var UploadRequest
12
     */
13
    protected $request;
14
15
    /**
16
     * Original response from storage provider
17
     *
18
     * @var mixed
19
     */
20
    protected $original;
21
22
    /**
23
     * @var bool
24
     */
25
    protected $async = false;
26
27
    /**
28
     * @var int
29
     */
30
    protected $statusChecks = 0;
31
32
    public function __construct( UploadRequest $request, $original, $async = false )
33
    {
34
        $this->request = $request;
35
        $this->original = $original;
36
        $this->async = $async;
37
    }
38
39
    /**
40
     * @return bool
41
     */
42
    public function isAsync()
43
    {
44
        return $this->async;
45
    }
46
47
    /**
48
     *
49
     */
50
    public function incrementStatusCheck()
51
    {
52
        $this->statusChecks++;
53
    }
54
55
    /**
56
     * @return int
57
     */
58
    public function getStatusChecks()
59
    {
60
        return $this->statusChecks;
61
    }
62
63
    /**
64
     * @return int
65
     */
66
    public function getNextCheckDelay()
67
    {
68
        return (new Backoff)
69
            ->setStrategy(new PolynomialStrategy(30, 2))
70
            ->setWaitCap(600)
71
            ->getWaitTime($this->getStatusChecks());
72
    }
73
74
    /**
75
     * @return UploadRequest
76
     */
77
    public function getRequest()
78
    {
79
        return $this->request;
80
    }
81
82
    /**
83
     * @return mixed
84
     */
85
    public function getOriginal()
86
    {
87
        return $this->original;
88
    }
89
}