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

UpdateActionTraitGenerator   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
lcom 1
cbo 6
dl 0
loc 27
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A addMethods() 0 21 1
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
class UpdateActionTraitGenerator extends AbstractActionTraitGenerator {
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: configureParams(OptionsResolver $resolver)
21
		$this->addConfigureParamsMethod($trait, $this->twig->render('update-configureParams.twig'));
22
	
23
		// method: run(Request $request)
24
		$trait->addUseStatement($fullModelObjectName);
25
		$trait->addUseStatement($fullModelObjectName . 'Query');
26
		$trait->addUseStatement('keeko\\core\\exceptions\\ValidationException');
27
		$trait->addUseStatement('keeko\\core\\utils\\HydrateUtils');
28
		$trait->addUseStatement('Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException');
29
		$trait->setMethod($this->generateRunMethod($this->twig->render('update-run.twig', [
30
			'model' => $modelVariableName,
31
			'class' => $modelObjectName,
32
			'fields' => $this->codegenService->getWriteFields($modelName)
33
		])));
34
	}
35
}