Wait::minutes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
namespace PHPKitchen\CodeSpecs\Directive;
4
5
use PHPKitchen\CodeSpecs\Expectation\Internal\StepsList;
6
7
/**
8
 * Represents a helper that allows to wait with a specified convention.
9
 *
10
 * @package PHPKitchen\CodeSpecs\Expectation
11
 * @author Dima Kolodko <[email protected]>
12
 */
13
class Wait {
14
    private const MICROSECOND_MULTIPLIER = 1;
15
    private const MILLISECOND_MULTIPLIER = 100000;
16
    private const SECOND_MULTIPLIER = 1000000;
17
    private const MINUTE_MULTIPLIER = 60000000;
18
    private int $timeToWait;
19
    private StepsList $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', self::MICROSECOND_MULTIPLIER);
28
    }
29
30
    public function milliseconds() {
31
        $this->wait('seconds', self::MILLISECOND_MULTIPLIER);
32
    }
33
34
    public function seconds() {
35
        $this->wait('seconds', self::SECOND_MULTIPLIER);
36
    }
37
38
    public function minutes() {
39
        $this->wait('minutes', self::MINUTE_MULTIPLIER);
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
}