Completed
Push — master ( 5d27f2...d6c5c0 )
by Thomas
08:45
created

AbstractEmberCommand::getProject()   B

Complexity

Conditions 6
Paths 10

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 22
rs 8.6737
cc 6
eloc 15
nc 10
nop 1
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
}