Completed
Push — 1.x ( b58125...978298 )
by Akihito
17s queued 12s
created

StorageRedisMemcachedModule::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 3
dl 0
loc 7
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\QueryRepository;
6
7
use BEAR\RepositoryModule\Annotation\EtagPool;
8
use Memcached;
9
use Psr\Cache\CacheItemPoolInterface;
10
use Ray\Di\AbstractModule;
11
use Ray\PsrCacheModule\Annotation\CacheNamespace;
12
use Ray\PsrCacheModule\Annotation\MemcacheConfig;
13
use Ray\PsrCacheModule\MemcachedProvider;
14
use Ray\PsrCacheModule\Psr6RedisModule;
15
use Symfony\Component\Cache\Adapter\MemcachedAdapter;
16
17
use function array_map;
18
use function explode;
19
20
/**
21
 * Bind redis to shared storage, Bind memcache to etag pool
22
 */
23
final class StorageRedisMemcachedModule extends AbstractModule
24
{
25
    /** @var string */
26
    private $redisServer;
27
28
    /** @var list<list<string>> */
0 ignored issues
show
Bug introduced by
The type BEAR\QueryRepository\list 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...
29
    private $memcacheServer;
30
31
    /**
32
     * @param string $redisServer 'localhost:6379' {host}:{port}
33
     */
34
    public function __construct(string $redisServer, string $memcacheServer, ?AbstractModule $module = null)
35
    {
36
        $this->redisServer = $redisServer;
37
        $this->memcacheServer = array_map(static function ($memcacheServer) {
0 ignored issues
show
Documentation Bug introduced by
It seems like array_map(function(...) ...(',', $memcacheServer)) of type array is incompatible with the declared type BEAR\QueryRepository\list of property $memcacheServer.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
38
            return explode(':', $memcacheServer);
39
        }, explode(',', $memcacheServer));
40
        parent::__construct($module);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    protected function configure(): void
47
    {
48
        $this->install(new Psr6RedisModule($this->redisServer));
49
        $this->bind(CacheItemPoolInterface::class)->annotatedWith(EtagPool::class)->toConstructor(MemcachedAdapter::class, [
50
            'namespace' => CacheNamespace::class,
51
        ]);
52
        $this->bind()->annotatedWith(MemcacheConfig::class)->toInstance($this->memcacheServer);
53
        $this->bind(Memcached::class)->toProvider(MemcachedProvider::class);
54
    }
55
}
56