Total Complexity | 7 |
Total Lines | 68 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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 |
||
76 | // force lock release |
||
77 | } |
||
78 | |||
79 | } |
||
80 |