FreezableValueTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
getFrozenValue() 0 1 ?
setValue() 0 1 ?
computeValue() 0 1 ?
A performFreeze() 0 4 1
A performUnfreeze() 0 4 1
A getValue() 0 6 2
A freezeValue() 0 6 1
A unfreezeValue() 0 6 1
1
<?php
2
3
namespace Clippings\Freezable;
4
5
/**
6
 * @author    Haralan Dobrev <[email protected]>
7
 * @copyright 2014, Clippings Ltd.
8
 * @license   http://spdx.org/licenses/BSD-3-Clause
9
 */
10
trait FreezableValueTrait
11
{
12
    use FreezableTrait;
13
14
    /**
15
     * {@inheritdoc}
16
     */
17 1
    public function performFreeze()
18
    {
19 1
        $this->freezeValue();
20 1
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 1
    public function performUnfreeze()
26
    {
27 1
        $this->unfreezeValue();
28 1
    }
29
30
    /**
31
     * Get the value - either the frozen one or compute it dynamically
32
     *
33
     * @return mixed
34
     */
35 1
    public function getValue()
36
    {
37 1
        return $this->isFrozen()
38 1
            ? $this->getFrozenValue()
39 1
            : $this->computeValue();
40
    }
41
42
    /**
43
     * @return self
44
     */
45 1
    public function freezeValue()
46
    {
47 1
        $this->setValue($this->getValue());
48
49 1
        return $this;
50
    }
51
52
    /**
53
     * @return self
54
     */
55 1
    public function unfreezeValue()
56
    {
57 1
        $this->setValue(null);
58
59 1
        return $this;
60
    }
61
62
    /**
63
     * Get frozen value
64
     *
65
     * @return mixed
66
     */
67
    abstract public function getFrozenValue();
68
69
    /**
70
     * Set the frozen value
71
     *
72
     * @param mixed $value
73
     * @return self
74
     */
75
    abstract public function setValue($value);
76
77
    /**
78
     * Compute the value to be frozen
79
     *
80
     * @return mixed
81
     */
82
    abstract public function computeValue();
83
}
84