LocalizationReadJsonResponder   C
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 19

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 19
dl 0
loc 42
rs 6.875

3 Methods

Rating   Name   Duplication   Size   Complexity  
A found() 0 18 1
A notFound() 0 3 1
A getPayloadMethods() 0 6 1
1
<?php
2
namespace keeko\core\responder\json\model;
3
4
use keeko\core\model\ApplicationUri;
5
use keeko\core\model\LanguageScript;
6
use keeko\core\model\LanguageVariant;
7
use keeko\core\model\Language;
8
use keeko\core\model\Localization;
9
use keeko\framework\domain\payload\Found;
10
use keeko\framework\domain\payload\NotFound;
11
use keeko\framework\foundation\AbstractPayloadResponder;
12
use Symfony\Component\HttpFoundation\JsonResponse;
13
use Symfony\Component\HttpFoundation\Request;
14
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
15
use Tobscure\JsonApi\Document;
16
use Tobscure\JsonApi\Parameters;
17
use Tobscure\JsonApi\Resource;
18
19
/**
20
 * Automatically generated JsonResponder for Reads a localization
21
 * 
22
 * @author Thomas Gossmann
23
 */
24
class LocalizationReadJsonResponder extends AbstractPayloadResponder {
25
26
	/**
27
	 * @param Request $request
28
	 * @param Found $payload
29
	 */
30
	public function found(Request $request, Found $payload) {
31
		$params = new Parameters($request->query->all());
32
		$serializer = Localization::getSerializer();
33
		$resource = new Resource($payload->getModel(), $serializer);
34
		$resource = $resource->with($params->getInclude(['localizations', 'parent', 'language', 'ext-lang', 'script', 'language-variants', 'application-uris']));
35
		$resource = $resource->fields($params->getFields([
36
			'localization' => Localization::getSerializer()->getFields(),
37
			'parent' => Localization::getSerializer()->getFields(),
38
			'language' => Language::getSerializer()->getFields(),
39
			'ext-lang' => Language::getSerializer()->getFields(),
40
			'script' => LanguageScript::getSerializer()->getFields(),
41
			'language-variant' => LanguageVariant::getSerializer()->getFields(),
42
			'application-uri' => ApplicationUri::getSerializer()->getFields()
43
		]));
44
		$document = new Document($resource);
45
46
		return new JsonResponse($document->toArray(), 200);
47
	}
48
49
	/**
50
	 * @param Request $request
51
	 * @param NotFound $payload
52
	 */
53
	public function notFound(Request $request, NotFound $payload) {
54
		throw new ResourceNotFoundException($payload->getMessage());
55
	}
56
57
	/**
58
	 */
59
	protected function getPayloadMethods() {
60
		return [
61
			'keeko\framework\domain\payload\Found' => 'found',
62
			'keeko\framework\domain\payload\NotFound' => 'notFound'
63
		];
64
	}
65
}
66