PreCacheViewModel::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Sfneal\ViewModels;
4
5
use Sfneal\Queueables\Job;
6
7
class PreCacheViewModel extends Job
8
{
9
    /**
10
     * @var int Number of seconds to delay dispatching by
11
     */
12
    public $delay = 30;
13
14
    /**
15
     * @var string Queue to use
16
     */
17
    public $queue = 'cache';
18
19
    /**
20
     * @var ViewModel
21
     */
22
    private ViewModel $viewModel;
23
24
    /**
25
     * @var string
26
     */
27
    private string $route_name;
28
29
    /**
30
     * @var array|null
31
     */
32
    private ?array $route_data;
33
34
    /**
35
     * PreCacheViewModel constructor.
36
     *
37
     * @param  $viewModel
38
     * @param  string  $route_name
39
     * @param  array|null  $route_data
40
     */
41
    public function __construct($viewModel, string $route_name, array $route_data = null)
42
    {
43
        $this->viewModel = $viewModel;
44
        $this->route_name = $route_name;
45
        $this->route_data = $route_data;
46
    }
47
48
    /**
49
     * Send a GuzzleHttp get request (intended for pre-caching a views).
50
     *
51
     * @return string
52
     */
53
    public function handle(): string
54
    {
55
        return $this->viewModel
56
            ->setRedisKey(route($this->route_name, $this->route_data))
57
            ->invalidateCache()
58
            ->render();
59
    }
60
}
61