Passed
Push — develop ( 566459...cdebde )
by Alec
03:08
created

BenchmarkSimplePB::getProgressBarWidth()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlecRabbit\Tools;
6
7
// BenchmarkSimpleProgressBar
8
class BenchmarkSimplePB extends Benchmark
9
{
10
    /** @var int */
11
    private $progressBarWidth;
12
13
    public function __construct(
14
        int $iterations = 1000,
15
        ?int $progressBarWidth = null
16
    ) {
17
        parent::__construct($iterations);
18
        $this->progressBarWidth = $this->advanceSteps = $progressBarWidth ?? $this->advanceSteps;
19
20
        $progressAdvance =
21
            function (): void {
22
                echo '*';
23
            };
24
25
        $progressFinish =
26
            function (): void {
27
                echo "\e[" . $this->advanceSteps . 'D';
28
                echo "\e[K";
29
            };
30
31
        $this->progressBar(null, $progressAdvance, $progressFinish);
32
    }
33
34
    /**
35
     * @return int
36
     */
37
    public function getProgressBarWidth(): int
38
    {
39
        return $this->progressBarWidth;
40
    }
41
}
42