PreUpdateEventArgs   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 17
c 2
b 0
f 0
dl 0
loc 74
ccs 23
cts 23
cp 1
rs 10
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A setNewValue() 0 8 2
A getOldValue() 0 6 2
A getNewValue() 0 6 2
A hasChangedField() 0 3 1
A getObjectChangeSet() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\SkeletonMapper\Event;
6
7
use Doctrine\SkeletonMapper\ObjectManagerInterface;
8
use Doctrine\SkeletonMapper\UnitOfWork\Change;
9
use Doctrine\SkeletonMapper\UnitOfWork\ChangeSet;
10
11
/**
12
 * Class that holds event arguments for a preUpdate event.
13
 */
14
class PreUpdateEventArgs extends LifecycleEventArgs
15
{
16
    /** @var ChangeSet */
17
    private $objectChangeSet;
18
19
    /**
20
     * @param object $object
21
     */
22 18
    public function __construct(
23
        $object,
24
        ObjectManagerInterface $objectManager,
25
        ChangeSet $changeSet
26
    ) {
27 18
        parent::__construct($object, $objectManager);
28 18
        $this->objectChangeSet = $changeSet;
29 18
    }
30
31
    /**
32
     * Retrieves the object changeset.
33
     */
34 1
    public function getObjectChangeSet() : ChangeSet
35
    {
36 1
        return $this->objectChangeSet;
37
    }
38
39
    /**
40
     * Checks if field has a changeset.
41
     */
42 1
    public function hasChangedField(string $field) : bool
43
    {
44 1
        return $this->objectChangeSet->hasChangedField($field);
45
    }
46
47
    /**
48
     * Gets the old value of the changeset of the changed field.
49
     *
50
     * @return mixed
51
     */
52 2
    public function getOldValue(string $field)
53
    {
54 2
        $change = $this->objectChangeSet->getFieldChange($field);
55
56 2
        if ($change !== null) {
57 1
            return $change->getOldValue();
58
        }
59 1
    }
60
61
    /**
62
     * Gets the new value of the changeset of the changed field.
63
     *
64
     * @return mixed
65
     */
66 3
    public function getNewValue(string $field)
67
    {
68 3
        $change = $this->objectChangeSet->getFieldChange($field);
69
70 3
        if ($change !== null) {
71 2
            return $change->getNewValue();
72
        }
73 1
    }
74
75
    /**
76
     * Sets the new value of this field.
77
     *
78
     * @param mixed $value
79
     */
80 2
    public function setNewValue(string $field, $value) : void
81
    {
82 2
        $change = $this->objectChangeSet->getFieldChange($field);
83
84 2
        if ($change !== null) {
85 1
            $change->setNewValue($value);
86
        } else {
87 1
            $this->objectChangeSet->addChange(new Change($field, null, $value));
88
        }
89 2
    }
90
}
91