MemcachedMutex   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A acquire() 0 6 2
A release() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Mutex Library.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace AMF\Mutex\Adapter;
11
12
use AMF\Mutex\MutexInterface;
13
14
/**
15
 * Mutex for memcached.
16
 *
17
 * @author Amine Fattouch <[email protected]>
18
 */
19
class MemcachedMutex implements MutexInterface
20
{
21
    /**
22
     * @var \Memcached
23
     */
24
    protected $memcached;
25
26
    /**
27
     * Constructor class.
28
     *
29
     * @param \Memcached $memcached
30
     */
31
    public function __construct(\Memcached $memcached)
32
    {
33
        $this->memcached = $memcached;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function acquire($key, $ttl)
40
    {
41
        $acquired = $this->memcached->add($key, true, $ttl);
42
43
        return ($acquired === true) ? $key: null;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function release($key)
50
    {
51
        return $this->memcached->delete($key);
52
    }
53
}
54