Completed
Push — master ( 8b74c1...befd33 )
by Clément
07:46 queued 04:00
created

CommandLockHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 5
c 3
b 0
f 1
lcom 1
cbo 2
dl 0
loc 52
ccs 17
cts 17
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isLocked() 0 6 1
A lock() 0 4 1
A release() 0 4 1
A setLockStatusForChannel() 0 6 1
1
<?php
2
3
namespace Itkg\DelayEventBundle\Handler;
4
5
use Itkg\DelayEventBundle\DomainManager\LockManagerInterface;
6
7
/**
8
 * Class CommandLockHandler
9
 */
10
class CommandLockHandler implements LockHandlerInterface
11
{
12
    /**
13
     * @var LockManagerInterface
14
     */
15
    private $lockManager;
16
17
    /**
18
     * @param LockManagerInterface $lockManager
19
     */
20 4
    public function __construct(LockManagerInterface $lockManager)
21
    {
22 4
        $this->lockManager = $lockManager;
23 4
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 1
    public function isLocked($channel)
29
    {
30 1
        $lock = $this->lockManager->getLock($channel);
31
32 1
        return $lock->isCommandLocked();
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 1
    public function lock($channel)
39
    {
40 1
        $this->setLockStatusForChannel($channel, true);
41 1
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 1
    public function release($channel)
47
    {
48 1
        $this->setLockStatusForChannel($channel, false);
49 1
    }
50
51
    /**
52
     * @param string $channel
53
     * @param bool   $locked
54
     */
55 2
    private function setLockStatusForChannel($channel, $locked)
56
    {
57 2
        $lock = $this->lockManager->getLock($channel);
58 2
        $lock->setCommandLocked($locked);
59 2
        $this->lockManager->save($lock);
60 2
    }
61
}
62