Completed
Push — develop ( eb616e...328010 )
by Alec
03:31
created

BenchmarkSimpleProgressBar   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 32
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getProgressBarWidth() 0 3 1
A __construct() 0 19 1
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Tools;
4
5
class BenchmarkSimpleProgressBar extends Benchmark
6
{
7
    /** @var int */
8
    private $progressBarWidth;
9
10 1
    public function __construct(
11
        int $iterations = 1000,
12
        ?int $progressBarWidth = null
13
    ) {
14 1
        parent::__construct($iterations);
15 1
        $this->progressBarWidth = $this->advanceSteps = $progressBarWidth ?? $this->advanceSteps;
16
17
        $progressAdvance =
18
            function (): void {
19 1
                echo '*';
20 1
            };
21
22
        $progressFinish =
23
            function (): void {
24 1
                echo "\e[" . $this->progressBarWidth . 'D';
25 1
                echo "\e[K";
26 1
            };
27
28 1
        $this->showProgressBy(null, $progressAdvance, $progressFinish);
29 1
    }
30
31
    /**
32
     * @return int
33
     */
34 1
    public function getProgressBarWidth(): int
35
    {
36 1
        return $this->progressBarWidth;
37
    }
38
}
39