Skip to content

Commit 2af317d

Browse files
committed
Apply StyleCI diff file;
1 parent 9a6b7ee commit 2af317d

1 file changed

Lines changed: 48 additions & 48 deletions

File tree

src/Models/Traits/RoleMethods.php

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,58 @@
22

33
namespace Hans\Sphinx\Models\Traits;
44

5-
use Illuminate\Support\Facades\Cache;
6-
use Throwable;
5+
use Illuminate\Support\Facades\Cache;
6+
use Throwable;
77

8-
trait RoleMethods
8+
trait RoleMethods
9+
{
10+
/**
11+
* @param int $id
12+
*
13+
* @return static
14+
*/
15+
public static function findAndCache(int $id): self
916
{
10-
/**
11-
* @param int $id
12-
*
13-
* @return static
14-
*/
15-
public static function findAndCache(int $id): self
16-
{
17-
return Cache::rememberForever(
18-
static::cacheKey($id),
19-
fn () => self::query()->findOrFail($id)
20-
);
21-
}
22-
23-
/**
24-
* @return int
25-
*/
26-
public function getVersion(): int
27-
{
28-
return $this->version ?: self::query()->findOrFail($this->id, ['id', 'version'])->version;
29-
}
17+
return Cache::rememberForever(
18+
static::cacheKey($id),
19+
fn () => self::query()->findOrFail($id)
20+
);
21+
}
3022

31-
/**
32-
* @return bool
33-
*/
34-
public function increaseVersion(): bool
35-
{
36-
try {
37-
$this->increment('version');
38-
$this->fill(['version' => $this->getVersion() + 1])->saveQuietly();
39-
Cache::forget(self::cacheKey($this->id));
40-
Cache::forever(self::cacheKey($this->id), $this);
41-
} catch (Throwable $e) {
42-
return false;
43-
}
23+
/**
24+
* @return int
25+
*/
26+
public function getVersion(): int
27+
{
28+
return $this->version ?: self::query()->findOrFail($this->id, ['id', 'version'])->version;
29+
}
4430

45-
return true;
31+
/**
32+
* @return bool
33+
*/
34+
public function increaseVersion(): bool
35+
{
36+
try {
37+
$this->increment('version');
38+
$this->fill(['version' => $this->getVersion() + 1])->saveQuietly();
39+
Cache::forget(self::cacheKey($this->id));
40+
Cache::forever(self::cacheKey($this->id), $this);
41+
} catch (Throwable $e) {
42+
return false;
4643
}
4744

48-
/**
49-
* Make the unique key for caching the instance.
50-
*
51-
* @param int $id
52-
*
53-
* @return string
54-
*/
55-
protected static function cacheKey(int $id): string
56-
{
57-
return "role_cache_$id";
58-
}
45+
return true;
46+
}
47+
48+
/**
49+
* Make the unique key for caching the instance.
50+
*
51+
* @param int $id
52+
*
53+
* @return string
54+
*/
55+
protected static function cacheKey(int $id): string
56+
{
57+
return "role_cache_$id";
5958
}
59+
}

0 commit comments

Comments
 (0)