Completed
Push — master ( 83bd2d...9517e2 )
by Arne
03:10
created

AbstractLockAdapter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 35
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hasLock() 0 4 1
A __destruct() 0 4 1
A releaseAcquiredLocks() 0 9 2
A getLockLabel() 0 7 1
1
<?php
2
3
namespace Archivr\LockAdapter;
4
5
abstract class AbstractLockAdapter implements LockAdapterInterface
6
{
7
    /**
8
     * @var string[]
9
     */
10
    protected $acquiredLocks = [];
11
12
    public function hasLock(string $name): bool
13
    {
14
        return in_array($name, $this->acquiredLocks);
15
    }
16
17
    public function __destruct()
18
    {
19
        $this->releaseAcquiredLocks();
20
    }
21
22
    protected function releaseAcquiredLocks()
23
    {
24
        foreach ($this->acquiredLocks as $acquiredLock)
25
        {
26
            $this->releaseLock($acquiredLock);
27
        }
28
29
        $this->acquiredLocks = [];
30
    }
31
32
    protected function getLockLabel(): string
33
    {
34
        return json_encode([
35
            'acquired' => time(),
36
            'user' => get_current_user()
37
        ]);
38
    }
39
}
40