Completed
Push — master ( 94e820...3f0fe0 )
by Thomas
10:39
created

ContinentListJsonResponder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 12

Importance

Changes 7
Bugs 0 Features 1
Metric Value
wmc 2
c 7
b 0
f 1
lcom 0
cbo 12
dl 0
loc 39
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B found() 0 24 1
A getPayloadMethods() 0 5 1
1
<?php
2
namespace keeko\core\responder;
3
4
use Symfony\Component\HttpFoundation\Request;
5
use Symfony\Component\HttpFoundation\JsonResponse;
6
use keeko\framework\foundation\AbstractPayloadResponder;
7
use keeko\core\model\Continent;
8
use keeko\core\model\Country;
9
use keeko\framework\domain\payload\Found;
10
use Tobscure\JsonApi\Document;
11
use Tobscure\JsonApi\Collection;
12
use Tobscure\JsonApi\Parameters;
13
14
/**
15
 * Automatically generated JsonResponder for List all continents
16
 * 
17
 * @author gossi
18
 */
19
class ContinentListJsonResponder extends AbstractPayloadResponder {
20
21
	/**
22
	 * @param Request $request
23
	 * @param Found $payload
24
	 */
25
	public function found(Request $request, Found $payload) {
26
		$params = new Parameters($request->query->all());
27
		$data = $payload->getModel();
28
		$serializer = Continent::getSerializer();
29
		$resource = new Collection($data, $serializer);
30
		$resource = $resource->with($params->getInclude(['country']));
31
		$resource = $resource->fields($params->getFields([
32
			'continent' => Continent::getSerializer()->getFields(),
33
			'country' => Country::getSerializer()->getFields()
34
		]));
35
		$document = new Document($resource);
36
37
		// meta
38
		$document->setMeta([
39
			'total' => $data->getNbResults(),
40
			'first' => $data->getFirstPage(),
41
			'next' => $data->getNextPage(),
42
			'previous' => $data->getPreviousPage(),
43
			'last' => $data->getLastPage()
44
		]);
45
46
		// return response
47
		return new JsonResponse($document->toArray());
48
	}
49
50
	/**
51
	 */
52
	protected function getPayloadMethods() {
53
		return [
54
			'keeko\framework\domain\payload\Found' => 'found'
55
		];
56
	}
57
}
58