Completed
Push — master ( 74f1fd...158e39 )
by Alexander
01:41
created

AnyDependency::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
2
3
namespace Yiisoft\Cache\Dependency;
4
5
use Yiisoft\Cache\CacheInterface;
6
7
/**
8
 * AnyDependency represents a dependency based on the result of a callback.
9
 *
10
 * The dependency is reported as changed if any sub-dependency is changed.
11
 *
12
 * For more details and usage information on Cache, see the [guide article on caching](guide:caching-overview).
13
 */
14
class AnyDependency extends Dependency
15
{
16
    /**
17
         * @var Dependency[]
18
         */
19
        private $dependencies;
20
21
        /**
22
         * ChainedDependency constructor.
23
         * @param Dependency[] $dependencies list of dependencies that this dependency is composed of.
24
         * Each array element must be a dependency object.
25
         */
26 1
        public function __construct(array $dependencies = [])
27
        {
28 1
            $this->dependencies = $dependencies;
29
        }
30
31 1
        public function evaluateDependency(CacheInterface $cache): void
32
        {
33 1
            foreach ($this->dependencies as $dependency) {
34 1
                $dependency->evaluateDependency($cache);
35
            }
36
        }
37
38
        protected function generateDependencyData(CacheInterface $cache)
39
        {
40
            return null;
41
        }
42
43 1
        public function isChanged(CacheInterface $cache): bool
44
        {
45 1
            foreach ($this->dependencies as $dependency) {
46 1
                if ($dependency->isChanged($cache)) {
47 1
                    return true;
48
                }
49
            }
50
51 1
            return false;
52
        }
53
}
54