Completed
Push — master ( d197f6...1397b8 )
by Morris
32:43 queued 21:43
created

ConsoleOutput::advance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 7
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Thomas Müller <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2017, ownCloud GmbH
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
23
namespace OC\Migration;
24
25
26
use OCP\Migration\IOutput;
27
use Symfony\Component\Console\Helper\ProgressBar;
28
use Symfony\Component\Console\Output\OutputInterface;
29
30
/**
31
 * Class SimpleOutput
32
 *
33
 * Just a simple IOutput implementation with writes messages to the log file.
34
 * Alternative implementations will write to the console or to the web ui (web update case)
35
 *
36
 * @package OC\Migration
37
 */
38
class ConsoleOutput implements IOutput {
39
40
	/** @var OutputInterface */
41
	private $output;
42
43
	/** @var ProgressBar */
44
	private $progressBar;
45
46
	public function __construct(OutputInterface $output) {
47
		$this->output = $output;
48
	}
49
50
	/**
51
	 * @param string $message
52
	 */
53
	public function info($message) {
54
		$this->output->writeln("<info>$message</info>");
55
	}
56
57
	/**
58
	 * @param string $message
59
	 */
60
	public function warning($message) {
61
		$this->output->writeln("<comment>$message</comment>");
62
	}
63
64
	/**
65
	 * @param int $max
66
	 */
67 View Code Duplication
	public function startProgress($max = 0) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
		if (!is_null($this->progressBar)) {
69
			$this->progressBar->finish();
70
		}
71
		$this->progressBar = new ProgressBar($this->output);
72
		$this->progressBar->start($max);
73
	}
74
75
	/**
76
	 * @param int $step
77
	 * @param string $description
78
	 */
79 View Code Duplication
	public function advance($step = 1, $description = '') {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
		if (!is_null($this->progressBar)) {
81
			$this->progressBar = new ProgressBar($this->output);
82
			$this->progressBar->start();
83
		}
84
		$this->progressBar->advance($step);
85
	}
86
87
	public function finishProgress() {
88
		if (is_null($this->progressBar)) {
89
			return;
90
		}
91
		$this->progressBar->finish();
92
	}
93
}
94