Passed
Push — master ( 5f573b...01f3e2 )
by Alexander
12:45
created

InfoCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 13
ccs 0
cts 11
cp 0
rs 9.9666
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\SVNBuddy\Repository\RevisionLog\Plugin\DatabaseCollectorPlugin\ProjectsPlugin;
15
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\RevisionLog;
16
use Symfony\Component\Console\Helper\Table;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
class InfoCommand extends AbstractCommand implements IAggregatorAwareCommand
22
{
23
24
	/**
25
	 * Revision log
26
	 *
27
	 * @var RevisionLog
28
	 */
29
	private $_revisionLog;
30
31
	/**
32
	 * {@inheritdoc}
33
	 */
34
	protected function configure()
35
	{
36
		$this
37
			->setName('info')
38
			->setDescription('Displays working copy information')
39
			->addArgument(
40
				'path',
41
				InputArgument::OPTIONAL,
42
				'Working copy path',
43
				'.'
44
			);
45
46
		parent::configure();
47
	}
48
49
	/**
50
	 * {@inheritdoc}
51
	 */
52
	public function initialize(InputInterface $input, OutputInterface $output)
53
	{
54
		parent::initialize($input, $output);
55
56
		$this->_revisionLog = $this->getRevisionLog($this->getWorkingCopyUrl());
57
	}
58
59
	/**
60
	 * {@inheritdoc}
61
	 */
62
	protected function execute(InputInterface $input, OutputInterface $output)
63
	{
64
		$wc_path = $this->getWorkingCopyPath();
65
66
		$command = $this->repositoryConnector->getCommand('info', array($wc_path, '--xml'));
67
		$xml = $command->run();
68
69
		$table_data = array(
70
			array('Path', $xml->entry['path']),
71
			array('Working Copy Root Path', $xml->entry->{'wc-info'}->{'wcroot-abspath'}),
72
			array('URL', $xml->entry->url),
73
			array('Relative URL', $xml->entry->{'relative-url'}),
74
			array('Repository Root', '<info>' . $xml->entry->repository->root . '</info>'),
75
			array('Repository UUID', $xml->entry->repository->uuid),
76
			array('Revision', $xml->entry['revision']),
77
			array('Node Kind', $xml->entry['kind']), // TODO: Prettify "dir = directory, ...".
78
			array('Schedule', $xml->entry->{'wc-info'}->schedule),
79
			array('Last Changed Author', $xml->entry->commit->author),
80
			array('Last Changed Rev', $xml->entry->commit['revision']),
81
			array('Last Changed Date', $xml->entry->commit->date),
82
		);
83
84
		$table = new Table($this->io->getOutput());
85
		$table->setHeaders(array('Field Name', 'Field Value'));
86
		$table->setRows($table_data);
87
		$table->render();
88
	}
89
90
	/**
91
	 * Returns option names, that makes sense to use in aggregation mode.
92
	 *
93
	 * @return array
94
	 */
95
	public function getAggregatedOptions()
96
	{
97
		return array();
98
	}
99
100
}
101