Completed
Push — master ( 98cd2e...56265b )
by Thomas
09:01
created

AbstractActionTraitGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 4
dl 0
loc 30
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 10 1
A addMethods() 0 2 1
A ensureUseStatements() 0 6 1
1
<?php
2
namespace keeko\tools\generator\action;
3
4
use gossi\codegen\model\AbstractPhpStruct;
5
use gossi\codegen\model\PhpTrait;
6
use keeko\framework\schema\ActionSchema;
7
8
class AbstractActionTraitGenerator extends AbstractActionGenerator {
9
	
10
	/**
11
	 * Generates an action trait with the given name as classname
12
	 * 
13
	 * @param string $name
14
	 * @param ActionSchema $action
15
	 * @return PhpTrait
16
	 */
17
	public function generate($name, ActionSchema $action) {
18
		$trait = PhpTrait::create($name)
19
			->setDescription('Base methods for ' . $action->getClass())
20
			->setLongDescription('This code is automatically created. Modifications will probably be overwritten.');
21
	
22
		$this->ensureUseStatements($trait);
23
		$this->addMethods($trait, $action);
24
25
		return $trait;
26
	}
27
28
	protected function addMethods(PhpTrait $struct, ActionSchema $action) {
29
	}
30
	
31
	protected function ensureUseStatements(AbstractPhpStruct $struct) {
32
		parent::ensureUseStatements($struct);
33
		$struct->removeUseStatement('keeko\\framework\\foundation\\AbstractAction');
34
		$struct->addUseStatement('Symfony\\Component\\HttpFoundation\\Request');
35
		$struct->addUseStatement('Symfony\\Component\\HttpFoundation\\Response');
36
	}
37
}