Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
CachingConstraintLookup | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
queryConstraintsForProperty | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace WikibaseQuality\ConstraintReport; |
4 | |
5 | use Wikibase\DataModel\Entity\NumericPropertyId; |
6 | |
7 | /** |
8 | * A ConstraintLookup that caches the results of another lookup in memory |
9 | * (by storing the constraint array per property ID in a big array). |
10 | * |
11 | * @author Lucas Werkmeister |
12 | * @license GPL-2.0-or-later |
13 | */ |
14 | class CachingConstraintLookup implements ConstraintLookup { |
15 | |
16 | /** |
17 | * @var ConstraintLookup |
18 | */ |
19 | private $lookup; |
20 | |
21 | /** |
22 | * @var Constraint[][] |
23 | */ |
24 | private $cache = []; |
25 | |
26 | /** |
27 | * @param ConstraintLookup $lookup The lookup to which all queries are delegated. |
28 | */ |
29 | public function __construct( ConstraintLookup $lookup ) { |
30 | $this->lookup = $lookup; |
31 | } |
32 | |
33 | /** |
34 | * @param NumericPropertyId $propertyId |
35 | * |
36 | * @return Constraint[] |
37 | */ |
38 | public function queryConstraintsForProperty( NumericPropertyId $propertyId ) { |
39 | $id = $propertyId->getSerialization(); |
40 | if ( !array_key_exists( $id, $this->cache ) ) { |
41 | $this->cache[$id] = $this->lookup->queryConstraintsForProperty( $propertyId ); |
42 | } |
43 | return $this->cache[$id]; |
44 | } |
45 | |
46 | } |