ModelSkeletonUI::show()   B
last analyzed

Complexity

Conditions 6
Paths 10

Size

Total Lines 33
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 8.439
c 0
b 0
f 0
cc 6
eloc 25
nc 10
nop 0
1
<?php
2
namespace keeko\tools\ui;
3
4
use keeko\tools\ui\AbstractUI;
5
use Symfony\Component\Console\Question\ConfirmationQuestion;
6
use Symfony\Component\Console\Question\Question;
7
8
abstract class ModelSkeletonUI extends AbstractUI {
9
10
	public function show() {
11
		$input = $this->io->getInput();
12
		$name = $input->getArgument('name');
13
		$model = $input->getOption('model');
14
		
15
		if ($model !== null) {
16
			return;
17
		} else if ($name !== null) {
18
			$generateModel = false;
19
		} else {
20
			$label = $this->getLabel();
21
			$label = (in_array($label[0], ['a', 'e', 'i', 'o', 'u']) ? 'an' : 'a') . ' ' . $label;
22
			$modelQuestion = new ConfirmationQuestion('Do you want to generate ' . $label . ' based off a model?');
23
			$generateModel = $this->askConfirmation($modelQuestion);
24
		}
25
		
26
		// ask questions for a model
27
		if ($generateModel !== false) {
28
			$modelService = $this->command->getService()->getModelService();
29
			$schema = str_replace(getcwd(), '', $modelService->getSchema());
30
			$allQuestion = new ConfirmationQuestion(sprintf('For all models in the schema (%s)?', $schema));
31
			$allModels = $this->askConfirmation($allQuestion);
32
		
33
			if (!$allModels) {
34
				$modelQuestion = new Question('Which model');
35
				$modelQuestion->setAutocompleterValues($modelService->getModelNames());
36
				$model = $this->askQuestion($modelQuestion);
37
				$input->setOption('model', $model);
38
			}
39
		} else {
40
			$this->showSkeleton();
41
		}
42
	}
43
44
	abstract protected function showSkeleton();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
45
46
	abstract protected function getLabel();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
47
}