UpdateLaraCacheModelsList   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 8 1
A __construct() 0 7 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
        $this->connection = config('laracache.queue.connection', config('queue.default'));
27
        $this->queue = config('laracache.queue.name', 'default');
28
    }
29
30
31
    public function handle(): void
32
    {
33
        $list = Cache::driver($this->driver)->get($this->key, []);
34
        $list[] = $this->model;
35
36
        Cache::driver($this->driver)->forever(
37
            key: 'laracache.models',
38
            value: array_unique($list)
39
        );
40
    }
41
}
42