Proxy::reveal()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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