Passed
Push — master ( cc91a3...057c43 )
by Christian
02:20
created

ConsoleOutput::createProgressBar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 7
ccs 0
cts 5
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Scheb\Tombstone\Analyzer\Cli;
4
5
use Symfony\Component\Console\Helper\ProgressBar;
6
use Symfony\Component\Console\Output\OutputInterface;
7
8
class ConsoleOutput
9
{
10
    /**
11
     * @var OutputInterface
12
     */
13
    private $output;
14
15
    /**
16
     * @var bool
17
     */
18
    private $isDebug;
19
20
    public function __construct(OutputInterface $output)
21
    {
22
        $this->output = $output;
23
        $this->isDebug = $output->isDebug();
24
    }
25
26
    public function write(string $string): void
27
    {
28
        $this->output->write($string);
29
    }
30
31
    public function writeln(?string $string = null): void
32
    {
33
        $this->output->writeln($string ?? '');
34
    }
35
36
    public function debug($string): void
37
    {
38
        if ($this->isDebug) {
39
            $this->writeln($string);
40
        }
41
    }
42
43
    public function createProgressBar(int $width): ProgressBar
44
    {
45
        $progress = new ProgressBar($this->output, $width);
46
        $progress->setBarWidth(50);
47
        $progress->display();
48
49
        return $progress;
50
    }
51
}
52