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

ReflectionClass::setPropertyValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 5
cts 5
cp 1
rs 9.4286
cc 1
eloc 4
nc 1
nop 2
crap 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