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

ProxyService   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
eloc 12
dl 0
loc 85
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

9 Methods

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