Passed
Push — main ( a6366b...47f44b )
by Dimitri
11:49
created

FileVarExportHandler::clearGroup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * This file is part of Blitz PHP framework.
5
 *
6
 * (c) 2022 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace BlitzPHP\Cache\Handlers;
13
14
use DateInterval;
15
16
final class FileVarExportHandler extends BaseHandler
17
{
18
	private string $path = FRAMEWORK_STORAGE_PATH . 'cache';
0 ignored issues
show
Bug introduced by
The constant BlitzPHP\Cache\Handlers\FRAMEWORK_STORAGE_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
19
20
    /**
21
     * {@inheritDoc}
22
     */
23
    public function isSupported(): bool
24
    {
25
        return true;
26
    }
27
28
    /**
29
     * {@inheritDoc}
30
     */
31
    public function init(array $config = []): bool
32
    {
33
        return true;
34
    }
35
36
    /**
37
     * {@inheritDoc}
38
	 *
39
	 * @param array|bool|float|int|object|string|null $value
40
     */
41
    public function set(string $key, mixed $value, null|DateInterval|int $ttl = null): bool
42
    {
43
        $value = var_export($value, true);
44
45
        // Écrire d'abord dans le fichier temporaire pour assurer l'atomicité
46
        $tmp = $this->path . "/{$key}." . uniqid('', true) . '.tmp';
47
        file_put_contents($tmp, '<?php return ' . $value . ';', LOCK_EX);
48
49
        return rename($tmp, $this->path . "/{$key}");
50
    }
51
52
    /**
53
     * {@inheritDoc}
54
     */
55
    public function setMultiple(iterable $values, null|DateInterval|int $ttl = null): bool
56
    {
57
        return true;
58
    }
59
60
    /**
61
     * {@inheritDoc}
62
	 *
63
	 * @return array|bool|float|int|object|string|null
64
     */
65
    public function get(string $key, mixed $default = null): mixed
66
    {
67
		return @include $this->path . "/{$key}";
68
	}
69
70
    /**
71
     * {@inheritDoc}
72
     */
73
    public function getMultiple(iterable $keys, mixed $default = null): iterable
74
    {
75
        return [];
76
    }
77
78
    /**
79
     * {@inheritDoc}
80
     */
81
    public function increment(string $key, int $offset = 1)
82
    {
83
        return 1;
84
    }
85
86
    /**
87
     * {@inheritDoc}
88
     */
89
    public function decrement(string $key, int $offset = 1)
90
    {
91
        return 0;
92
    }
93
94
    /**
95
     * {@inheritDoc}
96
     */
97
    public function delete(string $key): bool
98
    {
99
		return @unlink($this->path . "/{$key}");
100
    }
101
102
    /**
103
     * {@inheritDoc}
104
     */
105
    public function deleteMultiple(iterable $keys): bool
106
    {
107
        return true;
108
    }
109
110
    /**
111
     * {@inheritDoc}
112
     */
113
    public function clear(): bool
114
    {
115
		if (! is_dir($this->path)) {
116
			return false;
117
		}
118
119
		$files = glob($this->path . '/*');
120
		foreach ($files as $file) {
121
			if (is_file($file)) {
122
				unlink($file);
123
			} elseif (is_dir($file)) {
124
				$this->clear($file);
0 ignored issues
show
Unused Code introduced by
The call to BlitzPHP\Cache\Handlers\...rExportHandler::clear() has too many arguments starting with $file. ( Ignorable by Annotation )

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

124
				$this->/** @scrutinizer ignore-call */ 
125
           clear($file);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
125
			}
126
		}
127
128
		return rmdir($this->path);
129
	}
130
131
    /**
132
     * {@inheritDoc}
133
     */
134
    public function clearGroup(string $group): bool
135
    {
136
        return true;
137
    }
138
}
139