Passed
Push — master ( e2ddcf...f1d38c )
by Petr
07:04
created

XStorage   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 19
c 1
b 0
f 1
dl 0
loc 58
rs 10
wmc 12
1
<?php
2
3
use kalanis\kw_storage\Interfaces\IStorage;
4
use PHPUnit\Framework\TestCase;
5
6
7
/**
8
 * Class CommonTestClass
9
 * The structure for mocking and configuration seems so complicated, but it's necessary to let it be totally idiot-proof
10
 */
11
abstract class CommonTestClass extends TestCase
12
{
13
}
14
15
16
class XStorage implements IStorage
17
{
18
    /** @var string */
19
    protected $storedData = '';
20
21
    public function canUse(): bool
22
    {
23
        return true;
24
    }
25
26
    public function isFlat(): bool
27
    {
28
        return true;
29
    }
30
31
    public function write(string $sharedKey, $data, ?int $timeout = null): bool
32
    {
33
        if ('off' !== $sharedKey) {
34
            $this->storedData = $data;
35
            return true;
36
        } else {
37
            return false;
38
        }
39
    }
40
41
    public function read(string $sharedKey)
42
    {
43
        if ('off' !== $sharedKey) {
44
            return $this->storedData;
45
        } else {
46
            return 'mocked';
47
        }
48
    }
49
50
    public function remove(string $sharedKey): bool
51
    {
52
        $this->storedData = '';
53
        return 'off' !== $sharedKey;
54
    }
55
56
    public function exists(string $sharedKey): bool
57
    {
58
        return ('off' !== $sharedKey) ? !empty($this->storedData) : false;
59
    }
60
61
    public function lookup(string $mask): Traversable
62
    {
63
        yield from [];
64
    }
65
66
    public function increment(string $key): bool
67
    {
68
        return 'off' !== $key;
69
    }
70
71
    public function decrement(string $key): bool
72
    {
73
        return 'off' !== $key;
74
    }
75
76
    public function removeMulti(array $keys): array
77
    {
78
        return [];
79
    }
80
}
81