Completed
Push — master ( f90ba0...b3a61f )
by Martin
02:18
created

ReflectionClass   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 0
loc 51
ccs 26
cts 28
cp 0.9286
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 4
A getObject() 0 3 1
A from() 0 3 1
A invokeMethod() 0 6 1
A setPropertyValue() 0 7 1
A getPropertyValue() 0 6 1
A getParent() 0 3 1
1
<?php
2
namespace Yep\Reflection;
3
4
class ReflectionClass extends \ReflectionClass {
5
	/** @var object */
6
	protected $object;
7
8 10
	public function __construct($class, $object = null) {
9 10
		if (is_object($class) && !is_object($object)) {
10 6
			$object = $class;
11 6
		}
12
13 10
		if (!is_object($object)) {
14 4
			throw new \InvalidArgumentException(sprintf('Expected "object", got "%s".', gettype($object)));
15
		}
16
17 6
		parent::__construct($class);
18 6
		$this->object = $object;
19 6
	}
20
21
	public function getObject() {
22
		return $this->object;
23
	}
24
25 7
	public static function from($class, $object = null) {
26 7
		return new static($class, $object);
27
	}
28
29 1
	public function invokeMethod($method, array $arguments = []) {
30 1
		$reflection = $this->getMethod($method);
31 1
		$reflection->setAccessible(true);
32
33 1
		return $reflection->invokeArgs($this->object, $arguments);
34
	}
35
36 1
	public function setPropertyValue($property, $value) {
37 1
		$reflection = $this->getProperty($property);
38 1
		$reflection->setAccessible(true);
39 1
		$reflection->setValue($this->object, $value);
40
41 1
		return $this;
42
	}
43
44 2
	public function getPropertyValue($property) {
45 2
		$reflection = $this->getProperty($property);
46 2
		$reflection->setAccessible(true);
47
48 2
		return $reflection->getValue($this->object);
49
	}
50
51 1
	public function getParent() {
52 1
		return self::from($this->getParentClass()->getName(), $this->object);
53
	}
54
}
55