FileDependency::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 0
c 0
b 0
f 0
dl 0
loc 2
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Cache\Dependency;
6
7
use Yiisoft\Cache\CacheInterface;
8
9
use function clearstatcache;
10
use function filemtime;
11
12
/**
13
 * FileDependency represents a dependency based on a file's last modification time.
14
 *
15
 * If the last modification time of the file specified via {@see FileDependency::$fileName} is changed,
16
 * the dependency is considered as changed.
17
 */
18
final class FileDependency extends Dependency
19
{
20
    /**
21
     * @param string $fileName The file path whose last modification time is used to
22
     * check if the dependency has been changed.
23
     */
24
    public function __construct(private string $fileName)
25
    {
26 2
    }
27
28 2
    protected function generateDependencyData(CacheInterface $cache): false|int
29
    {
30
        clearstatcache(false, $this->fileName);
31
        return @filemtime($this->fileName);
32
    }
33
}
34