Completed
Pull Request — master (#40)
by Бабичев
04:27
created

ProxyService::remove()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Bavix\Wallet\Services;
4
5
class ProxyService implements \ArrayAccess
6
{
7
8
    /**
9
     * @var array
10
     */
11
    protected $data = [];
12
13
    /**
14
     * @param string $key
15
     * @return bool
16
     */
17 38
    public function has(string $key): bool
18
    {
19 38
        return $this->offsetExists($key);
20
    }
21
22
    /**
23
     * @inheritDoc
24
     */
25 38
    public function offsetExists($offset): bool
26
    {
27 38
        return \array_key_exists($offset, $this->data);
28
    }
29
30
    /**
31
     * @param string $key
32
     * @return int
33
     */
34 28
    public function get(string $key): int
35
    {
36 28
        return $this->offsetGet($key);
37
    }
38
39
    /**
40
     * @inheritDoc
41
     */
42 38
    public function offsetGet($offset): int
43
    {
44 38
        return $this->data[$offset] ?? 0;
45
    }
46
47
    /**
48
     * @param string $key
49
     * @param int $value
50
     * @return static
51
     */
52 38
    public function set(string $key, int $value): self
53
    {
54 38
        $this->offsetSet($key, $value);
55 38
        return $this;
56
    }
57
58
    /**
59
     * @inheritDoc
60
     */
61 38
    public function offsetSet($offset, $value): void
62
    {
63 38
        $this->data[$offset] = $value;
64 38
    }
65
66
    /**
67
     * @param string $key
68
     * @return static
69
     */
70
    public function remove(string $key): self
71
    {
72
        $this->offsetUnset($key);
73
        return $this;
74
    }
75
76
    /**
77
     * @inheritDoc
78
     */
79
    public function offsetUnset($offset): void
80
    {
81
        unset($this->data[$offset]);
82
    }
83
84
    /**
85
     * @return void
86
     */
87 40
    public function fresh(): void
88
    {
89 40
        $this->data = [];
90 40
    }
91
92
}
93