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

ApplicationUriLocalizationUpdateAction   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configureParams() 0 3 1
B run() 0 23 4
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\ApplicationUriQuery;
12
13
/**
14
 */
15
class ApplicationUriLocalizationUpdateAction 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
		$applicationUri = ApplicationUriQuery::create()->findOneById($id);
43
		$applicationUri->setLocalizationId($data['id']);
44
45
		// validate
46
		if (!$applicationUri->validate()) {
47
			throw new ValidationException($applicationUri->getValidationFailures());
48
		} else {
49
			$applicationUri->save();
50
			return $this->response->run($request, $applicationUri);
51
		}
52
	}
53
}
54