Completed
Push — master ( dd800d...af5658 )
by Thomas
07:26
created

ResponseUI::showSkeleton()   C

Complexity

Conditions 8
Paths 18

Size

Total Lines 47
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 47
rs 5.7377
cc 8
eloc 33
nc 18
nop 0
1
<?php
2
namespace keeko\tools\ui;
3
4
use keeko\tools\ui\ModelSkeletonUI;
5
use Symfony\Component\Console\Question\Question;
6
use keeko\framework\utils\NameUtils;
7
8
class ResponseUI extends ModelSkeletonUI {
9
10
	protected function getLabel() {
11
		return 'responder';
12
	}
13
	
14
	protected function showSkeleton() {
15
		$packageService = $this->getService()->getPackageService();
16
		$modelService = $this->getService()->getModelService();
17
		$input = $this->getService()->getIOService()->getInput();
18
		$name = $input->getArgument('name');
0 ignored issues
show
Unused Code introduced by
$name is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
19
		
20
		$names = [];
21
		$module = $packageService->getModule();
22
		foreach ($module->getActionNames() as $actionName) {
23
			$names[] = $actionName;
24
		}
25
			
26
		$actionQuestion = new Question('Which action');
27
		$actionQuestion->setAutocompleterValues($names);
28
		$name = $this->askQuestion($actionQuestion);
29
		$input->setArgument('name', $name);
30
		
31
		// ask which format
32
		$formatQuestion = new Question('Which format', 'json');
33
		$formatQuestion->setAutocompleterValues(['json', 'html']);
34
		$format = $this->askQuestion($formatQuestion);
35
		$input->setOption('format', $format);
36
		
37
		// ask which template
38
		$action = $packageService->getAction($name);
39
		if (!($format == 'json' && $modelService->isModelAction($action))) {
40
			$templates = [
41
				'html' => ['twig', 'blank'],
42
				'json' => ['api', 'blank']
43
			];
44
			
45
			$suggestions = isset($templates[$format]) ? $templates[$format] : [];
46
			$default = count($suggestions) ? $suggestions[0] : '';
47
			$templateQuestion = new Question('Which template', $default);
48
			$templateQuestion->setAutocompleterValues($suggestions);
49
			$template = $this->askQuestion($templateQuestion);
50
			$input->setOption('template', $template);
51
			
52
			// aks for serializer
53
			if ($format == 'json' && $template == 'api') {
54
				$guessedSerializer = NameUtils::toStudlyCase($name) . 'Serializer';
55
				$serializerQuestion = new Question('Which format', $guessedSerializer);
56
				$serializer = $this->askQuestion($serializerQuestion);
57
				$input->setOption('serializer', $serializer);
58
			}
59
		}
60
	}
61
}