Passed
Push — master ( 8b49d6...8ffc72 )
by Alec
16:03
created

BenchmarkOptions   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 54
ccs 13
cts 15
cp 0.8667
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getProgressThreshold() 0 3 1
A setMaxIterations() 0 5 1
A isCli() 0 3 1
A __construct() 0 6 2
A getMaxIterations() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Tools\Internal;
4
5
use function AlecRabbit\Helpers\bounds;
6
7
class BenchmarkOptions
8
{
9
    /** @var bool */
10
    protected $cli = false;
11
12
    /** @var int */
13
    protected $maxIterations;
14
    /** @var int */
15
    protected $progressThreshold;
16
17
    /**
18
     * BenchmarkOptions constructor.
19
     */
20 17
    public function __construct()
21
    {
22 17
        if (PHP_SAPI === 'cli') {
23 17
            $this->cli = true;
24
        }
25 17
        $this->setMaxIterations(5);
26 17
    }
27
28
    /**
29
     * @return int
30
     */
31 17
    public function getProgressThreshold(): int
32
    {
33 17
        return $this->progressThreshold;
34
    }
35
36
    /**
37
     * @return int
38
     */
39 17
    public function getMaxIterations(): int
40
    {
41 17
        return $this->maxIterations;
42
    }
43
44
    /**
45
     * @param int $maxIterations
46
     * @return BenchmarkOptions
47
     */
48 17
    public function setMaxIterations(int $maxIterations): self
49
    {
50 17
        $this->maxIterations = (int)bounds($maxIterations, 1, 10);
51 17
        $this->progressThreshold = 10 + 1000 * $this->maxIterations;
52 17
        return $this;
53
    }
54
55
    /**
56
     * @return bool
57
     */
58
    public function isCli(): bool
59
    {
60
        return $this->cli;
61
    }
62
}
63