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

ApiReadJsonResponder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 12
dl 0
loc 37
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A found() 0 13 1
A notFound() 0 3 1
A getPayloadMethods() 0 6 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\domain\payload\PayloadInterface;
7
use keeko\framework\foundation\AbstractPayloadResponder;
8
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
9
use keeko\core\model\Api;
10
use keeko\core\model\Action;
11
use Tobscure\JsonApi\Document;
12
use Tobscure\JsonApi\Resource;
13
use Tobscure\JsonApi\Parameters;
14
15
/**
16
 * Automatically generated JsonResponder for Reads an api
17
 * 
18
 * @author gossi
19
 */
20
class ApiReadJsonResponder extends AbstractPayloadResponder {
21
22
	/**
23
	 * @param Request $request
24
	 * @param PayloadInterface $payload
25
	 */
26
	public function found(Request $request, PayloadInterface $payload) {
27
		$params = new Parameters($request->query->all());
28
		$serializer = Api::getSerializer();
29
		$resource = new Resource($payload->get('model'), $serializer);
30
		$resource = $resource->with($params->getInclude(['action']));
31
		$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('api' => \keeko\co...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...
32
			'api' => Api::getSerializer()->getFields(),
33
			'action' => Action::getSerializer()->getFields()
34
		]));
35
		$document = new Document($resource);
36
37
		return new JsonResponse($document->toArray(), 200);
38
	}
39
40
	/**
41
	 * @param Request $request
42
	 * @param PayloadInterface $payload
43
	 */
44
	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...
45
		throw new ResourceNotFoundException($payload->get('message'));
46
	}
47
48
	/**
49
	 */
50
	protected function getPayloadMethods() {
51
		return [
52
			'keeko\framework\domain\payload\Found' => 'found',
53
			'keeko\framework\domain\payload\NotFound' => 'notFound'
54
		];
55
	}
56
}
57