PropertyObjectProxy   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 8
dl 0
loc 27
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A object() 0 3 1
A state() 0 3 1
A apply() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Dflydev\FiniteStateMachine\ObjectProxy;
6
7
use Dflydev\FiniteStateMachine\Contracts\ObjectProxy;
8
use Dflydev\FiniteStateMachine\State\State;
9
use Dflydev\FiniteStateMachine\Transition\Transition;
10
use ReflectionProperty;
11
12
class PropertyObjectProxy implements ObjectProxy
13
{
14
    private object $object;
15
    private ReflectionProperty $property;
16
17 19
    public function __construct(object $object, ReflectionProperty $property)
18
    {
19 19
        $this->object = $object;
20 19
        $this->property = $property;
21 19
    }
22
23 13
    public function object(): object
24
    {
25 13
        return $this->object;
26
    }
27
28 14
    public function state(): ?string
29
    {
30 14
        return $this->property->getValue($this->object);
31
    }
32
33 7
    public function apply(
34
        Transition $transition,
35
        State $fromState,
36
        State $toState
37
    ): void {
38 7
        $this->property->setValue($this->object, $toState->name());
39 7
    }
40
}
41