Completed
Push — master ( 4c6a99...b37e90 )
by Alec
05:15 queued 02:22
created

BenchmarkSimpleProgressBar::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 15
nc 2
nop 2
dl 0
loc 25
ccs 3
cts 3
cp 1
crap 2
rs 9.7666
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 1
    public function __construct(
8
        int $iterations = 1000,
9
        bool $quiet = false
10
    ) {
11 1
        parent::__construct($iterations);
12 1
        $width = $this->advanceSteps = $this->terminalWidth();
13
        // @codeCoverageIgnoreStart
14
        if (!$quiet) {
15
            $progressStart =
16
                static function () use ($width): void {
17
                    echo ' [' . str_repeat('░', $width) . ']';
18
                    echo "\e[" . ($width + 1) . 'D';
19
                };
20
            $progressAdvance =
21
                static function (): void {
22
                    echo '█';
23
                };
24
25
            $progressFinish =
26
                static function () use ($width): void {
27
                    echo "\e[" . ($width + 1) . 'D';
28
                    echo "\e[K";
29
                };
30
31
            $this->showProgressBy($progressStart, $progressAdvance, $progressFinish);
32
        }
33
        // @codeCoverageIgnoreEnd
34 1
    }
35
}
36