RedisMutexFactory::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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