LogCache::increment()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
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 Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Valkyrja\Cache\Contract\Cache as Contract;
19
use Valkyrja\Cache\Tagger\Contract\Tagger;
20
use Valkyrja\Cache\Tagger\Tagger as TagClass;
21
use Valkyrja\Log\Contract\Logger;
22
use Valkyrja\Type\BuiltIn\Support\Arr;
23
24
/**
25
 * Class LogCache.
26
 *
27
 * @author Melech Mizrachi
28
 */
29
class LogCache implements Contract
30
{
31
    /**
32
     * LogCache constructor.
33
     *
34
     * @param Logger $logger The logger service
35
     * @param string $prefix [optional] The prefix
36
     */
37
    public function __construct(
38
        protected Logger $logger,
39
        protected string $prefix = ''
40
    ) {
41
    }
42
43
    /**
44
     * @inheritDoc
45
     */
46
    #[Override]
47
    public function has(string $key): bool
48
    {
49
        $this->logger->info(self::class . " has: $key");
50
51
        return true;
52
    }
53
54
    /**
55
     * @inheritDoc
56
     */
57
    #[Override]
58
    public function get(string $key): string|null
59
    {
60
        $this->logger->info(self::class . " get: $key");
61
62
        return '';
63
    }
64
65
    /**
66
     * @inheritDoc
67
     *
68
     * @throws JsonException
69
     */
70
    #[Override]
71
    public function many(string ...$keys): array
72
    {
73
        $keysString = Arr::toString($keys);
74
75
        $this->logger->info(self::class . " many: $keysString");
76
77
        return [];
78
    }
79
80
    /**
81
     * @inheritDoc
82
     */
83
    #[Override]
84
    public function put(string $key, string $value, int $minutes): void
85
    {
86
        $this->logger->info(self::class . " put: $key, value $value, minutes $minutes");
87
    }
88
89
    /**
90
     * @inheritDoc
91
     *
92
     * @throws JsonException
93
     */
94
    #[Override]
95
    public function putMany(array $values, int $minutes): void
96
    {
97
        $valuesString = Arr::toString($values);
98
99
        $this->logger->info(self::class . " putMany: $valuesString, minutes $minutes");
100
    }
101
102
    /**
103
     * @inheritDoc
104
     */
105
    #[Override]
106
    public function increment(string $key, int $value = 1): int
107
    {
108
        $this->logger->info(self::class . " increment: $key, value $value");
109
110
        return $value;
111
    }
112
113
    /**
114
     * @inheritDoc
115
     */
116
    #[Override]
117
    public function decrement(string $key, int $value = 1): int
118
    {
119
        $this->logger->info(self::class . " decrement: $key, value $value");
120
121
        return $value;
122
    }
123
124
    /**
125
     * @inheritDoc
126
     */
127
    #[Override]
128
    public function forever(string $key, $value): void
129
    {
130
        $this->logger->info(self::class . " forever: $key, value $value");
131
    }
132
133
    /**
134
     * @inheritDoc
135
     */
136
    #[Override]
137
    public function forget(string $key): bool
138
    {
139
        $this->logger->info(self::class . " forget: $key");
140
141
        return true;
142
    }
143
144
    /**
145
     * @inheritDoc
146
     */
147
    #[Override]
148
    public function flush(): bool
149
    {
150
        $this->logger->info(self::class . ' flush');
151
152
        return true;
153
    }
154
155
    /**
156
     * @inheritDoc
157
     */
158
    #[Override]
159
    public function getPrefix(): string
160
    {
161
        return $this->prefix;
162
    }
163
164
    /**
165
     * @inheritDoc
166
     */
167
    #[Override]
168
    public function getTagger(string ...$tags): Tagger
169
    {
170
        return TagClass::make($this, ...$tags);
171
    }
172
173
    /**
174
     * Get key.
175
     *
176
     * @param string $key
177
     *
178
     * @return string
179
     */
180
    protected function getKey(string $key): string
181
    {
182
        return $this->getPrefix() . $key;
183
    }
184
}
185