Passed
Pull Request — master (#43)
by
unknown
05:16
created

AnyDependency::generateDependencyData()   A

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