NinjaMutexLockAdapter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 51
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A acquireLock() 0 4 1
A releaseLock() 0 4 1
A isLocked() 0 4 1
1
<?php
2
3
namespace Metabor\Adapter;
4
5
use MetaborStd\Semaphore\LockAdapterInterface;
6
use NinjaMutex\Lock\LockInterface;
7
8
/**
9
 * @author Oliver Tischlinger
10
 */
11
class NinjaMutexLockAdapter implements LockAdapterInterface
12
{
13
    /**
14
     * @var LockInterface
15
     */
16
    private $ninjaMutexLock;
17
18
    /**
19
     * @var null|int
20
     */
21
    private $timeout;
22
23
    /**
24
     * @param LockInterface $ninjaMutexLock
25
     * @param  null|int $timeout 1. null if you want blocking lock
26
     *                           2. 0 if you want just lock and go
27
     *                           3. $timeout > 0 if you want to wait for lock some time (in milliseconds)
28
     */
29
    public function __construct(LockInterface $ninjaMutexLock, $timeout = null)
30
    {
31
        $this->ninjaMutexLock = $ninjaMutexLock;
32
        $this->timeout = $timeout;
33
    }
34
35
    /**
36
     * @param string $resourceName
37
     * @return bool
38
     */
39
    public function acquireLock($resourceName)
40
    {
41
        return $this->ninjaMutexLock->acquireLock($resourceName, $this->timeout);
42
    }
43
44
    /**
45
     * @param string $resourceName
46
     * @return bool
47
     */
48
    public function releaseLock($resourceName)
49
    {
50
        return $this->ninjaMutexLock->releaseLock($resourceName);
51
    }
52
53
    /**
54
     * @param string $resourceName
55
     * @return bool
56
     */
57
    public function isLocked($resourceName)
58
    {
59
        return $this->ninjaMutexLock->isLocked($resourceName);
60
    }
61
}
62