Completed
Push — master ( d6a6e9...1d4c8e )
by Thomas
10:31
created

ActionModuleUpdateAction::configureParams()   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 1
1
<?php
2
namespace keeko\core\action;
3
4
use keeko\framework\foundation\AbstractAction;
5
use Symfony\Component\OptionsResolver\OptionsResolver;
6
use keeko\framework\exceptions\ValidationException;
7
use Tobscure\JsonApi\Exception\InvalidParameterException;
8
use phootwork\json\Json;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Response;
11
use keeko\core\model\ActionQuery;
12
13
/**
14
 */
15
class ActionModuleUpdateAction extends AbstractAction {
16
17
	/**
18
	 * @param OptionsResolver $resolver
19
	 */
20
	public function configureParams(OptionsResolver $resolver) {
21
		$resolver->setRequired(['id']);
22
	}
23
24
	/**
25
	 * Automatically generated run method
26
	 * 
27
	 * @param Request $request
28
	 * @return Response
29
	 */
30
	public function run(Request $request) {
31
		$body = Json::decode($request->getContent());
1 ignored issue
show
Bug introduced by
It seems like $request->getContent() targeting Symfony\Component\HttpFo...n\Request::getContent() can also be of type resource; however, phootwork\json\Json::decode() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
32
		if (!isset($body['data'])) {
33
			throw new InvalidParameterException();
34
		}
35
		$data = $body['data'];
36
37
		if (!isset($data['id'])) {
38
			throw new InvalidParameterException();
39
		}
40
41
		$id = $this->getParam('id');
42
		$action = ActionQuery::create()->findOneById($id);
43
		$action->setModuleId($data['id']);
44
45
		// validate
46
		if (!$action->validate()) {
47
			throw new ValidationException($action->getValidationFailures());
48
		} else {
49
			$action->save();
50
			return $this->response->run($request, $action);
51
		}
52
	}
53
}
54