Failed Conditions
Push — master ( 1ba572...22cc0d )
by Alexander
02:39 queued 11s
created

ReparseCommand::prepareDependencies()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * This file is part of the SVN-Buddy library.
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 *
7
 * @copyright Alexander Obuhovich <[email protected]>
8
 * @link      https://github.com/console-helpers/svn-buddy
9
 */
10
11
namespace ConsoleHelpers\SVNBuddy\Command;
12
13
14
use ConsoleHelpers\ConsoleKit\Exception\CommandException;
15
use ConsoleHelpers\SVNBuddy\Repository\Parser\RevisionListParser;
16
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\RevisionLog;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Input\InputOption;
20
use Symfony\Component\Console\Output\OutputInterface;
21
22
class ReparseCommand extends AbstractCommand
23
{
24
25
	/**
26
	 * Revision log
27
	 *
28
	 * @var RevisionLog
29
	 */
30
	private $_revisionLog;
31
32
	/**
33
	 * Revision list parser.
34
	 *
35
	 * @var RevisionListParser
36
	 */
37
	private $_revisionListParser;
38
39
	/**
40
	 * {@inheritdoc}
41
	 */
42
	protected function configure()
43
	{
44
		$this
45
			->setName('reparse')
46
			->setDescription('Reparses given revision')
47
			->addArgument(
48
				'path',
49
				InputArgument::OPTIONAL,
50
				'Working copy path',
51
				'.'
52
			)
53
			->addOption(
54
				'revisions',
55
				'r',
56
				InputOption::VALUE_REQUIRED,
57
				'List of revision(-s) and/or revision range(-s) to reparse, e.g. <comment>53324</comment>, <comment>1224-4433</comment> or <comment>all</comment>'
58
			);
59
60
		parent::configure();
61
	}
62
63
	/**
64
	 * Prepare dependencies.
65
	 *
66
	 * @return void
67
	 */
68
	protected function prepareDependencies()
69
	{
70
		parent::prepareDependencies();
71
72
		$container = $this->getContainer();
73
74
		$this->_revisionListParser = $container['revision_list_parser'];
75
	}
76
77
	/**
78
	 * {@inheritdoc}
79
	 */
80
	public function initialize(InputInterface $input, OutputInterface $output)
81
	{
82
		parent::initialize($input, $output);
83
84
		$this->_revisionLog = $this->getRevisionLog($this->getWorkingCopyUrl());
85
	}
86
87
	/**
88
	 * {@inheritdoc}
89
	 *
90
	 * @throws CommandException When mandatory "revision" option wasn't given.
91
	 */
92
	protected function execute(InputInterface $input, OutputInterface $output)
93
	{
94
		$revisions = $this->io->getOption('revisions');
95
96
		if ( !$revisions ) {
97
			throw new CommandException('The "revisions" option is mandatory.');
98
		}
99
100
		// FIXME: Not checking, that given revisions belong to a working copy.
101
		$revisions = $this->_revisionListParser->expandRanges($this->getList($revisions));
102
103
		foreach ( $this->_revisionListParser->collapseRanges($revisions) as $revision_range ) {
104
			if ( strpos($revision_range, '-') === false ) {
105
				$this->_revisionLog->reparse($revision_range, $revision_range);
106
			}
107
			else {
108
				list($from_revision, $to_revision) = explode('-', $revision_range, 2);
109
				$this->_revisionLog->reparse($from_revision, $to_revision);
0 ignored issues
show
Bug introduced by
$to_revision of type string is incompatible with the type integer expected by parameter $to_revision of ConsoleHelpers\SVNBuddy\...\RevisionLog::reparse(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

109
				$this->_revisionLog->reparse($from_revision, /** @scrutinizer ignore-type */ $to_revision);
Loading history...
Bug introduced by
$from_revision of type string is incompatible with the type integer expected by parameter $from_revision of ConsoleHelpers\SVNBuddy\...\RevisionLog::reparse(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

109
				$this->_revisionLog->reparse(/** @scrutinizer ignore-type */ $from_revision, $to_revision);
Loading history...
110
			}
111
		}
112
	}
113
114
}
115