Passed
Push — master ( abeffe...907b02 )
by Jean-Christophe
01:39
created

ReflexionFieldsTrait::getAnnotationColumnMember()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Ubiquity\orm\parser;
3
4
use mindplay\annotations\Annotations;
5
6
trait ReflexionFieldsTrait {
7
	/**
8
	 * @param string $class
9
	 * @param string $member
10
	 * @return \Ubiquity\annotations\ColumnAnnotation|boolean
11
	 */
12
	protected function getAnnotationColumnMember($class, $member){
13
		return self::getAnnotationMember($class, $member, "@column");
0 ignored issues
show
Bug introduced by
The method getAnnotationMember() does not exist on Ubiquity\orm\parser\ReflexionFieldsTrait. Did you maybe mean getAnnotationColumnMember()? ( Ignorable by Annotation )

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

13
		return self::/** @scrutinizer ignore-call */ getAnnotationMember($class, $member, "@column");

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...
14
	}
15
	
16
	public static function getDbType($class, $member) {
17
		$ret=self::getAnnotationColumnMember($class, $member);
0 ignored issues
show
Bug Best Practice introduced by
The method Ubiquity\orm\parser\Refl...nnotationColumnMember() is not static, but was called statically. ( Ignorable by Annotation )

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

17
		/** @scrutinizer ignore-call */ 
18
  $ret=self::getAnnotationColumnMember($class, $member);
Loading history...
18
		if (!$ret)
19
			return false;
20
			else
21
				return $ret->dbType;
22
	}
23
	
24
	public static function isSerializable($class, $member) {
25
		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)
26
			return false;
27
			else
28
				return true;
29
	}
30
	
31
	public static function getFieldName($class, $member) {
32
		$ret=self::getAnnotationColumnMember($class, $member);
0 ignored issues
show
Bug Best Practice introduced by
The method Ubiquity\orm\parser\Refl...nnotationColumnMember() is not static, but was called statically. ( Ignorable by Annotation )

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

32
		/** @scrutinizer ignore-call */ 
33
  $ret=self::getAnnotationColumnMember($class, $member);
Loading history...
33
		if ($ret === false || !isset($ret->name))
34
			$ret=$member;
35
			else
36
				$ret=$ret->name;
37
				return $ret;
38
	}
39
	
40
	public static function isNullable($class, $member) {
41
		$ret=self::getAnnotationColumnMember($class, $member);
0 ignored issues
show
Bug Best Practice introduced by
The method Ubiquity\orm\parser\Refl...nnotationColumnMember() is not static, but was called statically. ( Ignorable by Annotation )

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

41
		/** @scrutinizer ignore-call */ 
42
  $ret=self::getAnnotationColumnMember($class, $member);
Loading history...
42
		if (!$ret)
43
			return false;
44
			else
45
				return $ret->nullable;
46
	}
47
	
48
	public static function getProperties($instance) {
49
		if (\is_string($instance)) {
50
			$instance=new $instance();
51
		}
52
		$reflect=new \ReflectionClass($instance);
53
		$props=$reflect->getProperties();
54
		return $props;
55
	}
56
	
57
	public static function getProperty($instance, $member) {
58
		$reflect=new \ReflectionClass($instance);
59
		$prop=false;
60
		if($reflect->hasProperty($member))
61
			$prop=$reflect->getProperty($member);
62
			return $prop;
63
	}
64
	
65
	public static function getPropertyType($class,$property){
66
		return self::getMetadata($class, $property, "@var", "type");
67
	}
68
	
69
	public static function getMetadata($class,$property, $type, $name){
70
		$a = Annotations::ofProperty($class, $property, $type);
71
		if (!count($a)){
72
			return false;
73
		}
74
		return trim($a[0]->$name,";");
75
	}
76
}
77
78