NinjaMutexLockAdapter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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