Accesor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 48
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 6 1
A get() 0 7 1
A newInstanceWithoutConstructor() 0 6 1
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
}