Completed
Push — master ( 9d89b4...9742ac )
by Alexander
01:48
created

CallbackDependency::generateDependencyData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
ccs 3
cts 3
cp 1
cc 1
nc 1
nop 1
crap 1
1
<?php
2
namespace Yiisoft\Cache\Dependency;
3
4
use Yiisoft\Cache\CacheInterface;
5
6
/**
7
 * CallbackDependency represents a dependency based on the result of a callback.
8
 *
9
 * The dependency is reported as unchanged if and only if the result of the callback is
10
 * the same as the one evaluated when storing the data to cache.
11
 *
12
 * For more details and usage information on Cache, see the [guide article on caching](guide:caching-overview).
13
 */
14
class CallbackDependency extends Dependency
15
{
16
    private $callback;
17
18 2
    public function __construct(callable $callback)
19
    {
20 2
        $this->callback = $callback;
21
    }
22
23 2
    protected function generateDependencyData(CacheInterface $cache)
24
    {
25 2
        $callback = $this->callback;
26 2
        return $callback();
27
    }
28
}
29