FileDependency::generateDependencyData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
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