Completed
Push — master ( e6e2aa...27549f )
by Thomas
09:03
created

addMethods()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 22
rs 9.2
cc 1
eloc 16
nc 1
nop 2
1
<?php
2
namespace keeko\tools\generator\responder;
3
4
use gossi\codegen\model\PhpClass;
5
use keeko\framework\schema\ActionSchema;
6
use keeko\framework\utils\NameUtils;
7
use keeko\tools\model\ManyRelationship;
8
use keeko\tools\services\CommandService;
9
10
class ToManyRelationshipJsonResponderGenerator extends AbstractPayloadJsonResponderGenerator {
11
	
12
	/** @var ManyRelationship */
13
	private $relationship;
14
	
15
	public function __construct(CommandService $service, ManyRelationship $relationship) {
16
		parent::__construct($service);
17
		$this->relationship = $relationship;
18
	}
19
20
	protected function addMethods(PhpClass $class, ActionSchema $action) {
0 ignored issues
show
Unused Code introduced by
The parameter $action is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
21
		$this->generateGetPayloadMethods($class, $this->twig->render('to-many/getPayloadMethods.twig'));
22
		$this->generateNotValid($class);
23
		$this->generateNotFound($class);
24
		
25
		// method: updated(Request $request, Updated $payload) : JsonResponse
26
		$model = $this->relationship->getModel();
27
		$updated = $this->generatePayloadMethod('updated', $this->twig->render('to-many/updated.twig', [
28
			'class' => $model->getPhpName(),
29
			'related' => NameUtils::pluralize(NameUtils::toCamelCase($this->relationship->getRelatedName()))
30
		]), 'Updated');
31
		
32
		$class->setMethod($updated);
33
		$class->addUseStatement('keeko\\framework\\domain\\payload\\Updated');
34
		$class->addUseStatement($model->getNamespace() . '\\' . $model->getPhpName());
35
		
36
		// method: notUpdated(Request $request, NotUpdated $payload) : JsonResponse
37
		$notUpdated = $this->generatePayloadMethod('notUpdated', $this->twig->render('payload/notUpdated.twig'),
38
			'NotUpdated');
39
		$class->setMethod($notUpdated);
40
		$class->addUseStatement('keeko\\framework\\domain\\payload\\NotUpdated');
41
	}
42
}