GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

LockManager   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 68
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __destruct() 0 7 2
A acquire() 0 10 2
A release() 0 10 2
A getLockStore() 0 4 1
A prepareLockKey() 0 4 1
1
<?php
2
namespace Metaphore;
3
4
use Metaphore\Store\LockStoreInterface;
5
6
/**
7
 * Manages locks (acquiring and releasing).
8
 */
9
class LockManager
10
{
11
    /*** @var LockStoreInterface */
12
    protected $lockStore;
13
14
    /*** @var array */
15
    protected $acquiredLocks = [];
16
17
    /**
18
     * @param LockStoreInterface
19
     */
20
    public function __construct(LockStoreInterface $lockStore)
21
    {
22
        $this->lockStore = $lockStore;
23
    }
24
25
    public function __destruct()
26
    {
27
        // release locks that have been acquired but not released for some reason
28
        foreach ($this->acquiredLocks as $key => $true) {
29
            $this->release($key);
30
        }
31
    }
32
33
    /**
34
     * @param string
35
     * @param int
36
     * @return bool
37
     */
38
    public function acquire($key, $lockTtl)
39
    {
40
        $result = $this->lockStore->add($this->prepareLockKey($key), 1, $lockTtl);
41
42
        if ($result) {
43
            $this->acquiredLocks[$key] = true;
44
        }
45
46
        return $result;
47
    }
48
49
    /**
50
     * @param string
51
     * @return bool
52
     */
53
    public function release($key)
54
    {
55
        $result = $this->lockStore->delete($this->prepareLockKey($key));
56
57
        if (isset($this->acquiredLocks[$key])) {
58
            unset($this->acquiredLocks[$key]);
59
        }
60
61
        return $result;
62
    }
63
64
    /**
65
     * @return LockStoreInterface
66
     */
67
    public function getLockStore()
68
    {
69
        return $this->lockStore;
70
    }
71
72
    protected function prepareLockKey($key)
73
    {
74
        return sprintf('%s.lock', $key);
75
    }
76
}
77