Passed
Push — master ( 708ccf...fe543b )
by Stephen
01:05 queued 12s
created

CachingPreferences::dontCacheInDevelopment()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Sfneal\ViewModels\Traits;
4
5
use Sfneal\Helpers\Laravel\AppInfo;
6
7
trait CachingPreferences
8
{
9
    /**
10
     * @var bool Determine if caching has been disabled.
11
     */
12
    protected $cachingDisabled = false;
13
14
    /**
15
     * Disable ViewModel render caching if the conditional evaluates as true.
16
     *
17
     * @param  bool  $conditional
18
     * @return $this
19
     */
20
    public function dontCacheIf(bool $conditional): self
21
    {
22
        if ($conditional) {
23
            $this->cachingDisabled = true;
24
        }
25
26
        return $this;
27
    }
28
29
    /**
30
     * Disable ViewModel render caching if the app environment is 'development'.
31
     *
32
     * @return $this
33
     */
34
    public function dontCacheInDevelopment(): self
35
    {
36
        if (AppInfo::isEnvDevelopment()) {
37
            $this->cachingDisabled = true;
38
        }
39
40
        return $this;
41
    }
42
43
    /**
44
     * Disable ViewModel render caching if the app environment is 'production'.
45
     *
46
     * @return $this
47
     */
48
    public function dontCacheInProduction(): self
49
    {
50
        if (AppInfo::isEnvProduction()) {
51
            $this->cachingDisabled = true;
52
        }
53
54
        return $this;
55
    }
56
}
57