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

CountryListJsonResponder::found()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 26
rs 8.8571
cc 1
eloc 19
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\Country;
9
use keeko\core\model\Continent;
10
use keeko\core\model\Currency;
11
use keeko\core\model\RegionType;
12
use Tobscure\JsonApi\Document;
13
use Tobscure\JsonApi\Collection;
14
use Tobscure\JsonApi\Parameters;
15
16
/**
17
 * Automatically generated JsonResponder for List all countries
18
 * 
19
 * @author gossi
20
 */
21
class CountryListJsonResponder extends AbstractPayloadResponder {
22
23
	/**
24
	 * @param Request $request
25
	 * @param PayloadInterface $payload
26
	 */
27
	public function found(Request $request, PayloadInterface $payload) {
28
		$params = new Parameters($request->query->all());
29
		$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...
30
		$serializer = Country::getSerializer();
31
		$resource = new Collection($data, $serializer);
32
		$resource = $resource->with($params->getInclude(['continent', 'currency', 'region-type', 'region-type', 'country']));
33
		$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('country' => \keek...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...
34
			'country' => Country::getSerializer()->getFields(),
35
			'continent' => Continent::getSerializer()->getFields(),
36
			'currency' => Currency::getSerializer()->getFields(),
37
			'region-type' => RegionType::getSerializer()->getFields()
38
		]));
39
		$document = new Document($resource);
40
41
		// meta
42
		$document->setMeta([
43
			'total' => $data->getNbResults(),
44
			'first' => $data->getFirstPage(),
45
			'next' => $data->getNextPage(),
46
			'previous' => $data->getPreviousPage(),
47
			'last' => $data->getLastPage()
48
		]);
49
50
		// return response
51
		return new JsonResponse($document->toArray());
52
	}
53
54
	/**
55
	 */
56
	protected function getPayloadMethods() {
57
		return [
58
			'keeko\framework\domain\payload\Found' => 'found'
59
		];
60
	}
61
}
62