Passed
Push — develop ( d84c4e...84aa32 )
by Alec
05:02 queued 01:51
created

BenchmarkSymfonyPB::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
2
3
declare(strict_types=1);
4
5
namespace AlecRabbit\Tools;
6
7
use Symfony\Component\Console\Helper\ProgressBar;
8
use Symfony\Component\Console\Output\ConsoleOutput;
9
10
// BenchmarkSymfonyProgressBar
11
class BenchmarkSymfonyPB extends Benchmark
12
{
13
    public const PROGRESS_BAR_WIDTH = 80;
14
15
    /** @var ConsoleOutput */
16
    protected $output;
17
    /** @var ProgressBar */
18
    protected $progressBar;
19
    /** @var int */
20
    private $progressBarWidth;
21
22 1
    public function __construct(
23
        int $iterations = 1000,
24
        ?int $progressBarMax = null,
25
        ?int $progressBarWidth = null,
26
        ?ConsoleOutput $output = null
27
    ) {
28 1
        parent::__construct($iterations);
29 1
        $this->output = $output ?? new ConsoleOutput();
30 1
        $this->advanceSteps = $progressBarMax ?? $this->advanceSteps;
31 1
        $this->progressBarWidth = $progressBarWidth ?? self::PROGRESS_BAR_WIDTH;
32
33 1
        $this->progressBar = new ProgressBar($this->output, $this->advanceSteps);
34 1
        $this->progressBar->setBarWidth($this->progressBarWidth);
35
        $progressStart =
36
            function (): void {
37 1
                $this->progressBar->start();
38 1
            };
39
40
        $progressAdvance =
41
            function (): void {
42 1
                $this->progressBar->advance();
43 1
            };
44
45
        $progressFinish =
46
            function (): void {
47 1
                $this->progressBar->finish();
48 1
                $this->progressBar->clear();
49 1
            };
50
51 1
        $this->progressBar($progressStart, $progressAdvance, $progressFinish);
52 1
    }
53
54
    /**
55
     * @return ConsoleOutput
56
     */
57 1
    public function getOutput(): ConsoleOutput
58
    {
59 1
        return $this->output;
60
    }
61
62
    /**
63
     * @return ProgressBar
64
     */
65 1
    public function getProgressBar(): ProgressBar
66
    {
67 1
        return $this->progressBar;
68
    }
69
70
    /**
71
     * @return int
72
     */
73 1
    public function getProgressBarWidth(): int
74
    {
75 1
        return $this->progressBarWidth;
76
    }
77
}
78