AbstractEmberCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
namespace keeko\tools\command;
3
4
use keeko\tools\command\AbstractKeekoCommand;
5
use Symfony\Component\Console\Input\InputOption;
6
use keeko\tools\model\Project;
7
8
class AbstractEmberCommand extends AbstractKeekoCommand {
9
	
10
	private $prj;
11
	
12
	protected function configure() {
13
		$this->addOption(
14
			'package',
15
			'',
16
			InputOption::VALUE_OPTIONAL,
17
			'The package from which the models should be generated'
18
		);
19
	
20
		$this->configureGenerateOptions();
21
	
22
		parent::configure();
23
	}
24
	
25
	protected function getProject($packageName = null) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
26
		if ($this->prj === null) {
27
			if ($packageName === null) {
28
				$input = $this->io->getInput();
29
				$packageName = $input->getOption('package');
30
				if (empty($packageName)) {
31
					$packageName = $this->package->getFullName();
32
				}
33
			}
34
35
			if ($this->package->getFullName() == $packageName) {
36
				$this->prj = $this->project;
37
			} else {
38
				$path = 'vendor/' . $packageName;
39
				if (!file_exists($path)) {
40
					throw new \RuntimeException(sprintf('Package (%s) cannot be found', $packageName));
41
				}
42
				$this->prj = new Project($path);
43
			}
44
		}
45
		return $this->prj;
46
	}
47
48
}