Memory::locked()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * Stores in memory
4
 * User: moyo
5
 * Date: 18/10/2017
6
 * Time: 3:32 PM
7
 */
8
9
namespace Carno\Config\Chips\Stores;
10
11
trait Memory
12
{
13
    /**
14
     * @var array
15
     */
16
    private $data = [];
17
18
    /**
19
     * @var array
20
     */
21
    private $protected = [];
22
23
    /**
24
     * @var array
25
     */
26
    private $replicated = [];
27
28
    /**
29
     * @param string $key
30
     * @return bool
31
     */
32
    protected function locked(string $key) : bool
33
    {
34
        return isset($this->protected[$key]);
35
    }
36
37
    /**
38
     * @param string $key
39
     * @param mixed $value
40
     */
41
    protected function replica(string $key, $value) : void
42
    {
43
        if (is_null($value)) {
44
            unset($this->replicated[$key]);
45
        } else {
46
            $this->replicated[$key] = $value;
47
        }
48
    }
49
50
    /**
51
     * @param string $key
52
     * @param mixed $value
53
     * @param bool $replica
54
     */
55
    protected function reset(string $key, $value, bool $replica = false) : void
56
    {
57
        if (is_null($value)) {
58
            if (isset($this->replicated[$key])) {
59
                $this->data[$key] = $value = $this->replicated[$key];
60
            } else {
61
                unset($this->data[$key]);
62
            }
63
            unset($this->protected[$key]);
64
        } else {
65
            $this->data[$key] = $value;
66
            $replica || $this->protected[$key] = true;
67
        }
68
69
        $this->wkChanged($key, $value);
0 ignored issues
show
Bug introduced by
It seems like wkChanged() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
        $this->/** @scrutinizer ignore-call */ 
70
               wkChanged($key, $value);
Loading history...
70
    }
71
}
72