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

BenchmarkSimpleProgressBar   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 30.76%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 30
ccs 4
cts 13
cp 0.3076
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 25 2
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