Skip to content

Commit adefaa2

Browse files
author
Babichev Maxim
committed
fix "Function lockProvider has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring"
1 parent 0383042 commit adefaa2

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/Services/LockService.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Bavix\Wallet\Objects\EmptyLock;
66
use Illuminate\Contracts\Cache\Lock;
77
use Illuminate\Contracts\Cache\LockProvider;
8+
use Illuminate\Contracts\Cache\Store;
89
use Illuminate\Database\Eloquent\Model;
910
use Illuminate\Support\Facades\Cache;
1011
use Illuminate\Support\Str;
@@ -51,6 +52,18 @@ protected function bindTo($self, \Closure $closure): \Closure
5152
}
5253
}
5354

55+
/**
56+
* @return Store|null
57+
*/
58+
protected function cache(): ?Store
59+
{
60+
try {
61+
return Cache::getStore();
62+
} catch (\Throwable $throwable) {
63+
return null;
64+
}
65+
}
66+
5467
/**
5568
* @param object $self
5669
* @param string $name
@@ -59,19 +72,8 @@ protected function bindTo($self, \Closure $closure): \Closure
5972
*/
6073
protected function lockProvider($self, string $name, int $seconds): Lock
6174
{
62-
try {
63-
/**
64-
* @var LockProvider $store
65-
*/
66-
$store = Cache::getStore();
67-
} catch (\Throwable $throwable) {
68-
// todo: write error's
69-
}
70-
71-
$enabled = false;
72-
if (isset($store)) {
73-
$enabled = config('wallet.lock.enabled', false);
74-
}
75+
$store = $this->cache();
76+
$enabled = $store && config('wallet.lock.enabled', false);
7577

7678
if ($enabled && $store instanceof LockProvider) {
7779
$class = \get_class($self);

0 commit comments

Comments
 (0)