| Total Complexity | 11 |
| Total Lines | 85 |
| Duplicated Lines | 30.59 % |
| Coverage | 0% |
| Changes | 0 | ||
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 21 | class ProgressBar implements IProgressBar |
||
| 22 | { |
||
| 23 | use Console; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var bool |
||
| 27 | */ |
||
| 28 | protected $disabled; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var CliProgressBar |
||
| 32 | */ |
||
| 33 | protected $progressBar; |
||
| 34 | |||
| 35 | /**s |
||
| 36 | * @var int |
||
| 37 | */ |
||
| 38 | protected $total; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * {@inheritdoc} |
||
| 42 | */ |
||
| 43 | public function isDisabled():bool |
||
| 44 | { |
||
| 45 | if (isset($this->disabled)) { |
||
| 46 | return $this->disabled; |
||
| 47 | } |
||
| 48 | |||
| 49 | $isQuiet = $this->output->isQuiet(); |
||
| 50 | $noProgress = $this->input->getOption('no-progress'); |
||
| 51 | $noAnsi = $this->input->getOption('no-ansi'); |
||
| 52 | |||
| 53 | $this->disabled = $isQuiet || $noProgress || $noAnsi; |
||
| 54 | |||
| 55 | return $this->disabled; |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * {@inheritdoc} |
||
| 60 | */ |
||
| 61 | public function start(int $total):IProgressBar |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * {@inheritdoc} |
||
| 75 | */ |
||
| 76 | View Code Duplication | public function progress(int $current = 0):IProgressBar |
|
| 77 | { |
||
| 78 | if ($this->isDisabled()) { |
||
| 79 | return $this; |
||
| 80 | } |
||
| 81 | |||
| 82 | if ($current) { |
||
| 83 | $this->progressBar->progress($current); |
||
| 84 | |||
| 85 | return $this; |
||
| 86 | } |
||
| 87 | |||
| 88 | $this->progressBar->progress(); |
||
| 89 | |||
| 90 | return $this; |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * {@inheritdoc} |
||
| 95 | */ |
||
| 96 | View Code Duplication | public function end():IProgressBar |
|
| 106 | } |
||
| 107 | } |
||
| 108 |