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

ProxyService::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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