CallbackDependency::generateDependencyData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 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