Completed
Push — master ( 5895ce...415b34 )
by Thomas
08:36
created

LanguageListJsonResponder::found()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 27
rs 8.8571
cc 1
eloc 20
nc 1
nop 2
1
<?php
2
namespace keeko\core\responder;
3
4
use Symfony\Component\HttpFoundation\Request;
5
use Symfony\Component\HttpFoundation\JsonResponse;
6
use keeko\framework\domain\payload\PayloadInterface;
7
use keeko\framework\foundation\AbstractPayloadResponder;
8
use keeko\core\model\Language;
9
use keeko\core\model\LanguageScope;
10
use keeko\core\model\LanguageType;
11
use keeko\core\model\LanguageScript;
12
use keeko\core\model\LanguageFamily;
13
use Tobscure\JsonApi\Document;
14
use Tobscure\JsonApi\Collection;
15
use Tobscure\JsonApi\Parameters;
16
17
/**
18
 * Automatically generated JsonResponder for List all languages
19
 * 
20
 * @author gossi
21
 */
22
class LanguageListJsonResponder extends AbstractPayloadResponder {
23
24
	/**
25
	 * @param Request $request
26
	 * @param PayloadInterface $payload
27
	 */
28
	public function found(Request $request, PayloadInterface $payload) {
29
		$params = new Parameters($request->query->all());
30
		$data = $payload->get('model');
31
		$serializer = Language::getSerializer();
32
		$resource = new Collection($data, $serializer);
33
		$resource = $resource->with($params->getInclude(['language', 'language-scope', 'language-type', 'language-script', 'language-family']));
34
		$resource = $resource->fields($params->getFields([
1 ignored issue
show
Unused Code introduced by
The call to Parameters::getFields() has too many arguments starting with array('language' => \kee...ializer()->getFields()).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
35
			'language' => Language::getSerializer()->getFields(),
36
			'language-scope' => LanguageScope::getSerializer()->getFields(),
37
			'language-type' => LanguageType::getSerializer()->getFields(),
38
			'language-script' => LanguageScript::getSerializer()->getFields(),
39
			'language-family' => LanguageFamily::getSerializer()->getFields()
40
		]));
41
		$document = new Document($resource);
42
43
		// meta
44
		$document->setMeta([
45
			'total' => $data->getNbResults(),
46
			'first' => $data->getFirstPage(),
47
			'next' => $data->getNextPage(),
48
			'previous' => $data->getPreviousPage(),
49
			'last' => $data->getLastPage()
50
		]);
51
52
		// return response
53
		return new JsonResponse($document->toArray());
54
	}
55
56
	/**
57
	 */
58
	protected function getPayloadMethods() {
59
		return [
60
			'keeko\framework\domain\payload\Found' => 'found'
61
		];
62
	}
63
}
64