Completed
Pull Request — master (#104)
by Бабичев
96:02
created

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