Accesor::get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
namespace Workana\AsyncJobs\Normalizer;
3
4
use ReflectionClass;
5
use ReflectionProperty;
6
7
/**
8
 * Property accesor
9
 *
10
 * @author Carlos Frutos <[email protected]>
11
 */
12
abstract class Accesor
13
{
14
    /**
15
     * Set protected/private property
16
     *
17
     * @param object $target
18
     * @param string $propertyName
19
     * @param mixed $value
20
     *
21
     * @return void
22
     */
23
    public static function set($target, $propertyName, $value)
24
    {
25
        $property = new ReflectionProperty($target, $propertyName);
26
        $property->setAccessible(true);
27
        $property->setValue($target, $value);
28
    }
29
30
    /**
31
     * Get protected/private property
32
     *
33
     * @param object $target
34
     * @param string $propertyName
35
     *
36
     * @return mixed
37
     */
38
    public static function get($target, $propertyName)
39
    {
40
        $property = new ReflectionProperty($target, $propertyName);
41
        $property->setAccessible(true);
42
        
43
        return $property->getValue($target);
44
    }
45
46
    /**
47
     * Creates a new instance without using constructor
48
     *
49
     * @param string $class
50
     *
51
     * @return mixed
52
     */
53
    public static function newInstanceWithoutConstructor($class)
54
    {
55
        $reflection = new ReflectionClass($class);
56
57
        return $reflection->newInstanceWithoutConstructor();
58
    }
59
}