Passed
Pull Request — master (#83)
by Бабичев
10:10
created

EmptyLock::owner()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
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
    /**
12
     * @var string
13
     */
14
    protected $ownerId;
15
16
    /**
17
     * Attempt to acquire the lock.
18
     *
19
     * @param  callable|null  $callback
20
     * @return mixed
21
     */
22 55
    public function get($callback = null)
23
    {
24 55
        if ($callback === null) {
25 1
            return null;
26
        }
27
28 55
        return $callback();
29
    }
30
31
    /**
32
     * Attempt to acquire the lock for the given number of seconds.
33
     *
34
     * @param  int  $seconds
35
     * @param  callable|null  $callback
36
     * @return bool
37
     */
38 1
    public function block($seconds, $callback = null): bool
39
    {
40 1
        return true;
41
    }
42
43
    /**
44
     * Release the lock.
45
     *
46
     * @return void
47
     * @codeCoverageIgnore
48
     */
49
    public function release(): void
50
    {
51
        // lock release
52
    }
53
54
    /**
55
     * Returns the current owner of the lock.
56
     *
57
     * @return string
58
     */
59 1
    public function owner(): string
60
    {
61 1
        if (!$this->ownerId) {
62 1
            $this->ownerId = Str::random();
63
        }
64
65 1
        return $this->ownerId;
66
    }
67
68
    /**
69
     * Releases this lock in disregard of ownership.
70
     *
71
     * @return void
72
     * @codeCoverageIgnore
73
     */
74
    public function forceRelease(): void
75
    {
76
        // force lock release
77
    }
78
79
}
80