Completed
Push — master ( 03348b...b5d7f5 )
by Martin
18:07 queued 08:53
created

ReflectionClass   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 37
ccs 21
cts 21
cp 1
rs 10

5 Methods

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