Passed
Push — v9 ( e6f9d3...0a233b )
by Georges
02:05
created

IOConfigurationOptionTrait::getDefaultChmod()   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
declare(strict_types=1);
15
16
namespace Phpfastcache\Config;
17
18
use Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException;
19
use Phpfastcache\Exceptions\PhpfastcacheLogicException;
20
21
trait IOConfigurationOptionTrait
22
{
23
    protected bool $secureFileManipulation = false;
24
25
    protected string $securityKey = '';
26
27
    protected string $cacheFileExtension = 'txt';
28
29
    protected int $defaultChmod = 0777;
30
31
    /**
32
     * @return string
33
     */
34
    public function getSecurityKey(): string
35
    {
36
        return $this->securityKey;
37
    }
38
39
    /**
40
     * @param string $securityKey
41
     * @return static
42
     * @throws PhpfastcacheLogicException
43
     */
44
    public function setSecurityKey(string $securityKey): static
45
    {
46
        $this->enforceLockedProperty(__FUNCTION__);
0 ignored issues
show
Bug introduced by
It seems like enforceLockedProperty() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
        $this->/** @scrutinizer ignore-call */ 
47
               enforceLockedProperty(__FUNCTION__);
Loading history...
47
        $this->securityKey = $securityKey;
48
49
        return $this;
50
    }
51
52
    /**
53
     * @return bool
54
     */
55
    public function isSecureFileManipulation(): bool
56
    {
57
        return $this->secureFileManipulation;
58
    }
59
60
    /**
61
     * @param bool $secureFileManipulation
62
     * @return self
63
     * @throws PhpfastcacheLogicException
64
     */
65
    public function setSecureFileManipulation(bool $secureFileManipulation): static
66
    {
67
        $this->enforceLockedProperty(__FUNCTION__);
68
        $this->secureFileManipulation = $secureFileManipulation;
69
        return $this;
70
    }
71
72
73
    /**
74
     * @return string
75
     */
76
    public function getCacheFileExtension(): string
77
    {
78
        return $this->cacheFileExtension;
79
    }
80
81
    /**
82
     * @param string $cacheFileExtension
83
     * @return static
84
     * @throws PhpfastcacheInvalidConfigurationException
85
     * @throws PhpfastcacheLogicException
86
     */
87
    public function setCacheFileExtension(string $cacheFileExtension): static
88
    {
89
        $this->enforceLockedProperty(__FUNCTION__);
90
        $safeFileExtensions = \explode('|', IOConfigurationOptionInterface::SAFE_FILE_EXTENSIONS);
91
92
        if (str_contains($cacheFileExtension, '.')) {
93
            throw new PhpfastcacheInvalidConfigurationException('cacheFileExtension cannot contain a dot "."');
94
        }
95
        if (!\in_array($cacheFileExtension, $safeFileExtensions, true)) {
96
            throw new PhpfastcacheInvalidConfigurationException(
97
                "Extension \"$cacheFileExtension\" is not safe, currently allowed extension names: " . \implode(', ', $safeFileExtensions)
98
            );
99
        }
100
101
        $this->cacheFileExtension = $cacheFileExtension;
102
        return $this;
103
    }
104
105
    /**
106
     * @return int
107
     */
108
    public function getDefaultChmod(): int
109
    {
110
        return $this->defaultChmod;
111
    }
112
113
    /**
114
     * @param int $defaultChmod
115
     * @return self
116
     * @throws PhpfastcacheLogicException
117
     */
118
    public function setDefaultChmod(int $defaultChmod): static
119
    {
120
        $this->enforceLockedProperty(__FUNCTION__);
121
        $this->defaultChmod = $defaultChmod;
122
        return $this;
123
    }
124
}
125