Wait::seconds()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PHPKitchen\CodeSpecsCore\Directive;
4
5
use PHPKitchen\CodeSpecsCore\Expectation\Internal\StepsList;
6
7
/**
8
 * Represents a helper that allows to wait with a specified convention.
9
 *
10
 * @package PHPKitchen\CodeSpecsCore\Expectation
11
 * @author Dmitry Kolodko <[email protected]>
12
 */
13
class Wait {
14
    private $microSecondMultiplier = 1;
15
    private $milliSecondMultiplier = 100000;
16
    private $secondMultiplier = 1000000;
17
    private $minuteMultiplier = 60000000;
18
    private $timeToWait;
19
    private $steps;
20
21
    public function __construct(int $timeToWait, StepsList $stepsList) {
22
        $this->timeToWait = $timeToWait;
23
        $this->steps = $stepsList;
24
    }
25
26
    public function microseconds() {
27
        $this->wait('seconds', $this->microSecondMultiplier);
28
    }
29
30
    public function milliseconds() {
31
        $this->wait('seconds', $this->milliSecondMultiplier);
32
    }
33
34
    public function seconds() {
35
        $this->wait('seconds', $this->secondMultiplier);
36
    }
37
38
    public function minutes() {
39
        $this->wait('minutes', $this->minuteMultiplier);
40
    }
41
42
    protected function wait($unitOfTime, $multiplier) {
43
        $this->steps->add("I wait {$this->timeToWait} {$unitOfTime}");
44
45
        usleep($this->timeToWait * $multiplier);
46
    }
47
}