Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
24 / 24 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
Metadata | |
100.00% |
24 / 24 |
|
100.00% |
6 / 6 |
7 | |
100.00% |
1 / 1 |
blank | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
ofCachingMetadata | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
ofDependencyMetadata | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
merge | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
2 | |||
getCachingMetadata | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getDependencyMetadata | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Cache; |
4 | |
5 | use Wikimedia\Assert\Assert; |
6 | |
7 | /** |
8 | * Collection of information about a value. |
9 | * |
10 | * @author Lucas Werkmeister |
11 | * @license GPL-2.0-or-later |
12 | */ |
13 | class Metadata { |
14 | |
15 | /** |
16 | * @var CachingMetadata |
17 | */ |
18 | private $cachingMetadata; |
19 | |
20 | /** |
21 | * @var DependencyMetadata |
22 | */ |
23 | private $dependencyMetadata; |
24 | |
25 | /** |
26 | * @return self Empty collection. |
27 | */ |
28 | public static function blank() { |
29 | $ret = new self; |
30 | $ret->cachingMetadata = CachingMetadata::fresh(); |
31 | $ret->dependencyMetadata = DependencyMetadata::blank(); |
32 | return $ret; |
33 | } |
34 | |
35 | public static function ofCachingMetadata( CachingMetadata $cachingMetadata ) { |
36 | $ret = new self; |
37 | $ret->cachingMetadata = $cachingMetadata; |
38 | $ret->dependencyMetadata = DependencyMetadata::blank(); |
39 | return $ret; |
40 | } |
41 | |
42 | public static function ofDependencyMetadata( DependencyMetadata $dependencyMetadata ) { |
43 | $ret = new self; |
44 | $ret->cachingMetadata = CachingMetadata::fresh(); |
45 | $ret->dependencyMetadata = $dependencyMetadata; |
46 | return $ret; |
47 | } |
48 | |
49 | /** |
50 | * @param self[] $metadatas |
51 | * @return self |
52 | */ |
53 | public static function merge( array $metadatas ) { |
54 | Assert::parameterElementType( self::class, $metadatas, '$metadatas' ); |
55 | $cachingMetadatas = []; |
56 | $dependencyMetadatas = []; |
57 | foreach ( $metadatas as $metadata ) { |
58 | $cachingMetadatas[] = $metadata->cachingMetadata; |
59 | $dependencyMetadatas[] = $metadata->dependencyMetadata; |
60 | } |
61 | $ret = new self; |
62 | $ret->cachingMetadata = CachingMetadata::merge( $cachingMetadatas ); |
63 | $ret->dependencyMetadata = DependencyMetadata::merge( $dependencyMetadatas ); |
64 | return $ret; |
65 | } |
66 | |
67 | /** |
68 | * @return CachingMetadata |
69 | */ |
70 | public function getCachingMetadata() { |
71 | return $this->cachingMetadata; |
72 | } |
73 | |
74 | /** |
75 | * @return DependencyMetadata |
76 | */ |
77 | public function getDependencyMetadata() { |
78 | return $this->dependencyMetadata; |
79 | } |
80 | |
81 | } |