ProgressBar   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Test Coverage

Coverage 62.96%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 28
c 3
b 0
f 0
dl 0
loc 84
ccs 17
cts 27
cp 0.6296
rs 10
wmc 11

4 Methods

Rating   Name   Duplication   Size   Complexity  
A start() 0 10 2
A end() 0 9 2
A isDisabled() 0 13 4
A progress() 0 15 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Packagist Mirror.
7
 *
8
 * For the full license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webs\Mirror;
13
14
use Symfony\Component\Console\Helper\ProgressBar as ConsoleProgressBar;
15
16
/**
17
 * Progress bar for console.
18
 *
19
 * @author Webysther Nunes <[email protected]>
20
 */
21
class ProgressBar implements IProgressBar
22
{
23
    use Console;
24
25
    /**
26
     * @var bool
27
     */
28
    protected $disabled;
29
30
    /**
31
     * @var ConsoleProgressBar
32
     */
33
    protected $progressBar;
34
35
    /**s
36
     * @var int
37
     */
38
    protected $total;
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 1
    public function isDisabled():bool
44
    {
45 1
        if (isset($this->disabled)) {
46 1
            return $this->disabled;
47
        }
48
49 1
        $isQuiet = $this->output->isQuiet();
50 1
        $noProgress = $this->input->getOption('no-progress');
51 1
        $noAnsi = $this->input->getOption('no-ansi');
52
53 1
        $this->disabled = $isQuiet || $noProgress || $noAnsi;
54
55 1
        return $this->disabled;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 1
    public function start(int $total):IProgressBar
62
    {
63 1
        if ($this->isDisabled()) {
64 1
            return $this;
65
        }
66
67
        $this->total = $total;
68
        $this->progressBar = new ConsoleProgressBar($this->output, $total);
69
70
        return $this;
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76 1
    public function progress(int $current = 0):IProgressBar
77
    {
78 1
        if ($this->isDisabled()) {
79 1
            return $this;
80
        }
81
82
        if ($current) {
83
            $this->progressBar->setProgress($current);
84
85
            return $this;
86
        }
87
88
        $this->progressBar->advance();
89
90
        return $this;
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96 1
    public function end():IProgressBar
97
    {
98 1
        if ($this->isDisabled()) {
99 1
            return $this;
100
        }
101
102
        $this->progressBar->finish();
103
104
        return $this;
105
    }
106
}
107