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

ExecutionTimeLimited   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 38
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A wait() 0 8 2
A resetState() 0 4 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