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

ModuleUpdateJsonResponder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 13

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 13
dl 0
loc 55
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A notFound() 0 3 1
A notUpdated() 0 3 1
A notValid() 0 3 1
A updated() 0 13 1
A getPayloadMethods() 0 8 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\framework\exceptions\ValidationException;
10
use keeko\core\model\Module;
11
use keeko\core\model\Package;
12
use Tobscure\JsonApi\Document;
13
use Tobscure\JsonApi\Resource;
14
use Tobscure\JsonApi\Parameters;
15
16
/**
17
 * Automatically generated JsonResponder for Updates a module
18
 * 
19
 * @author gossi
20
 */
21
class ModuleUpdateJsonResponder extends AbstractPayloadResponder {
22
23
	/**
24
	 * @param Request $request
25
	 * @param PayloadInterface $payload
26
	 */
27
	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...
28
		throw new ResourceNotFoundException($payload->get('message'));
29
	}
30
31
	/**
32
	 * @param Request $request
33
	 * @param PayloadInterface $payload
34
	 */
35
	public function notUpdated(Request $request, PayloadInterface $payload) {
2 ignored issues
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...
Unused Code introduced by
The parameter $payload 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...
36
		return new JsonResponse(null, 204);
37
	}
38
39
	/**
40
	 * @param Request $request
41
	 * @param PayloadInterface $payload
42
	 */
43
	public function notValid(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...
44
		new ValidationException($payload->get('errors'));
45
	}
46
47
	/**
48
	 * @param Request $request
49
	 * @param PayloadInterface $payload
50
	 */
51
	public function updated(Request $request, PayloadInterface $payload) {
52
		$params = new Parameters($request->query->all());
53
		$serializer = Module::getSerializer();
54
		$resource = new Resource($payload->get('model'), $serializer);
55
		$resource = $resource->with($params->getInclude(['package']));
56
		$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('module' => \keeko...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...
57
			'module' => Module::getSerializer()->getFields(),
58
			'package' => Package::getSerializer()->getFields()
59
		]));
60
		$document = new Document($resource);
61
62
		return new JsonResponse($document->toArray(), 200);
63
	}
64
65
	/**
66
	 */
67
	protected function getPayloadMethods() {
68
		return [
69
			'keeko\framework\domain\payload\NotValid' => 'notValid',
70
			'keeko\framework\domain\payload\NotFound' => 'notFound',
71
			'keeko\framework\domain\payload\Updated' => 'updated',
72
			'keeko\framework\domain\payload\NotUpdated' => 'notUpdated'
73
		];
74
	}
75
}
76