RedisStorageAdapter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 36
ccs 0
cts 24
cp 0
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A read() 0 13 2
A delete() 0 3 1
A __construct() 0 4 1
A write() 0 3 1
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/redis-adapter project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\Redis\Storage;
10
11
use Daikon\ReadModel\Projection\ProjectionMap;
12
use Daikon\Redis\Connector\RedisConnector;
13
use Daikon\ReadModel\Storage\StorageAdapterInterface;
14
use Daikon\ReadModel\Storage\StorageResultInterface;
15
16
final class RedisStorageAdapter implements StorageAdapterInterface
17
{
18
    private RedisConnector $connector;
19
20
    private array $settings;
21
22
    public function __construct(RedisConnector $connector, array $settings = [])
23
    {
24
        $this->connector = $connector;
25
        $this->settings = $settings;
26
    }
27
28
    public function read(string $identifier): StorageResultInterface
29
    {
30
        $projections = [];
31
        //@todo handle errors
32
        $hashMap = $this->connector->getConnection()->hGetAll($identifier);
33
34
        if (!empty($hashMap)) {
35
            $projectionClass = $hashMap['@type'];
36
            $projections = [$projectionClass::fromNative($hashMap)];
37
        }
38
39
        return new RedisStorageResult(
40
            new ProjectionMap($projections)
41
        );
42
    }
43
44
    public function write(string $identifier, array $data): bool
45
    {
46
        return $this->connector->getConnection()->hMSet($identifier, $data);
47
    }
48
49
    public function delete(string $identifier): bool
50
    {
51
        return $this->connector->getConnection()->unlink($identifier);
0 ignored issues
show
Bug introduced by
The method unlink() does not exist on Redis. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        return $this->connector->getConnection()->/** @scrutinizer ignore-call */ unlink($identifier);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52
    }
53
}
54