Completed
Push — master ( 1d4c8e...a7ae23 )
by Thomas
16:08 queued 10:12
created

User   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 11
Bugs 0 Features 1
Metric Value
wmc 11
c 11
b 0
f 1
lcom 0
cbo 3
dl 0
loc 68
rs 10
ccs 0
cts 38
cp 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSerializer() 0 7 2
A newActivity() 0 19 2
A getActivityObject() 0 9 3
A findActivityObject() 0 21 4
1
<?php
2
namespace keeko\core\model;
3
4
use keeko\core\model\Base\User as BaseUser;
5
use keeko\core\model\serializer\UserSerializer;
6
use keeko\framework\model\ApiModelInterface;
7
use Symfony\Component\OptionsResolver\OptionsResolver;
8
9
/**
10
 * Skeleton subclass for representing a row from the 'kk_user' table.
11
 *
12
 * You should add additional methods to this class to meet the
13
 * application requirements.  This class will only be generated as
14
 * long as it does not already exist in the output directory.
15
 */
16
class User extends BaseUser implements ApiModelInterface {
17
18
	/**
19
	 */
20
	private static $serializer;
21
22
	/**
23
	 */
24
	public static function getSerializer() {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
25
		if (self::$serializer === null) {
26
			self::$serializer = new UserSerializer();
27
		}
28
29
		return self::$serializer;
30
	}
31
	
32
	public function newActivity(array $activity) {
33
		$resolver = new OptionsResolver();
34
		$resolver->setRequired(['verb', 'object']);
35
		$resolver->setOptional(['target']);
0 ignored issues
show
Bug introduced by
The method setOptional() does not seem to exist on object<Symfony\Component...solver\OptionsResolver>.

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...
36
		$resolver->setAllowedTypes([
0 ignored issues
show
Bug introduced by
The call to setAllowedTypes() misses a required argument $allowedTypes.

This check looks for function calls that miss required arguments.

Loading history...
Documentation introduced by
array('target' => array(...odel\\ActivityObject')) is of type array<string,array<integ...",\"1\":\"string\"}>"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
37
			'target' => ['keeko\framework\model\ActivityObjectInterface', 'keeko\core\model\ActivityObject'],
38
			'object' => ['keeko\framework\model\ActivityObjectInterface', 'keeko\core\model\ActivityObject']
39
		]);
40
		$options = $resolver->resolve($activity);
41
		
42
		$obj = new Activity();
43
		$obj->setActor($this);
44
		$obj->setVerb($options['verb']);
45
		$obj->setObject($this->getActivityObject($options['object']));
46
		if (isset($options['target'])) {
47
			$obj->setTarget($this->getActivityObject($options['target']));
48
		}
49
		$obj->save();
50
	}
51
	
52
	private function getActivityObject($obj) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
53
		if ($obj instanceof ActivityObject) {
54
			return $obj;
55
		}
56
	
57
		if ($obj instanceof ActivityObjectInterface) {
0 ignored issues
show
Bug introduced by
The class keeko\core\model\ActivityObjectInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
58
			return $this->findActivityObject($obj->toActivityObject());
59
		}
60
	}
61
	
62
	private function findActivityObject(ActivityObject $ao) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
63
		$q = ActivityObjectQuery::create()
64
			->filterByClassName($ao->getClassName())
65
			->filterByType($ao->getType())
66
			->filterByReferenceId($ao->getId());
67
		
68
		if (method_exists($ao, 'getVersion')) {
69
			$version = $ao->getVersion();
70
			if (!empty($version)) {
71
				$q = $q->filterByVersion($version);
72
			}
73
		}
74
		
75
		$result = $q->findOne();
76
		if ($result) {
77
			$result->setDisplayName($ao->getDisplayName());
78
			return $result;
79
		}
80
	
81
		return $ao;
82
	}
83
}
84