Test Failed
Push — master ( 3e96d2...d4b731 )
by Dan
06:30
created

Reflection::setProperty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 4
1
<?php
2
3
namespace Tests\Ds\Router\Helpers;
4
5
/**
6
 * Class Reflection
7
 *
8
 * PHPUnit Helper Class
9
 *
10
 * @package Tests\Ds\Router\Helpers
11
 */
12
class Reflection
13
{
14
    /**
15
     * Get private/protected properties from Reflection.
16
     * @param string $className
17
     * @param string $property
18
     * @param object $object
19
     * @return mixed
20
     */
21
    public static function getProperty($className, $property, $object)
22
    {
23
        $reflector = new \ReflectionClass($className);
24
        $prop = $reflector->getProperty($property);
25
        $prop->setAccessible(true);
26
        return $prop->getValue($object);
27
    }
28
29
    /**
30
     * Set private/protected properies and return original object.
31
     * @param string $className
32
     * @param string $property
33
     * @param object $object
34
     * @param mixed $value
35
     * @return object
36
     */
37
    public static function setProperty($className, $property, $object, $value)
38
    {
39
        $reflectionClass = new \ReflectionClass($className);
40
        $reflectionProperty = $reflectionClass->getProperty($property);
41
        $reflectionProperty->setAccessible(true);
42
        $reflectionProperty->setValue($object, $value);
43
        return $object;
44
    }
45
}
46