Completed
Push — master ( c5cc72...7c6f56 )
by Jean-Christophe
02:02
created

BaseAnnotation   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 2
dl 0
loc 40
rs 10
c 0
b 0
f 0
1
<?php
2
use micro\utils\StrUtils;
3
require_once ROOT.DS.'micro/addendum/annotations.php';
4
5
class BaseAnnotation extends \Annotation {
6
7
	public function getProperties(){
8
		$reflect = new \ReflectionClass($this);
9
		$props   = $reflect->getProperties();
10
		return $props;
11
	}
12
13
	public function getPropertiesAndValues($props=NULL){
14
		$ret=array();
15
		if(is_null($props))
16
			$props=$this->getProperties($this);
17
			foreach ($props as $prop){
18
				$prop->setAccessible(true);
19
				$v=$prop->getValue($this);
20
					if($v!==null && $v!=="" && isset($v)){
21
						$ret[$prop->getName()]=$v;
22
				}
23
			}
24
			return $ret;
25
	}
26
27
	public function __toString(){
28
		$fields=$this->getPropertiesAndValues();
29
		$exts=array();
30
		$extsStr="";
31
		foreach ($fields as $k=>$v){
32
			if(\is_bool($v)===true){
33
				$exts[]=$k."=".StrUtils::getBooleanStr($v);
34
			}else{
35
				$exts[]=$k."=\"".$v."\"";
36
			}
37
		}
38
		if(\sizeof($exts)>0){
39
			$extsStr="(".\implode(",", $exts).")";
40
		}
41
42
		return "@".get_class($this).$extsStr;
43
	}
44
}
45