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