EmptyLock   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 67
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A forceRelease() 0 2 1
A block() 0 3 1
A release() 0 2 1
A get() 0 7 2
A owner() 0 7 2
1
<?php
2
3
namespace Bavix\Wallet\Objects;
4
5
use Illuminate\Contracts\Cache\Lock;
6
use Illuminate\Support\Str;
7
8
class EmptyLock implements Lock
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $ownerId;
14
15
    /**
16
     * Attempt to acquire the lock.
17
     *
18
     * @param callable|null $callback
19
     * @return mixed
20
     */
21 96
    public function get($callback = null)
22
    {
23 96
        if ($callback === null) {
24 1
            return null;
25
        }
26
27 96
        return $callback();
28
    }
29
30
    /**
31
     * Attempt to acquire the lock for the given number of seconds.
32
     *
33
     * @param int $seconds
34
     * @param callable|null $callback
35
     * @return bool
36
     */
37 1
    public function block($seconds, $callback = null): bool
38
    {
39 1
        return true;
40
    }
41
42
    /**
43
     * Release the lock.
44
     *
45
     * @return void
46
     * @codeCoverageIgnore
47
     */
48
    public function release(): void
49
    {
50
        // lock release
51
    }
52
53
    /**
54
     * Returns the current owner of the lock.
55
     *
56
     * @return string
57
     */
58 1
    public function owner(): string
59
    {
60 1
        if (! $this->ownerId) {
61 1
            $this->ownerId = Str::random();
62
        }
63
64 1
        return $this->ownerId;
65
    }
66
67
    /**
68
     * Releases this lock in disregard of ownership.
69
     *
70
     * @return void
71
     * @codeCoverageIgnore
72
     */
73
    public function forceRelease(): void
74
    {
75
        // force lock release
76
    }
77
}
78