Completed
Push — master ( 8714ce...91124c )
by Thomas
10:30 queued 06:04
created

ExtensionListJsonResponder::found()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 24
rs 8.9713
cc 1
eloc 17
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\Extension;
9
use keeko\core\model\Package;
10
use Tobscure\JsonApi\Document;
11
use Tobscure\JsonApi\Collection;
12
use Tobscure\JsonApi\Parameters;
13
14
/**
15
 * Automatically generated JsonResponder for List all extensions
16
 * 
17
 * @author gossi
18
 */
19
class ExtensionListJsonResponder extends AbstractPayloadResponder {
20
21
	/**
22
	 * @param Request $request
23
	 * @param PayloadInterface $payload
24
	 */
25
	public function found(Request $request, PayloadInterface $payload) {
26
		$params = new Parameters($request->query->all());
27
		$data = $payload->Model();
0 ignored issues
show
Bug introduced by
The method Model() does not seem to exist on object<keeko\framework\d...yload\PayloadInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
28
		$serializer = Extension::getSerializer();
29
		$resource = new Collection($data, $serializer);
30
		$resource = $resource->with($params->getInclude(['package']));
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('extension' => \ke...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
			'extension' => Extension::getSerializer()->getFields(),
33
			'package' => Package::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