InitializationCallback::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 3
1
<?php
2
3
namespace Isolate\Framework\UnitOfWork\LazyObjects;
4
5
use Isolate\LazyObjects\Proxy\LazyProperty;
6
use Isolate\UnitOfWork\Object\PropertyAccessor;
7
use Isolate\LazyObjects\Proxy\LazyProperty\InitializationCallback as BaseCallback;
8
use Isolate\UnitOfWork\Object\SnapshotMaker;
9
10
final class InitializationCallback implements BaseCallback
11
{
12
    /**
13
     * @var PropertyAccessor
14
     */
15
    private $propertyAccessor;
16
17
    /**
18
     * @var
19
     */
20
    private $snapshot;
21
22
    /**
23
     * @var LazyProperty
24
     */
25
    private $lazyProperty;
26
27
    /**
28
     * @var SnapshotMaker
29
     */
30
    private $snapshotMaker;
31
32
    /**
33
     * @param SnapshotMaker $snapshotMaker
34
     * @param PropertyAccessor $propertyAccessor
35
     * @param LazyProperty $lazyProperty
36
     * @param $snapshot
37
     */
38
    public function __construct(SnapshotMaker $snapshotMaker, PropertyAccessor $propertyAccessor, LazyProperty $lazyProperty, $snapshot)
39
    {
40
        $this->propertyAccessor = $propertyAccessor;
41
        $this->lazyProperty = $lazyProperty;
42
        $this->snapshot = $snapshot;
43
        $this->snapshotMaker = $snapshotMaker;
44
    }
45
46
    /**
47
     * @param mixed $defaultValue
48
     * @param mixed $newValue
49
     * @param mixed $targetObject
50
     */
51
    public function execute($defaultValue, $newValue, $targetObject)
52
    {
53
        $newValueSnapshot = $this->snapshotMaker->makeSnapshotOf($newValue);
54
        $this->propertyAccessor->setValue($this->snapshot, (string) $this->lazyProperty->getName(), $newValueSnapshot);
55
    }
56
}
57