Passed
Push — master ( 1764e1...1efcca )
by Alexander
02:27
created

Application::doRunCommand()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 6
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;
12
13
14
use ConsoleHelpers\ConsoleKit\Application as BaseApplication;
15
use ConsoleHelpers\ConsoleKit\Container as BaseContainer;
16
use ConsoleHelpers\SVNBuddy\Command\AggregateCommand;
17
use ConsoleHelpers\SVNBuddy\Repository\Connector\Connector;
18
use Symfony\Component\Console\Command\Command;
19
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
20
use Symfony\Component\Console\Input\InputInterface;
21
use Symfony\Component\Console\Output\OutputInterface;
22
23
class Application extends BaseApplication
24
{
25
26
	/**
27
	 * Creates application.
28
	 *
29
	 * @param BaseContainer $container Container.
30
	 */
31
	public function __construct(BaseContainer $container)
32
	{
33
		parent::__construct($container);
34
35
		if ( $container instanceof CommandLoaderInterface ) {
36
			$this->setCommandLoader($container);
37
		}
38
39
		$helper_set = $this->getHelperSet();
40
		$helper_set->set($this->dic['date_helper']);
41
		$helper_set->set($this->dic['size_helper']);
42
		$helper_set->set($this->dic['output_helper']);
43
44
		set_time_limit(0);
45
		ini_set('memory_limit', -1);
46
47
		putenv('LC_CTYPE=en_US.UTF-8'); // For SVN.
48
	}
49
50
	/**
51
	 * @inheritDoc
52
	 */
53
	protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
54
	{
55
		try {
56
			return parent::doRunCommand($command, $input, $output);
57
		}
58
		catch ( \Exception $e ) {
59
			$this->dic['io']->notify();
60
61
			throw $e;
62
		}
63
	}
64
65
	/**
66
	 * Returns the long version of the application.
67
	 *
68
	 * @return string The long application version
69
	 *
70
	 * @api
71
	 */
72
	public function getLongVersion()
73
	{
74
		$version = parent::getLongVersion();
75
76
		/** @var Connector $repository_connector */
77
		$repository_connector = $this->dic['repository_connector'];
78
		$client_version = $repository_connector->getCommand('', array('--version', '--quiet'))->run();
79
80
		return $version . ' (SVN <comment>v' . trim($client_version) . '</comment>)';
81
	}
82
83
	/**
84
	 * {@inheritdoc}
85
	 */
86
	protected function getDefaultCommands()
87
	{
88
		$default_commands = parent::getDefaultCommands();
89
90
		// Add this command outside of container, because it scans other commands.
91
		$default_commands[] = new AggregateCommand();
92
93
		return $default_commands;
94
	}
95
96
}
97