Passed
Pull Request — master (#30)
by Mostafa
11:18
created

DebounceRefresh   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handle() 0 9 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
13
class DebounceRefresh implements ShouldQueue
14
{
15
    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\Jobs\DebounceRefresh: $collectionClass, $id, $relations, $class, $keyBy
Loading history...
16
17
    public function __construct(
18
        public string     $key,
19
        public string     $token,
20
        public string     $model,
21
        public string $name,
22
    ) {}
23
24
25
    public function handle(): void
26
    {
27
        $latestToken = Cache::get($this->key);
28
29
        if ($latestToken !== $this->token) {
30
            return;
31
        }
32
33
        app($this->model)->cache()->update($this->name);
34
    }
35
}
36