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

AbstractLockAdapter::getLockLabel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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