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

ModelPaginateJsonResponderGenerator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 29
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B addMethods() 0 25 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
}