Passed
Pull Request — main (#61)
by Sílvio
02:54
created

FlushHelper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A pathFor() 0 9 2
1
<?php
2
3
namespace Silviooosilva\CacheerPhp\Helpers;
4
5
/**
6
 * Class FlushHelper
7
 * Builds deterministic file paths for last-flush timestamps per store type.
8
 */
9
class FlushHelper
10
{
11
    /**
12
     * Returns a path to store a last-flush timestamp.
13
     * @param string $storeType e.g., 'redis' or 'db'
14
     * @param string $identifier e.g., namespace or table name
15
     * @return string
16
     */
17
    public static function pathFor(string $storeType, string $identifier): string
18
    {
19
        $root = EnvHelper::getRootPath();
20
        $dir = $root . DIRECTORY_SEPARATOR . 'CacheerPHP' . DIRECTORY_SEPARATOR . 'Flush';
21
        if (!is_dir($dir)) {
22
            @mkdir($dir, 0755, true);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for mkdir(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

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

22
            /** @scrutinizer ignore-unhandled */ @mkdir($dir, 0755, true);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
23
        }
24
        $safeId = preg_replace('/[^a-zA-Z0-9_-]+/', '_', $identifier);
25
        return $dir . DIRECTORY_SEPARATOR . $storeType . '_' . $safeId . '.time';
26
    }
27
}
28
29