Passed
Push — master ( eac3f8...2377e1 )
by Alexander
01:46
created

FileDependency   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A generateDependencyData() 0 4 1
1
<?php
2
namespace Yiisoft\Cache\Dependency;
3
4
use Yiisoft\Cache\CacheInterface;
5
use Yiisoft\Cache\Exception\InvalidConfigException;
6
7
/**
8
 * FileDependency represents a dependency based on a file's last modification time.
9
 *
10
 * If the last modification time of the file specified via {@see fileName} is changed,
11
 * the dependency is considered as changed.
12
 *
13
 * For more details and usage information on Cache, see the [guide article on caching](guide:caching-overview).
14
 */
15
final class FileDependency extends Dependency
16
{
17
    private $fileName;
18
19
    /**
20
     * @param string $fileName the file path or [path alias](guide:concept-aliases) whose last modification time is used to
21
     * check if the dependency has been changed.
22
     */
23 1
    public function __construct(string $fileName)
24
    {
25 1
        $this->fileName = $fileName;
26
    }
27
28
    /**
29
     * Generates the data needed to determine if dependency has been changed.
30
     * This method returns the file's last modification time.
31
     * @param CacheInterface $cache the cache component that is currently evaluating this dependency
32
     * @return mixed the data needed to determine if dependency has been changed.
33
     * @throws InvalidConfigException if {@see fileName} is not set
34
     */
35 1
    protected function generateDependencyData(CacheInterface $cache)
36
    {
37 1
        clearstatcache(false, $this->fileName);
38 1
        return @filemtime($this->fileName);
39
    }
40
}
41