Passed
Push — master ( 795a3e...0f843e )
by Alexander
14:26
created

AbstractCommand::completeArgumentValues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 2
crap 2
1
<?php
2
/**
3
 * This file is part of the Console-Kit 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/console-kit
9
 */
10
11
namespace ConsoleHelpers\ConsoleKit\Command;
12
13
14
use ConsoleHelpers\ConsoleKit\Application;
15
use ConsoleHelpers\ConsoleKit\ConsoleIO;
16
use ConsoleHelpers\ConsoleKit\Helper\ContainerHelper;
17
use ConsoleHelpers\ConsoleKit\Container;
18
use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
19
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
20
use Symfony\Component\Console\Command\Command;
21
use Symfony\Component\Console\Input\ArrayInput;
22
use Symfony\Component\Console\Input\InputInterface;
23
use Symfony\Component\Console\Output\OutputInterface;
24
25
/**
26
 * Base command class.
27
 */
28
abstract class AbstractCommand extends Command implements CompletionAwareInterface
29
{
30
31
	/**
32
	 * Console IO.
33
	 *
34
	 * @var ConsoleIO
35
	 */
36
	protected $io;
37
38
	/**
39
	 * {@inheritdoc}
40
	 */
41
	protected function initialize(InputInterface $input, OutputInterface $output)
42
	{
43
		parent::initialize($input, $output);
44
45
		// Don't use IO from container, because it contains outer IO which doesn't reflect sub-command calls.
46
		$this->io = new ConsoleIO($input, $output, $this->getHelperSet());
0 ignored issues
show
Bug introduced by
It seems like $this->getHelperSet() can also be of type null; however, parameter $helper_set of ConsoleHelpers\ConsoleKit\ConsoleIO::__construct() does only seem to accept Symfony\Component\Console\Helper\HelperSet, maybe add an additional type check? ( Ignorable by Annotation )

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

46
		$this->io = new ConsoleIO($input, $output, /** @scrutinizer ignore-type */ $this->getHelperSet());
Loading history...
47
48
		$this->prepareDependencies();
49
	}
50
51
	/**
52
	 * Return possible values for the named option
53
	 *
54
	 * @param string            $optionName Option name.
55
	 * @param CompletionContext $context    Completion context.
56
	 *
57
	 * @return array
58
	 */
59
	public function completeOptionValues($optionName, CompletionContext $context)
60
	{
61
		$this->prepareDependencies();
62
63
		return array();
64
	}
65
66
	/**
67
	 * Return possible values for the named argument
68
	 *
69
	 * @param string            $argumentName Argument name.
70
	 * @param CompletionContext $context      Completion context.
71
	 *
72
	 * @return array
73
	 */
74
	public function completeArgumentValues($argumentName, CompletionContext $context)
75
	{
76
		$this->prepareDependencies();
77
78
		return array();
79
	}
80
81
	/**
82
	 * Prepare dependencies.
83
	 *
84
	 * @return void
85
	 */
86
	protected function prepareDependencies()
87
	{
88
89
	}
90
91
	/**
92
	 * Runs another command.
93
	 *
94
	 * @param string $name      Command name.
95
	 * @param array  $arguments Arguments.
96
	 *
97
	 * @return integer
98
	 */
99
	protected function runOtherCommand($name, array $arguments = array())
100
	{
101
		$arguments['command'] = $name;
102
		$cleanup_command = $this->getApplication()->find($name);
103
104
		$input = new ArrayInput($arguments);
105
106
		return $cleanup_command->run($input, $this->io->getOutput());
107
	}
108
109
	/**
110
	 * Returns container.
111
	 *
112
	 * @return Container
113
	 */
114
	protected function getContainer()
115
	{
116
		static $container;
117
118
		if ( !isset($container) ) {
119
			/** @var ContainerHelper $container_helper */
120
			$container_helper = $this->getHelper('container');
121
122
			$container = $container_helper->getContainer();
123
		}
124
125
		return $container;
126
	}
127
128
	/**
129
	 * Gets the application instance for this command.
130
	 *
131
	 * @return Application
132
	 */
133
	public function getApplication()
134
	{
135
		return parent::getApplication();
136
	}
137
138
}
139