FileDependency   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 2
c 1
b 0
f 0
dl 0
loc 14
ccs 2
cts 2
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A generateDependencyData() 0 4 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