Skip to content

Commit 5ece5e5

Browse files
committed
Coding standards
1 parent 80b83ee commit 5ece5e5

File tree

2 files changed

+18
-28
lines changed

2 files changed

+18
-28
lines changed

src/RepositoryServiceProvider.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ public function boot()
1717
$this->mergeConfigFrom(
1818
__DIR__ . '/../config/repositories.php', 'repositories'
1919
);
20-
21-
// Get caching
22-
AbstractRepository::setCacheInstance($this->app['cache']);
2320
}
2421

2522
/**
@@ -31,7 +28,7 @@ public function register()
3128
{
3229
if ($this->isLumen() === false) {
3330
$this->publishes([
34-
__DIR__ . '/../config/repositories.php' => config_path('repositories.php')
31+
__DIR__ . '/../config/repositories.php' => config_path('repositories.php'),
3532
], 'config');
3633
}
3734
}
@@ -45,4 +42,4 @@ protected function isLumen()
4542
{
4643
return str_contains($this->app->version(), 'Lumen') === true;
4744
}
48-
}
45+
}

src/Traits/Cacheable.php

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,24 @@
99

1010
trait Cacheable
1111
{
12-
/**
13-
* Cache instance
14-
*
15-
* @var CacheManager
16-
*/
17-
protected static $cache = null;
12+
protected static CacheManager|null $cache = null;
1813

1914
/**
2015
* Flush the cache after create/update/delete events.
21-
*
22-
* @var bool
2316
*/
24-
protected $eventFlushCache = false;
17+
protected bool $eventFlushCache = false;
2518

2619
/**
2720
* Global lifetime of the cache.
28-
*
29-
* @var int
3021
*/
31-
protected $cacheMinutes = 60;
22+
protected int $cacheMinutes = 60;
3223

3324
/**
3425
* Set cache manager.
3526
*
3627
* @param CacheManager $cache
28+
*
29+
* @return void
3730
*/
3831
public static function setCacheInstance(CacheManager $cache)
3932
{
@@ -68,13 +61,13 @@ public function skippedCache()
6861
/**
6962
* Get Cache key for the method
7063
*
71-
* @param string $method
72-
* @param mixed $args
73-
* @param string $tag
64+
* @param string $method
65+
* @param array|null $args
66+
* @param string $tag
7467
*
7568
* @return string
7669
*/
77-
public function getCacheKey($method, $args = null, $tag = '')
70+
public function getCacheKey(string $method, array $args = null, string $tag = ''): string
7871
{
7972
// Sort through arguments
8073
foreach ($args as &$a) {
@@ -100,12 +93,12 @@ public function getCacheKey($method, $args = null, $tag = '')
10093
*
10194
* @param string $method
10295
* @param array $args
103-
* @param \Closure $callback
104-
* @param int $time
96+
* @param Closure $callback
97+
* @param int|null $time
10598
*
10699
* @return mixed
107100
*/
108-
public function cacheCallback($method, $args, Closure $callback, $time = null)
101+
public function cacheCallback(string $method, array $args, Closure $callback, int $time = null)
109102
{
110103
// Cache disabled, just execute query & return result
111104
if ($this->skippedCache() === true) {
@@ -127,7 +120,7 @@ public function cacheCallback($method, $args, Closure $callback, $time = null)
127120
*
128121
* @return bool
129122
*/
130-
public function flushCache()
123+
public function flushCache(): bool
131124
{
132125
// Cache disabled, just ignore this
133126
if ($this->eventFlushCache === false || config('repositories.cache_enabled', false) === false) {
@@ -143,11 +136,11 @@ public function flushCache()
143136
/**
144137
* Return the time until expires in minutes.
145138
*
146-
* @param int $time
139+
* @param mixed $time
147140
*
148141
* @return int
149142
*/
150-
protected function getCacheExpiresTime($time = null)
143+
protected function getCacheExpiresTime(mixed $time = null): int
151144
{
152145
if ($time === self::EXPIRES_END_OF_DAY) {
153146
return class_exists(Carbon::class)
@@ -157,4 +150,4 @@ protected function getCacheExpiresTime($time = null)
157150

158151
return $time ?: $this->cacheMinutes;
159152
}
160-
}
153+
}

0 commit comments

Comments
 (0)