Passed
Push — master ( f0915f...7925ec )
by Alexander
01:20
created

AllDependencies::isChanged()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

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