Passed
Push — master ( 1efd90...6b1ebf )
by Melech
03:59
created

LogCache::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Valkyrja\Cache;
15
16
use JsonException;
17
use Valkyrja\Cache\Contract\Cache as Contract;
18
use Valkyrja\Cache\Tagger\Contract\Tagger;
19
use Valkyrja\Cache\Tagger\Tagger as TagClass;
20
use Valkyrja\Log\Contract\Logger;
21
use Valkyrja\Type\BuiltIn\Support\Arr;
22
23
/**
24
 * Class LogCache.
25
 *
26
 * @author Melech Mizrachi
27
 */
28
class LogCache implements Contract
29
{
30
    /**
31
     * LogCache constructor.
32
     *
33
     * @param Logger $logger The logger service
34
     * @param string $prefix [optional] The prefix
35
     */
36
    public function __construct(
37
        protected Logger $logger,
38
        protected string $prefix = ''
39
    ) {
40
    }
41
42
    /**
43
     * @inheritDoc
44
     */
45
    public function has(string $key): bool
46
    {
47
        $this->logger->info(self::class . " has: $key");
48
49
        return true;
50
    }
51
52
    /**
53
     * @inheritDoc
54
     */
55
    public function get(string $key): string|null
56
    {
57
        $this->logger->info(self::class . " get: $key");
58
59
        return '';
60
    }
61
62
    /**
63
     * @inheritDoc
64
     *
65
     * @throws JsonException
66
     */
67
    public function many(string ...$keys): array
68
    {
69
        $keysString = Arr::toString($keys);
70
71
        $this->logger->info(self::class . " many: $keysString");
72
73
        return [];
74
    }
75
76
    /**
77
     * @inheritDoc
78
     */
79
    public function put(string $key, string $value, int $minutes): void
80
    {
81
        $this->logger->info(self::class . " put: $key, value $value, minutes $minutes");
82
    }
83
84
    /**
85
     * @inheritDoc
86
     *
87
     * @throws JsonException
88
     */
89
    public function putMany(array $values, int $minutes): void
90
    {
91
        $valuesString = Arr::toString($values);
92
93
        $this->logger->info(self::class . " putMany: $valuesString, minutes $minutes");
94
    }
95
96
    /**
97
     * @inheritDoc
98
     */
99
    public function increment(string $key, int $value = 1): int
100
    {
101
        $this->logger->info(self::class . " increment: $key, value $value");
102
103
        return $value;
104
    }
105
106
    /**
107
     * @inheritDoc
108
     */
109
    public function decrement(string $key, int $value = 1): int
110
    {
111
        $this->logger->info(self::class . " decrement: $key, value $value");
112
113
        return $value;
114
    }
115
116
    /**
117
     * @inheritDoc
118
     */
119
    public function forever(string $key, $value): void
120
    {
121
        $this->logger->info(self::class . " forever: $key, value $value");
122
    }
123
124
    /**
125
     * @inheritDoc
126
     */
127
    public function forget(string $key): bool
128
    {
129
        $this->logger->info(self::class . " forget: $key");
130
131
        return true;
132
    }
133
134
    /**
135
     * @inheritDoc
136
     */
137
    public function flush(): bool
138
    {
139
        $this->logger->info(self::class . ' flush');
140
141
        return true;
142
    }
143
144
    /**
145
     * @inheritDoc
146
     */
147
    public function getPrefix(): string
148
    {
149
        return $this->prefix;
150
    }
151
152
    /**
153
     * @inheritDoc
154
     */
155
    public function getTagger(string ...$tags): Tagger
156
    {
157
        return TagClass::make($this, ...$tags);
158
    }
159
160
    /**
161
     * Get key.
162
     *
163
     * @param string $key
164
     *
165
     * @return string
166
     */
167
    protected function getKey(string $key): string
168
    {
169
        return $this->getPrefix() . $key;
170
    }
171
}
172