Passed
Push — master ( c82647...c877fa )
by Georges
11:01
created

IOConfigurationOption::getCacheSlamsTimeout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 *
5
 * This file is part of Phpfastcache.
6
 *
7
 * @license MIT License (MIT)
8
 *
9
 * For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files.
10
 *
11
 * @author Georges.L (Geolim4)  <[email protected]>
12
 * @author Contributors  https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
13
 */
14
15
declare(strict_types=1);
16
17
namespace Phpfastcache\Config;
18
19
use Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException;
20
use Phpfastcache\Exceptions\PhpfastcacheLogicException;
21
22
/**
23
 * @todo: As of V10, imports cache slams properties.
24
 */
25
class IOConfigurationOption extends ConfigurationOption
26
{
27
    protected bool $secureFileManipulation = false;
28
29
    protected string $securityKey = '';
30
31
    protected string $cacheFileExtension = 'txt';
32
33
    protected int $defaultChmod = 0777;
34
35
    /**
36
     * @return string
37
     */
38
    public function getSecurityKey(): string
39
    {
40
        return $this->securityKey;
41
    }
42
43
    /**
44
     * @param string $securityKey
45
     * @return static
46
     * @throws PhpfastcacheLogicException
47
     */
48
    public function setSecurityKey(string $securityKey): static
49
    {
50
        return $this->setProperty('securityKey', $securityKey);
51
    }
52
53
    /**
54
     * @return bool
55
     */
56
    public function isSecureFileManipulation(): bool
57
    {
58
        return $this->secureFileManipulation;
59
    }
60
61
    /**
62
     * @param bool $secureFileManipulation
63
     * @return static
64
     * @throws PhpfastcacheLogicException
65
     */
66
    public function setSecureFileManipulation(bool $secureFileManipulation): static
67
    {
68
        return $this->setProperty('secureFileManipulation', $secureFileManipulation);
69
    }
70
71
72
    /**
73
     * @return string
74
     */
75
    public function getCacheFileExtension(): string
76
    {
77
        return $this->cacheFileExtension;
78
    }
79
80
    /**
81
     * @param string $cacheFileExtension
82
     * @return static
83
     * @throws PhpfastcacheInvalidConfigurationException
84
     * @throws PhpfastcacheLogicException
85
     */
86
    public function setCacheFileExtension(string $cacheFileExtension): static
87
    {
88
        $safeFileExtensions = \explode('|', IOConfigurationOptionInterface::SAFE_FILE_EXTENSIONS);
89
90
        if (\str_contains($cacheFileExtension, '.')) {
91
            throw new PhpfastcacheInvalidConfigurationException('cacheFileExtension cannot contain a dot "."');
92
        }
93
        if (!\in_array($cacheFileExtension, $safeFileExtensions, true)) {
94
            throw new PhpfastcacheInvalidConfigurationException(
95
                "Extension \"$cacheFileExtension\" is unsafe, currently allowed extension names: " . \implode(', ', $safeFileExtensions)
96
            );
97
        }
98
99
        return $this->setProperty('cacheFileExtension', $cacheFileExtension);
100
    }
101
102
    /**
103
     * @return int
104
     */
105
    public function getDefaultChmod(): int
106
    {
107
        return $this->defaultChmod;
108
    }
109
110
    /**
111
     * @param int $defaultChmod
112
     * @return static
113
     * @throws PhpfastcacheLogicException
114
     */
115
    public function setDefaultChmod(int $defaultChmod): static
116
    {
117
        return $this->setProperty('defaultChmod', $defaultChmod);
118
    }
119
120
121
    /**
122
     * @return bool
123
     */
124
    public function isPreventCacheSlams(): bool
125
    {
126
        return $this->preventCacheSlams;
127
    }
128
129
    /**
130
     * @param bool $preventCacheSlams
131
     * @return static
132
     * @throws PhpfastcacheLogicException
133
     */
134
    public function setPreventCacheSlams(bool $preventCacheSlams): static
135
    {
136
        return $this->setProperty('preventCacheSlams', $preventCacheSlams);
137
    }
138
139
    /**
140
     * @return int
141
     */
142
    public function getCacheSlamsTimeout(): int
143
    {
144
        return $this->cacheSlamsTimeout;
145
    }
146
147
    /**
148
     * @param int $cacheSlamsTimeout
149
     * @return static
150
     * @throws PhpfastcacheLogicException
151
     */
152
    public function setCacheSlamsTimeout(int $cacheSlamsTimeout): static
153
    {
154
        return $this->setProperty('cacheSlamsTimeout', $cacheSlamsTimeout);
155
    }
156
}
157