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

Reflection   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getProperty() 0 7 1
A setProperty() 0 8 1
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