Completed
Push — master ( 28797f...652832 )
by Alexander
01:44
created

ExpressionDependency   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 6
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A generateDependencyData() 0 3 1
1
<?php
2
namespace Yiisoft\Cache\Dependency;
3
4
use Yiisoft\Cache\CacheInterface;
5
6
/**
7
 * ExpressionDependency represents a dependency based on the result of a PHP expression.
8
 *
9
 * ExpressionDependency will use `eval()` to evaluate the PHP expression.
10
 * The dependency is reported as unchanged if and only if the result of the expression is
11
 * the same as the one evaluated when storing the data to cache.
12
 *
13
 * A PHP expression can be any PHP code that has a value. To learn more about what an expression is,
14
 * please refer to the [php manual](http://www.php.net/manual/en/language.expressions.php).
15
 *
16
 * For more details and usage information on Cache, see the [guide article on caching](guide:caching-overview).
17
 */
18
final class ExpressionDependency extends Dependency
19
{
20
    /**
21
     * @var string the string representation of a PHP expression whose result is used to determine the dependency.
22
     * A PHP expression can be any PHP code that evaluates to a value. To learn more about what an expression is,
23
     * please refer to the [php manual](http://www.php.net/manual/en/language.expressions.php).
24
     */
25
    private $expression;
26
    /**
27
     * @var mixed custom parameters associated with this dependency. You may get the value
28
     * of this property in {@see expression} using `$this->params`.
29
     */
30
    private $params;
31
32
    /**
33
     * @param string $expression the string representation of a PHP expression whose result is used to determine the dependency.
34
     * A PHP expression can be any PHP code that evaluates to a value. To learn more about what an expression is,
35
     * please refer to the [php manual](http://www.php.net/manual/en/language.expressions.php).
36
     * @param mixed $params custom parameters associated with this dependency. You may get the value
37
     * of this property in {@see expression} using `$this->params`.
38
     */
39
    public function __construct(string $expression, mixed $params = null)
0 ignored issues
show
Bug introduced by
The type Yiisoft\Cache\Dependency\mixed was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
40
    {
41
        $this->expression = $expression;
42
        $this->params = $params;
43
    }
44
45
    /**
46
     * Generates the data needed to determine if dependency has been changed.
47
     * This method returns the result of the PHP expression.
48
     * @param CacheInterface $cache the cache component that is currently evaluating this dependency
49
     * @return mixed the data needed to determine if dependency has been changed.
50
     */
51
    protected function generateDependencyData(CacheInterface $cache)
52
    {
53
        return eval("return {$this->expression};");
0 ignored issues
show
introduced by
The use of eval() is discouraged.
Loading history...
54
    }
55
}
56