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

CallbackDependency   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
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 13
rs 10
ccs 5
cts 5
cp 1

2 Methods

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