Passed
Push — master ( 13e2f1...aac75f )
by Stephen
01:01 queued 14s
created

PreCacheViewModel   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 52
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 6 1
A __construct() 0 5 1
1
<?php
2
3
namespace Sfneal\ViewModels;
4
5
use Sfneal\Queueables\AbstractJob;
6
7
class PreCacheViewModel extends AbstractJob
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 AbstractViewModel
21
     */
22
    private $viewModel;
23
24
    /**
25
     * @var string
26
     */
27
    private $route_name;
28
29
    /**
30
     * @var array
31
     */
32
    private $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 mixed
52
     */
53
    public function handle()
54
    {
55
        return $this->viewModel
56
            ->setRedisKey(route($this->route_name, $this->route_data))
57
            ->invalidateCache()
58
            ->render();
59
    }
60
}
61