Completed
Push — develop ( eb616e...328010 )
by Alec
03:31
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
    /** @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