RedisSimpleLockFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A create() 0 4 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