Completed
Pull Request — master (#54)
by Timothée
08:58
created

ExecutionTimeLimited::wait()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace Rezzza\RestApiBehatExtension\Tolerance;
4
5
use Tolerance\Waiter\Waiter;
6
use Tolerance\Waiter\StatefulWaiter;
7
8
class ExecutionTimeLimited implements Waiter, StatefulWaiter
9
{
10
    /**
11
     * @var Waiter
12
     */
13
    private $waiter;
14
15
    private $maxExecutionTime;
16
17
    private $timeEllapsed;
18
19
    public function __construct(Waiter $waiter, $maxExecutionTime)
20
    {
21
        $this->waiter = $waiter;
22
        $this->maxExecutionTime = $maxExecutionTime;
23
        $this->timeEllapsed = 0;
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function wait($seconds = 1)
30
    {
31
        $this->timeEllapsed += $seconds;
32
        if ($this->maxExecutionTime < $this->timeEllapsed) {
33
            throw MaxExecutionTimeReached::withValue($this->maxExecutionTime);
34
        }
35
        $this->waiter->wait($seconds);
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function resetState()
42
    {
43
        // wait to fix https://github.com/Tolerance/Tolerance/pull/66
44
    }
45
}
46