Test Failed
Push — master ( 77d86a...4c6a99 )
by Alec
03:20
created

BenchmarkSimpleProgressBar::getProgressBarWidth()   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;
4
5
class BenchmarkSimpleProgressBar extends Benchmark
6
{
7
    public function __construct(
8
        int $iterations = 1000,
9
        bool $quiet = false
10 1
    ) {
11
        parent::__construct($iterations);
12
        $width = $this->advanceSteps = $this->terminalWidth();
13
        if (!$quiet) {
14 1
            $progressStart =
15 1
                static function () use ($width): void {
16
                    echo ' [' . str_repeat('░', $width) . ']';
17
                    echo "\e[" . ($width + 1) . 'D';
18
                };
19 1
20 1
            $progressAdvance =
21
                static function (): void {
22
                    echo '█';
23
                };
24 1
25 1
            $progressFinish =
26 1
                static function () use ($width): void {
27
                    echo "\e[" . ($width + 1) . 'D';
28 1
                    echo "\e[K";
29 1
                };
30
31
            $this->showProgressBy($progressStart, $progressAdvance, $progressFinish);
32
        }
33
    }
34
}
35