InMemoryClient   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 16
c 1
b 0
f 0
dl 0
loc 57
ccs 0
cts 23
cp 0
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A commit() 0 3 1
A deleteItem() 0 7 2
A deleteItems() 0 5 1
A clear() 0 5 1
A save() 0 5 1
A saveDeferred() 0 3 1
A getItem() 0 3 1
A hasItem() 0 3 1
A getItems() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Crossword\Infrastructure\Cache;
6
7
use Psr\Cache\CacheItemInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Cache\CacheItemInterface 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...
8
use Psr\Cache\CacheItemPoolInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Cache\CacheItemPoolInterface 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...
9
10
final class InMemoryClient implements CacheItemPoolInterface
11
{
12
    private array $items;
13
14
    public function getItem(string $key): CacheItemInterface
15
    {
16
        return new CacheItem($key, $this->items[$key]);
17
    }
18
19
    public function getItems(array $keys = []): array
20
    {
21
        return array_map(static fn (string $key): CacheItemInterface => $this->getItem($key), $keys);
22
    }
23
24
    public function hasItem(string $key): bool
25
    {
26
        return $this->getItem($key)->isHit();
27
    }
28
29
    public function clear(): bool
30
    {
31
        $this->items = [];
32
33
        return true;
34
    }
35
36
    public function deleteItem(string $key): bool
37
    {
38
        if (in_array($key, $this->items, true)) {
39
            unset($this->items[$key]);
40
        }
41
42
        return true;
43
    }
44
45
    public function deleteItems(array $keys): bool
46
    {
47
        array_map(static fn (string $key): bool => $this->deleteItem($key), $keys);
48
49
        return true;
50
    }
51
52
    public function save(CacheItemInterface $item): bool
53
    {
54
        $this->items[$item->getKey()] = $item->get();
55
56
        return true;
57
    }
58
59
    public function saveDeferred(CacheItemInterface $item): bool
60
    {
61
        return $this->save($item);
62
    }
63
64
    public function commit(): bool
65
    {
66
        return true;
67
    }
68
}
69