CallbackDependency   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A generateDependencyData() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Cache\Dependency;
6
7
use Yiisoft\Cache\CacheInterface;
8
9
/**
10
 * CallbackDependency represents a dependency based on the result of a callback.
11
 *
12
 * The dependency is reported as unchanged if and only if the result of the callback is
13
 * the same as the one evaluated when storing the data to cache.
14
 */
15
final class CallbackDependency extends Dependency
16
{
17
    private $callback;
18
19 5
    public function __construct(callable $callback)
20
    {
21 5
        $this->callback = $callback;
22
    }
23
24 5
    protected function generateDependencyData(CacheInterface $cache): mixed
25
    {
26 5
        return ($this->callback)($cache);
27
    }
28
}
29