Passed
Push — master ( b68a78...d29a76 )
by Jean-Christophe
16:10 queued 03:52
created

ReflexionFieldsTrait::getProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 3
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Ubiquity\orm\parser;
4
5
6
trait ReflexionFieldsTrait {
7
8
	abstract public static function getAnnotationMember($class, $member, $annotation);
9
	abstract public static function getAnnotsEngine();
10
11
	/**
12
	 *
13
	 * @param string $class
14
	 * @param string $member
15
	 * @return \Ubiquity\annotations\ColumnAnnotation|boolean
0 ignored issues
show
Bug introduced by
The type Ubiquity\annotations\ColumnAnnotation was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
	 */
17 48
	protected static function getAnnotationColumnMember($class, $member) {
18 48
		return self::getAnnotationMember ( $class, $member, 'column' );
19
	}
20
21 48
	public static function getDbType($class, $member) {
22 48
		$ret = self::getAnnotationColumnMember ( $class, $member );
23 48
		if (! $ret)
24 47
			return false;
25
		else
26 48
			return $ret->dbType;
0 ignored issues
show
Bug introduced by
The property dbType does not exist on true.
Loading history...
27
	}
28
29 48
	public static function isSerializable($class, $member) {
30 48
		if (self::getAnnotationMember ( $class, $member, 'transient' ) !== false || self::getAnnotationMember ( $class, $member, 'manyToOne' ) !== false || self::getAnnotationMember ( $class, $member, 'manyToMany' ) !== false || self::getAnnotationMember ( $class, $member, 'oneToMany' ) !== false)
31 48
			return false;
32
		else
33 48
			return true;
34
	}
35
36 48
	public static function getFieldName($class, $member) {
37 48
		$ret = self::getAnnotationColumnMember ( $class, $member );
38 48
		if ($ret === false || ! isset ( $ret->name ))
0 ignored issues
show
Bug introduced by
The property name does not exist on true.
Loading history...
39 47
			$ret = $member;
40
		else
41 48
			$ret = $ret->name;
42 48
		return $ret;
43
	}
44
45 48
	public static function isNullable($class, $member) {
46 48
		$ret = self::getAnnotationColumnMember ( $class, $member );
47 48
		if (! $ret)
48 47
			return false;
49
		else
50 48
			return $ret->nullable;
0 ignored issues
show
Bug introduced by
The property nullable does not exist on true.
Loading history...
51
	}
52
53 57
	public static function getProperties($class) {
54 57
		$reflect = new \ReflectionClass ( $class );
55 57
		return $reflect->getProperties ();
56
	}
57
58 34
	public static function getProperty($instance, $member) {
59 34
		$reflect = new \ReflectionClass ( $instance );
60 34
		$prop = false;
61 34
		if ($reflect->hasProperty ( $member )) {
62 34
			$prop = $reflect->getProperty ( $member );
63
		}
64 34
		return $prop;
65
	}
66
67 8
	public static function getPropertyType($class, $property) {
68 8
		if(($r=self::getMetadata ( $class, $property, 'var', 'type' ))===false){
69
			$reflect=new \ReflectionProperty($class, $property);
70
			return $reflect->getType();
71
		}
72 8
		return $r;
73
	}
74
75 8
	public static function getMetadata($class, $property, $type, $name) {
76 8
		$a = self::getAnnotsEngine()->getAnnotsOfProperty ( $class, $property, $type );
77 8
		if (! \count ( $a )) {
78
			return false;
79
		}
80 8
		return \trim ( $a [0]->$name, ';' );
81
	}
82
}
83
84