RedisSimpleLockFactory::create()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
nc 1
nop 2
1
<?php
2
3
namespace TH\RedisLock;
4
5
use Predis\Client;
6
use Psr\Log\LoggerInterface;
7
use Psr\Log\NullLogger;
8
use TH\Lock\TtlFactory;
9
10
class RedisSimpleLockFactory implements TtlFactory
11
{
12
    private $client;
13
    private $defaultTtl;
14
    private $logger;
15
    private $ignoredSAPIs;
16
17
    public function __construct(Client $client, $defaultTtl = 10000, LoggerInterface $logger = null, array $ignoredSAPIs = [])
18
    {
19
        $this->client       = $client;
20
        $this->defaultTtl   = $defaultTtl;
21
        $this->logger       = $logger ?: new NullLogger;
22
        $this->ignoredSAPIs = $ignoredSAPIs;
23
    }
24
25
    /**
26
     * Create a new RedisSimpleLock
27
     *
28
     * @param string  $identifier the redis lock key
29
     * @param integer $ttl        lock time-to-live in milliseconds
30
     *
31
     * @return RedisSimpleLock
32
     */
33
    public function create($identifier, $ttl = null)
34
    {
35
        return new RedisSimpleLock($identifier, $this->client, $ttl ?: $this->defaultTtl, $this->logger, $this->ignoredSAPIs);
36
    }
37
}
38