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

CommandLockHandler::setLockStatusForChannel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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