Completed
Pull Request — master (#68)
by Timothée
03:50
created

TimeOut::resetState()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Tolerance package.
5
 *
6
 * (c) Samuel ROZE <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tolerance\Waiter;
13
14
class TimeOut implements Waiter, StatefulWaiter
15
{
16
    /**
17
     * @var Waiter
18
     */
19
    private $delegateWaiter;
20
21
    /**
22
     * @var integer
23
     */
24
    private $timeOut;
25
26
    /**
27
     * @var float
28
     */
29
    private $secondsEllapsed;
30
31
    /**
32
     * @var Waiter $delegateWaiter
33
     * @var integer $timeOut
34
     */
35
    public function __construct(Waiter $delegateWaiter, $timeOut)
36
    {
37
        $this->delegateWaiter = $delegateWaiter;
38
        $this->timeOut = $timeOut;
39
        $this->secondsEllapsed = 0.0;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function wait($seconds = 1)
46
    {
47
        $this->delegateWaiter->wait($seconds);
48
        $this->secondsEllapsed += $seconds;
49
        if ($this->timeOut <= $this->secondsEllapsed) {
50
            throw Exception\TimedOutExceeded::withValue($this->timeOut);
51
        }
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function resetState()
58
    {
59
        $this->secondsEllapsed = 0;
0 ignored issues
show
Documentation Bug introduced by
The property $secondsEllapsed was declared of type double, but 0 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
60
    }
61
}
62