99
1010trait 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