Completed
Push — develop ( f8787b...f5c859 )
by Alec
03:03
created

BenchmarkSimpleProgressBar::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 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Tools;
4
5
class BenchmarkSimpleProgressBar extends Benchmark
6
{
7
    /** @var int */
8
    private $progressBarWidth;
0 ignored issues
show
introduced by
The private property $progressBarWidth is not used, and could be removed.
Loading history...
9
10 1
    public function __construct(
11
        int $iterations = 1000,
12
        bool $quiet = false
13
    ) {
14 1
        parent::__construct($iterations);
15 1
        $width = $this->advanceSteps = $this->terminalWidth();
16 1
        if (!$quiet) {
17
            $progressStart =
18
                static function () use ($width): void {
19
                    echo ' [' . str_repeat('░', $width) . ']';
20
                    echo "\e[" . ($width + 1) . 'D';
21
                };
22
23
            $progressAdvance =
24
                static function (): void {
25
                    echo '█';
26
                };
27
28
            $progressFinish =
29
                static function () use ($width): void {
30
                    echo "\e[" . ($width + 1) . 'D';
31
                    echo "\e[K";
32
                };
33
34
            $this->showProgressBy($progressStart, $progressAdvance, $progressFinish);
35
        }
36 1
    }
37
}
38