Sleeper::sleep()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace League\CLImate\TerminalObject\Helper;
4
5
class Sleeper implements SleeperInterface
6
{
7
    /**
8
     * The default length of the sleep
9
     *
10
     * @var int|float $speed
11
     */
12
    protected $speed = 50000;
13
14
    /**
15
     * Set the speed based on a percentage (50% slower, 200% faster, etc)
16
     *
17
     * @param int|float $percentage
18
     *
19
     * @return float
20
     */
21 12
    public function speed($percentage)
22
    {
23 12
        if (is_numeric($percentage) && $percentage > 0) {
24 8
            $this->speed *= (100 / $percentage);
25 8
        }
26
27 12
        return $this->speed;
28
    }
29
30
    /**
31
     * Sleep for the specified amount of time
32
     */
33 12
    public function sleep()
34
    {
35 12
        usleep($this->speed);
36 12
    }
37
}
38