Completed
Push — master ( cac1be...eadaa3 )
by Thomas
04:35
created

ModelResponseTraitGenerator::addUseStatements()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 4
cts 4
cp 1
rs 10
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
namespace keeko\tools\generator;
3
4
use gossi\codegen\model\AbstractPhpStruct;
5
use gossi\codegen\model\PhpTrait;
6
use keeko\core\schema\ActionSchema;
7
use keeko\tools\utils\NameUtils;
8
use gossi\codegen\model\PhpMethod;
9
use gossi\codegen\model\PhpParameter;
10
11
class ModelResponseTraitGenerator extends AbstractResponseGenerator {
12
13
	/**
14
	 * Generates a json response class for the given action
15
	 *
16
	 * @param ActionSchema $action
17
	 * @return PhpTrait
18
	 */
19 2
	public function generate(ActionSchema $action) {
20 2
		return $this->doGenerate($action, 'json');
21
	}
22
	
23
	/**
24
	 * Generates the struct
25
	 *
26
	 * @param ActionSchema $action
27
	 * @param string $format
28
	 * @return PhpTrat
29
	 */
30 2
	protected function generateStruct(ActionSchema $action, $format) {
31 2
		$modelName = $this->modelService->getModelNameByAction($action);
32 2
		$model = $this->modelService->getModel($modelName);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
33
34 2
		$namespace = $this->modelService->getDatabase()->getNamespace();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
35 2
		$nsModelName = $namespace . '\\' . $model->getPhpName();
36
37 2
		$response = $action->getResponse($format);
38 2
		$name = str_replace('action', 'response', $response);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
39 2
		$ns = dirname(str_replace('\\', '/', $name));
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
40 2
		$name = str_replace('/', '\\', $ns) . '\\' . $model->getPhpName() . 'ResponseTrait';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
41
		
42 2
		return PhpTrait::create($name)
43 2
			->setDescription('Automatically generated common response methods for ' . $modelName)
44 2
			->addUseStatement($nsModelName);
45
	}
46
	
47 2
	protected function addUseStatements(AbstractPhpStruct $struct) {
48 2
		$struct->addUseStatement('keeko\\core\\utils\\FilterUtils');
49 2
		$struct->addUseStatement('Propel\\Runtime\\Map\\TableMap');
50 2
	}
51
	
52 2
	protected function addMethods(PhpTrait $trait, ActionSchema $action) {
53 2
		$modelName = $this->modelService->getModelNameByAction($action);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
54 2
		$model = $this->modelService->getModel($modelName);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 13 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
55 2
		$modelVariableName = NameUtils::toCamelCase($modelName);
56 2
		$modelObjectName = $model->getPhpName();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
57 2
		$codegen = $this->codegenService->getCodegen();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
58
59
		// method: filter(array ${{model}})
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
60 2
		$trait->setMethod(PhpMethod::create('filter')
61 2
			->setDescription('Automatically generated method, will be overridden')
62 2
			->addParameter(PhpParameter::create($modelVariableName)->setType('array'))
63 2
			->setVisibility('protected')
64 2
			->setBody($this->twig->render('filter.twig', [
65 2
				'model' => $modelVariableName,
66 2
				'filter' => $this->codegenService->arrayToCode($codegen->getReadFilter($modelName))
67 2
			]))
68 2
		);
69
	
70
		// method: {{model}}toArray({{Model}} ${{model}})
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
71 2
		$trait->setMethod(PhpMethod::create($modelVariableName . 'ToArray')
72 2
			->setDescription('Automatically generated method, will be overridden')
73 2
			->addParameter(PhpParameter::create($modelVariableName)->setType($modelObjectName))
74 2
			->setVisibility('protected')
75 2
			->setBody($this->twig->render('modelToArray.twig', ['model' => $modelVariableName]))
76 2
		);
77 2
	}
78
	
79
}
80