Passed
Push — master ( 1827cf...3466fc )
by Alec
02:53
created

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