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

AbstractEmberCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 41
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 12 1
B getProject() 0 22 6
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
}