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

BenchmarkOptions::getProgressThreshold()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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