Test Failed
Push — master ( 93f81f...e78505 )
by Jean-Christophe
78:02
created

BaseAnnotationTrait::getPropertiesAndValues()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 16
rs 8.4444
cc 8
nc 8
nop 1
1
<?php
2
namespace Ubiquity\annotations;
3
4
use Ubiquity\utils\base\UArray;
5
6
/**
7
 * Ubiquity\annotations$BaseAnnotationTrait
8
 * This class is part of Ubiquity
9
 * @author jc
10
 * @version 1.0.0
11
 *
12
 */
13
trait BaseAnnotationTrait {
14
	public function getProperties() {
15
		$reflect = new \ReflectionClass ( $this );
16
		$props = $reflect->getProperties ();
17
		return $props;
18
	}
19
20
	public function getPropertiesAndValues($props = NULL) {
21
		$ret = [];
22
		$defaultParameters=$this->getDefaultParameters();
0 ignored issues
show
Bug introduced by
It seems like getDefaultParameters() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
		/** @scrutinizer ignore-call */ 
23
  $defaultParameters=$this->getDefaultParameters();
Loading history...
23
		if (\is_null ( $props ))
24
			$props = $this->getProperties ( $this );
0 ignored issues
show
Unused Code introduced by
The call to Ubiquity\annotations\Bas...nTrait::getProperties() has too many arguments starting with $this. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
			/** @scrutinizer ignore-call */ 
25
   $props = $this->getProperties ( $this );

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. Please note the @ignore annotation hint above.

Loading history...
25
			foreach ( $props as $prop ) {
26
				$prop->setAccessible ( true );
27
				$name=$prop->getName();
28
				$v = $prop->getValue ( $this );
29
				if ($v !== null && $v !== '' && isset ( $v )) {
30
					if(!isset($defaultParameters[$name]) || $defaultParameters[$name]!==$v){
31
						$ret [$name] = $v;
32
					}
33
				}
34
			}
35
			return $ret;
36
	}
37
}
38
39