Issues (902)

framework/caching/FileDependency.php (2 issues)

Labels
Severity
1
<?php
2
/**
3
 * @link https://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license https://www.yiiframework.com/license/
6
 */
7
8
namespace yii\caching;
9
10
use Yii;
11
use yii\base\InvalidConfigException;
12
13
/**
14
 * FileDependency represents a dependency based on a file's last modification time.
15
 *
16
 * If the last modification time of the file specified via [[fileName]] is changed,
17
 * the dependency is considered as changed.
18
 *
19
 * For more details and usage information on Cache, see the [guide article on caching](guide:caching-overview).
20
 *
21
 * @author Qiang Xue <[email protected]>
22
 * @since 2.0
23
 */
24
class FileDependency extends Dependency
25
{
26
    /**
27
     * @var string the file path or [path alias](guide:concept-aliases) whose last modification time is used to
28
     * check if the dependency has been changed.
29
     */
30
    public $fileName;
31
32
33
    /**
34
     * Generates the data needed to determine if dependency has been changed.
35
     * This method returns the file's last modification time.
36
     * @param CacheInterface $cache the cache component that is currently evaluating this dependency
37
     * @return mixed the data needed to determine if dependency has been changed.
38
     * @throws InvalidConfigException if [[fileName]] is not set
39
     */
40
    protected function generateDependencyData($cache)
41
    {
42
        if ($this->fileName === null) {
43
            throw new InvalidConfigException('FileDependency::fileName must be set');
44
        }
45
46
        $fileName = Yii::getAlias($this->fileName);
47
48
        clearstatcache(false, $fileName);
0 ignored issues
show
It seems like $fileName can also be of type false; however, parameter $filename of clearstatcache() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

48
        clearstatcache(false, /** @scrutinizer ignore-type */ $fileName);
Loading history...
49
        return @filemtime($fileName);
0 ignored issues
show
It seems like $fileName can also be of type false; however, parameter $filename of filemtime() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

49
        return @filemtime(/** @scrutinizer ignore-type */ $fileName);
Loading history...
50
    }
51
}
52