Passed
Push — main ( bce8dd...f4f8ca )
by Sílvio
56s
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
 * 
8
 * @author Sílvio Silva <https://github.com/silviooosilva>
9
 * @package Silviooosilva\CacheerPhp
10
 * 
11
 * Builds deterministic file paths for last-flush timestamps per store type.
12
 */
13
class FlushHelper
14
{
15
    /**
16
     * Returns a path to store a last-flush timestamp.
17
     * @param string $storeType e.g., 'redis' or 'db'
18
     * @param string $identifier e.g., namespace or table name
19
     * @return string
20
     */
21
    public static function pathFor(string $storeType, string $identifier): string
22
    {
23
        $root = EnvHelper::getRootPath();
24
        $dir = $root . DIRECTORY_SEPARATOR . 'CacheerPHP' . DIRECTORY_SEPARATOR . 'Flush';
25
        if (!is_dir($dir)) {
26
            @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

26
            /** @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...
27
        }
28
        $safeId = preg_replace('/[^a-zA-Z0-9_-]+/', '_', $identifier);
29
        return $dir . DIRECTORY_SEPARATOR . $storeType . '_' . $safeId . '.time';
30
    }
31
}
32
33