Completed
Push — master ( f99fed...57dceb )
by Jean-Christophe
03:29
created

JReflection   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 29
rs 10
c 2
b 0
f 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A shortClassName() 0 4 1
B jsonObject() 0 18 5
A callMethod() 0 3 1
1
<?php
2
3
namespace Ajax\service;
4
5
class JReflection {
6
	public static function shortClassName($object){
7
		$classNameWithNamespace = get_class($object);
8
		return substr($classNameWithNamespace, strrpos($classNameWithNamespace, '\\')+1);
9
	}
10
11
	public static function jsonObject($classname){
12
		$object=new $classname();
13
		$class = new \ReflectionClass($classname);
14
		$methods=$class->getMethods(\ReflectionMethod::IS_PUBLIC);
15
		foreach ($methods as $method){
16
			$name=$method->getName();
17
			if(JString::startswith($name, "set")){
18
				$property=\strtolower(JString::replaceAtFirst($name, "set", ""));
19
				$value="__".$property."__";
20
				try{
21
					if($class->getProperty($property)!==null){
22
						\call_user_func_array([$object,$name],[$value]);
23
					}
24
				}catch(\Exception $e){}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
25
			}
26
		}
27
		return $object;
28
	}
29
30
	public static function callMethod($object,$callback,array $values){
31
		return \call_user_func_array([$object,$callback],$values);
32
	}
33
}