PropertyReference   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 41
wmc 5
lcom 1
cbo 0
ccs 17
cts 17
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getValue() 0 11 2
A setValue() 0 13 2
1
<?php
2
3
namespace Cascade\Mapper\Field\Reference;
4
5
class PropertyReference implements ReferenceInterface
6
{
7
    /**
8
     * @var string
9
     */
10
    private $property;
11
12
    /**
13
     * @param string $property
14
     */
15 6
    public function __construct($property)
16
    {
17 6
        $this->property = $property;
18 6
    }
19
20 2
    public function getValue($instance)
21
    {
22 2
        $property = $this->property;
23 2
        $className = get_class($instance);
24
25 2
        if ($className === 'stdClass') {
26 1
            return $instance->$property;
27
        }
28
29 1
        return (new \ReflectionProperty($className, $property))->getValue($instance);
30
    }
31
32 2
    public function setValue($instance, $value)
33
    {
34 2
        $property = $this->property;
35 2
        $className = get_class($instance);
36
37 2
        if ($className === 'stdClass') {
38 1
            $instance->$property = $value;
39 1
        } else {
40 1
            (new \ReflectionProperty($className, $property))->setValue($instance, $value);
41
        }
42
43 2
        return $instance;
44
    }
45
}
46