Reflection   A
last analyzed

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
 * This file is part of the DS Framework.
4
 *
5
 * (c) Dan Smith <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Tests\Ds\Router\Helpers;
11
12
/**
13
 * Class Reflection
14
 *
15
 * PHPUnit Helper Class
16
 *
17
 * @package Tests\Ds\Router\Helpers
18
 */
19
class Reflection
20
{
21
    /**
22
     * Get private/protected properties from Reflection.
23
     * @param string $className
24
     * @param string $property
25
     * @param object $object
26
     * @return mixed
27
     */
28
    public static function getProperty($className, $property, $object)
29
    {
30
        $reflector = new \ReflectionClass($className);
31
        $prop = $reflector->getProperty($property);
32
        $prop->setAccessible(true);
33
        return $prop->getValue($object);
34
    }
35
36
    /**
37
     * Set private/protected properies and return original object.
38
     * @param string $className
39
     * @param string $property
40
     * @param object $object
41
     * @param mixed $value
42
     * @return object
43
     */
44
    public static function setProperty($className, $property, $object, $value)
45
    {
46
        $reflectionClass = new \ReflectionClass($className);
47
        $reflectionProperty = $reflectionClass->getProperty($property);
48
        $reflectionProperty->setAccessible(true);
49
        $reflectionProperty->setValue($object, $value);
50
        return $object;
51
    }
52
}
53