RedisMutexFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 6
dl 0
loc 18
ccs 5
cts 5
cp 1
rs 10
c 1
b 0
f 1
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Mutex\Redis;
6
7
use Predis\ClientInterface;
8
use Yiisoft\Mutex\MutexFactory;
9
use Yiisoft\Mutex\MutexInterface;
10
11
/**
12
 * Allows creating {@see RedisMutex} mutex objects.
13
 */
14
final class RedisMutexFactory extends MutexFactory
15
{
16
    private ClientInterface $client;
17
    private int $ttl;
18
19
    /**
20
     * @param ClientInterface $client Predis client instance to use.
21
     * @param int $ttl Number of seconds in which the lock will be auto released.
22
     */
23 1
    public function __construct(ClientInterface $client, int $ttl = 30)
24
    {
25 1
        $this->client = $client;
26 1
        $this->ttl = $ttl;
27
    }
28
29 1
    public function create(string $name): MutexInterface
30
    {
31 1
        return new RedisMutex($name, $this->client, $this->ttl);
32
    }
33
}
34