Completed
Push — master ( 0c2a73...853a48 )
by Sébastien
11s
created

ExecutionTimeLimited::resetState()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 1
nc 1
nop 0
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 for 0.4.0 to have https://github.com/Tolerance/Tolerance/pull/67
44
        // $this->timeEllapsed = 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
45
    }
46
}
47