Completed
Push — master ( c9073d...17137d )
by Thomas
17:02
created

CreateActionTraitGenerator::addMethods()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 12

Duplication

Lines 16
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 16
loc 16
rs 9.4286
cc 1
eloc 12
nc 1
nop 2
1
<?php
2
namespace keeko\tools\generator\action\base;
3
4
use gossi\codegen\model\PhpTrait;
5
use keeko\core\schema\ActionSchema;
6
use keeko\tools\generator\AbstractActionTraitGenerator;
7
use keeko\tools\utils\NameUtils;
8
9 View Code Duplication
class CreateActionTraitGenerator extends AbstractActionTraitGenerator {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
	
11
	/* (non-PHPdoc)
12
	 * @see \keeko\tools\generator\AbstractTraitGenerator::addMethods()
13
	 */
14
	protected function addMethods(PhpTrait $trait, ActionSchema $action) {
15
		$modelName = $this->modelService->getModelNameByAction($action);
16
		$modelVariableName = NameUtils::toCamelCase($modelName);
17
		$modelObjectName = NameUtils::toStudlyCase($modelName);
18
		$fullModelObjectName = $this->modelService->getFullModelObjectName($action);
19
20
		// method: run(Request $request)
21
		$trait->addUseStatement($fullModelObjectName);
22
		$trait->addUseStatement('keeko\\core\\exceptions\\ValidationException');
23
		$trait->addUseStatement('keeko\\core\\utils\\HydrateUtils');
24
		$trait->setMethod($this->generateRunMethod($this->twig->render('create-run.twig', [
25
			'model' => $modelVariableName,
26
			'class' => $modelObjectName,
27
			'fields' => $this->codegenService->getWriteFields($modelName)
28
		])));
29
	}
30
}