Completed
Push — master ( d6c5c0...118f52 )
by Thomas
04:57
created

ModelPaginateJsonResponderGenerator::addMethods()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 25
rs 8.8571
cc 2
eloc 19
nc 2
nop 2
1
<?php
2
namespace keeko\tools\generator\responder;
3
4
use gossi\codegen\model\PhpClass;
5
use keeko\framework\schema\ActionSchema;
6
7
class ModelPaginateJsonResponderGenerator extends AbstractModelJsonResponderGenerator {
8
9
	protected function addMethods(PhpClass $class, ActionSchema $action) {
10
		$this->generateGetPayloadMethods($class, $this->twig->render('model/getPayloadMethods-paginate.twig'));
11
12
		// method: found(Request $request, Found $payload) : JsonResponse
13
		$modelName = $this->modelService->getModelNameByAction($action);
14
		$model = $this->modelService->getModel($modelName);
15
		$fields = $this->getModelFields($model);
16
		foreach ($fields as $field) {
17
			$class->addUseStatement($field->getNamespace() . '\\' . $field->getPhpName());
18
		}
19
		
20
		$includes = $this->codegenService->arrayToCode($this->getRelationshipIncludes($model));
21
		$found = $this->generatePayloadMethod('found', $this->twig->render('model/paginate.twig', [
22
			'class' => $model->getPhpName(),
23
			'includes' => $includes,
24
			'fields' => $this->getFieldsCode($fields)
25
		]), 'Found');
26
		
27
		$class->setMethod($found);
28
		$class->addUseStatement('keeko\\framework\\domain\\payload\\Found');
29
		$class->addUseStatement('Tobscure\\JsonApi\\Document');
30
		$class->addUseStatement('Tobscure\\JsonApi\\Collection');
31
		$class->addUseStatement('Tobscure\\JsonApi\\Parameters');
32
		$class->addUseStatement($model->getNamespace() . '\\' . $model->getPhpName());
33
	}
34
35
}