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

LanguageReadJsonResponder::notFound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
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 Symfony\Component\Routing\Exception\ResourceNotFoundException;
9
use keeko\core\model\Language;
10
use keeko\core\model\LanguageScope;
11
use keeko\core\model\LanguageType;
12
use keeko\core\model\LanguageScript;
13
use keeko\core\model\LanguageFamily;
14
use Tobscure\JsonApi\Document;
15
use Tobscure\JsonApi\Resource;
16
use Tobscure\JsonApi\Parameters;
17
18
/**
19
 * Automatically generated JsonResponder for Reads a language
20
 * 
21
 * @author gossi
22
 */
23
class LanguageReadJsonResponder extends AbstractPayloadResponder {
24
25
	/**
26
	 * @param Request $request
27
	 * @param PayloadInterface $payload
28
	 */
29
	public function found(Request $request, PayloadInterface $payload) {
30
		$params = new Parameters($request->query->all());
31
		$serializer = Language::getSerializer();
32
		$resource = new Resource($payload->get('model'), $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
		return new JsonResponse($document->toArray(), 200);
44
	}
45
46
	/**
47
	 * @param Request $request
48
	 * @param PayloadInterface $payload
49
	 */
50
	public function notFound(Request $request, PayloadInterface $payload) {
1 ignored issue
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
51
		throw new ResourceNotFoundException($payload->get('message'));
52
	}
53
54
	/**
55
	 */
56
	protected function getPayloadMethods() {
57
		return [
58
			'keeko\framework\domain\payload\Found' => 'found',
59
			'keeko\framework\domain\payload\NotFound' => 'notFound'
60
		];
61
	}
62
}
63