AllDependencies::generateDependencyData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Cache\Dependency;
6
7
use Yiisoft\Cache\CacheInterface;
8
use Yiisoft\Cache\Exception\InvalidArgumentException;
9
10
use function sprintf;
11
12
/**
13
 * AllDependencies represents a dependency which is composed of a list of other dependencies.
14
 *
15
 * The dependency is reported as changed if all sub-dependencies are changed.
16
 */
17
final class AllDependencies extends Dependency
18
{
19
    /**
20
     * @var Dependency[]
21
     */
22
    private array $dependencies;
23
24
    /**
25
     * @param Dependency[] $dependencies list of dependencies that this dependency is composed of.
26
     * Each array element must be a dependency object.
27
     *
28
     * @psalm-suppress DocblockTypeContradiction, RedundantConditionGivenDocblockType
29
     */
30 9
    public function __construct(array $dependencies = [])
31
    {
32 9
        foreach ($dependencies as $dependency) {
33 9
            if (!($dependency instanceof Dependency)) {
34 8
                throw new InvalidArgumentException(sprintf(
35
                    'The dependency must be a "%s" instance, "%s" received',
36
                    Dependency::class,
37 8
                    get_debug_type($dependency),
38
                ));
39
            }
40
        }
41
42 1
        $this->dependencies = $dependencies;
43
    }
44
45 1
    public function evaluateDependency(CacheInterface $cache): void
46
    {
47 1
        foreach ($this->dependencies as $dependency) {
48 1
            $dependency->evaluateDependency($cache);
49
        }
50
    }
51
52
    /**
53
     * @codeCoverageIgnore Method is not used.
54
     */
55
    protected function generateDependencyData(CacheInterface $cache): mixed
56
    {
57
        return null;
58
    }
59
60 1
    public function isChanged(CacheInterface $cache): bool
61
    {
62 1
        foreach ($this->dependencies as $dependency) {
63 1
            if (!$dependency->isChanged($cache)) {
64 1
                return false;
65
            }
66
        }
67
68 1
        return true;
69
    }
70
}
71