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::acquire()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 2
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