1 | <?php |
||
25 | class EntityRetrievingClosestReferencedEntityIdLookup implements ReferencedEntityIdLookup { |
||
26 | |||
27 | /** |
||
28 | * @var EntityLookup |
||
29 | */ |
||
30 | private $entityLookup; |
||
31 | |||
32 | /** |
||
33 | * @var EntityPrefetcher |
||
34 | */ |
||
35 | private $entityPrefetcher; |
||
36 | |||
37 | /** |
||
38 | * @var int Maximum search depth: Maximum number of intermediate entities to search through. |
||
39 | * For example 0 means that only the entities immediately referenced will be found. |
||
40 | */ |
||
41 | private $maxDepth; |
||
42 | |||
43 | /** |
||
44 | * @var int Maximum number of entities to retrieve. |
||
45 | */ |
||
46 | private $maxEntityVisits; |
||
47 | |||
48 | /** |
||
49 | * Map (entity id => true) of already visited entities. |
||
50 | * |
||
51 | * @var bool[] |
||
52 | */ |
||
53 | private $alreadyVisited = []; |
||
54 | |||
55 | /** |
||
56 | * @param EntityLookup $entityLookup |
||
57 | * @param EntityPrefetcher $entityPrefetcher |
||
58 | * @param int $maxDepth Maximum search depth: Maximum number of intermediate entities to search through. |
||
59 | * For example if 0 is given, only the entities immediately referenced will be found. |
||
60 | * If this limit gets exhausted, a MaxReferenceDepthExhaustedException is thrown. |
||
61 | * @param int $maxEntityVisits Maximum number of entities to retrieve during a lookup. |
||
62 | * If this limit gets exhausted, a MaxReferencedEntityVisitsExhaustedException is thrown. |
||
63 | */ |
||
64 | public function __construct( |
||
75 | |||
76 | /** |
||
77 | * Get the closest entity (out of $toIds), from a given entity. The starting entity, and |
||
78 | * the target entities are (potentially indirectly, via intermediate entities) linked by |
||
79 | * statements with the given property ID, pointing from the starting entity to one of the |
||
80 | * target entities. |
||
81 | * |
||
82 | * @since 3.10 |
||
83 | * |
||
84 | * @param EntityId $fromId |
||
85 | * @param PropertyId $propertyId |
||
86 | * @param EntityId[] $toIds |
||
87 | * |
||
88 | * @return EntityId|null Returns null in case none of the target entities are referenced. |
||
89 | * @throws ReferencedEntityIdLookupException |
||
90 | */ |
||
91 | public function getReferencedEntityId( EntityId $fromId, PropertyId $propertyId, array $toIds ) { |
||
129 | |||
130 | /** |
||
131 | * Find out whether an entity (directly) references one of the target ids. |
||
132 | * |
||
133 | * @param EntityId $id Id of the entity to process |
||
134 | * @param EntityId $fromId Id this lookup started from |
||
135 | * @param PropertyId $propertyId |
||
136 | * @param EntityId[] $toIds |
||
137 | * @param EntityId[] &$toVisit List of entities that still need to be checked |
||
138 | * @return EntityId|null Target id the entity refers to, null if none. |
||
139 | */ |
||
140 | private function processEntityById( |
||
163 | |||
164 | /** |
||
165 | * @param EntityId $id Id of the entity to get |
||
166 | * @param EntityId $fromId Id this lookup started from |
||
167 | * @param PropertyId $propertyId |
||
168 | * @param EntityId[] $toIds |
||
169 | * |
||
170 | * @return StatementListProvider|null Null if not applicable. |
||
171 | */ |
||
172 | private function getEntity( EntityId $id, EntityId $fromId, PropertyId $propertyId, array $toIds ) { |
||
205 | |||
206 | /** |
||
207 | * Decide whether a single Snak is pointing to one of the target ids. |
||
208 | * |
||
209 | * @param Snak $snak |
||
210 | * @param EntityId[] &$toVisit List of entities that still need to be checked |
||
211 | * @param EntityId[] $toIds |
||
212 | * @return EntityId|null Target id the Snak refers to, null if none. |
||
213 | */ |
||
214 | private function processSnak( Snak $snak, array &$toVisit, array $toIds ) { |
||
232 | |||
233 | /** |
||
234 | * @param StatementListProvider $statementListProvider |
||
235 | * @param PropertyId $propertyId |
||
236 | * @return Snak[] |
||
237 | */ |
||
238 | private function getMainSnaks( |
||
248 | |||
249 | } |
||
250 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.