Completed
Push — master ( 56dae8...2928d3 )
by Бабичев
12:38 queued 05:37
created

ProxyService::offsetExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 42
    public function has(string $key): bool
21
    {
22 42
        return $this->offsetExists($key);
23
    }
24
25
    /**
26
     * @inheritDoc
27
     */
28 42
    public function offsetExists($offset): bool
29
    {
30 42
        return array_key_exists($offset, $this->data);
31
    }
32
33
    /**
34
     * @param string $key
35
     * @return int
36
     */
37 32
    public function get(string $key): int
38
    {
39 32
        return $this->offsetGet($key);
40
    }
41
42
    /**
43
     * @inheritDoc
44
     */
45 43
    public function offsetGet($offset): int
46
    {
47 43
        return $this->data[$offset] ?? 0;
48
    }
49
50
    /**
51
     * @param string $key
52
     * @param int $value
53
     * @return static
54
     */
55 42
    public function set(string $key, int $value): self
56
    {
57 42
        $this->offsetSet($key, $value);
58 42
        return $this;
59
    }
60
61
    /**
62
     * @inheritDoc
63
     */
64 43
    public function offsetSet($offset, $value): void
65
    {
66 43
        $this->data[$offset] = $value;
67 43
    }
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 45
    public function fresh(): void
91
    {
92 45
        $this->data = [];
93 45
    }
94
95
}
96