Completed
Push — master ( 061e94...8714ce )
by Thomas
06:16
created

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