Passed
Push — master ( 652acd...8b321d )
by Mostafa
13:28 queued 10:29
created

UpdateLaraCacheModelsList   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 12
c 1
b 0
f 0
dl 0
loc 24
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 8 1
A __construct() 0 4 2
1
<?php
2
3
namespace Mostafaznv\LaraCache\Jobs;
4
5
use Illuminate\Bus\Queueable;
6
use Illuminate\Contracts\Queue\ShouldQueue;
7
use Illuminate\Foundation\Bus\Dispatchable;
8
use Illuminate\Queue\InteractsWithQueue;
9
use Illuminate\Queue\SerializesModels;
10
use Illuminate\Support\Facades\Cache;
11
12
class UpdateLaraCacheModelsList implements ShouldQueue
13
{
14
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
0 ignored issues
show
introduced by
The trait Illuminate\Queue\SerializesModels requires some properties which are not provided by Mostafaznv\LaraCache\Job...dateLaraCacheModelsList: $collectionClass, $id, $relations, $class, $keyBy
Loading history...
15
16
    private string $driver;
17
    private string $key;
18
19
    public const LARACACHE_MODELS_LIST = 'laracache.models';
20
21
    public function __construct(private string $model)
22
    {
23
        $this->driver = config('laracache.driver') ?: config('cache.default');
24
        $this->key = self::LARACACHE_MODELS_LIST;
25
    }
26
27
28
    public function handle(): void
29
    {
30
        $list = Cache::driver($this->driver)->get($this->key, []);
31
        $list[] = $this->model;
32
33
        Cache::driver($this->driver)->forever(
34
            key: 'laracache.models',
35
            value: array_unique($list)
36
        );
37
    }
38
}
39