Passed
Push — master ( 94b014...e2ddcf )
by Petr
07:02
created

XStorage::exists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 1
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 3
rs 10
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 write(string $sharedKey, $data, ?int $timeout = null): bool
27
    {
28
        if ('off' !== $sharedKey) {
29
            $this->storedData = $data;
30
            return true;
31
        } else {
32
            return false;
33
        }
34
    }
35
36
    public function read(string $sharedKey)
37
    {
38
        if ('off' !== $sharedKey) {
39
            return $this->storedData;
40
        } else {
41
            return 'mocked';
42
        }
43
    }
44
45
    public function remove(string $sharedKey): bool
46
    {
47
        $this->storedData = '';
48
        return 'off' !== $sharedKey;
49
    }
50
51
    public function exists(string $sharedKey): bool
52
    {
53
        return ('off' !== $sharedKey) ? !empty($this->storedData) : false;
54
    }
55
56
    public function lookup(string $mask): Traversable
57
    {
58
        yield from [];
59
    }
60
61
    public function increment(string $key): bool
62
    {
63
        return 'off' !== $key;
64
    }
65
66
    public function decrement(string $key): bool
67
    {
68
        return 'off' !== $key;
69
    }
70
71
    public function removeMulti(array $keys): array
72
    {
73
        return [];
74
    }
75
}
76