Proxy   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 47
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A get() 0 4 1
A set() 0 6 1
A setArray() 0 8 2
A reveal() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Northwoods\EntityProxy;
5
6
use ReflectionProperty;
7
8
class Proxy
9
{
10
    /** @var object */
11
    private $instance;
12
13
    /** @var ReflectionProperty[] */
14
    private $properties;
15
16
    /**
17
     * @param ReflectionProperty[] $properties
18
     */
19 4
    public function __construct(object $instance, array $properties)
20
    {
21 4
        $this->instance = $instance;
22 4
        $this->properties = $properties;
23 4
    }
24
25
    /** @return mixed */
26 1
    public function get(string $name)
27
    {
28 1
        return $this->properties[$name]->getValue($this->instance);
29
    }
30
31
    /**
32
     * @param mixed $value
33
     */
34 3
    public function set(string $name, $value): self
35
    {
36 3
        $this->properties[$name]->setValue($this->instance, $value);
37
38 3
        return $this;
39
    }
40
41 1
    public function setArray(array $values): self
42
    {
43 1
        foreach ($values as $name => $value) {
44 1
            $this->set($name, $value);
45
        }
46
47 1
        return $this;
48
    }
49
50 4
    public function reveal(): object
51
    {
52 4
        return $this->instance;
53
    }
54
}
55