Completed
Push — master ( 415b34...7ef068 )
by Thomas
13:10 queued 06:22
created

ActivityUserUpdateAction::run()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 23
rs 8.7972
cc 4
eloc 15
nc 4
nop 1
1
<?php
2
namespace keeko\core\action;
3
4
use keeko\framework\foundation\AbstractAction;
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\HttpFoundation\Response;
7
use Symfony\Component\OptionsResolver\OptionsResolver;
8
use keeko\framework\exceptions\ValidationException;
9
use Tobscure\JsonApi\Exception\InvalidParameterException;
10
use phootwork\json\Json;
11
use keeko\core\model\ActivityQuery;
12
13
/**
14
 */
15
class ActivityUserUpdateAction 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
		$activity = ActivityQuery::create()->findOneById($id);
43
		$activity->setUserId($data['id']);
44
45
		// validate
46
		if (!$activity->validate()) {
47
			throw new ValidationException($activity->getValidationFailures());
48
		} else {
49
			$activity->save();
50
			return $this->response->run($request, $activity);
0 ignored issues
show
Bug introduced by
The property response does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
51
		}
52
	}
53
}
54