1 | <?php |
||
73 | class ConstraintReportFactory { |
||
74 | |||
75 | // services created by this factory |
||
76 | |||
77 | /** |
||
78 | * @var DelegatingConstraintChecker|null |
||
79 | */ |
||
80 | private $delegatingConstraintChecker; |
||
81 | |||
82 | /** |
||
83 | * @var ConstraintChecker[]|null |
||
84 | */ |
||
85 | private $constraintCheckerMap; |
||
86 | |||
87 | /** |
||
88 | * @var ConstraintRepository|null |
||
89 | */ |
||
90 | private $constraintRepository; |
||
91 | |||
92 | /** |
||
93 | * @var LoggingHelper|null |
||
94 | */ |
||
95 | private $loggingHelper; |
||
96 | |||
97 | /** |
||
98 | * @var CheckResultSerializer|null |
||
99 | */ |
||
100 | private $checkResultSerializer; |
||
101 | |||
102 | /** |
||
103 | * @var CheckResultDeserializer|null |
||
104 | */ |
||
105 | private $checkResultDeserializer; |
||
106 | |||
107 | /** |
||
108 | * @var WikiPageEntityMetaDataAccessor|null |
||
109 | */ |
||
110 | private $wikiPageEntityMetaDataAccessor; |
||
111 | |||
112 | /** |
||
113 | * @var ResultsSource|null |
||
114 | */ |
||
115 | private $resultsSource; |
||
116 | |||
117 | // services used by this factory |
||
118 | |||
119 | /** |
||
120 | * @var EntityLookup |
||
121 | */ |
||
122 | private $lookup; |
||
123 | |||
124 | /** |
||
125 | * @var PropertyDataTypeLookup |
||
126 | */ |
||
127 | private $propertyDataTypeLookup; |
||
128 | |||
129 | /** |
||
130 | * @var StatementGuidParser |
||
131 | */ |
||
132 | private $statementGuidParser; |
||
133 | |||
134 | /** |
||
135 | * @var Config |
||
136 | */ |
||
137 | private $config; |
||
138 | |||
139 | /** |
||
140 | * @var ConstraintParameterParser |
||
141 | */ |
||
142 | private $constraintParameterParser; |
||
143 | |||
144 | /** |
||
145 | * @var ViolationMessageSerializer |
||
146 | */ |
||
147 | private $violationMessageSerializer; |
||
148 | |||
149 | /** |
||
150 | * @var ViolationMessageDeserializer |
||
151 | */ |
||
152 | private $violationMessageDeserializer; |
||
153 | |||
154 | /** |
||
155 | * @var RdfVocabulary |
||
156 | */ |
||
157 | private $rdfVocabulary; |
||
158 | |||
159 | /** |
||
160 | * @var EntityIdParser |
||
161 | */ |
||
162 | private $entityIdParser; |
||
163 | |||
164 | /** |
||
165 | * @var TitleParser |
||
166 | */ |
||
167 | private $titleParser; |
||
168 | |||
169 | /** |
||
170 | * @var UnitConverter|null |
||
171 | */ |
||
172 | private $unitConverter; |
||
173 | |||
174 | /** |
||
175 | * @var DataValueFactory |
||
176 | */ |
||
177 | private $dataValueFactory; |
||
178 | |||
179 | /** |
||
180 | * @var EntityNamespaceLookup |
||
181 | */ |
||
182 | private $entityNamespaceLookup; |
||
183 | |||
184 | /** |
||
185 | * @var IBufferingStatsdDataFactory |
||
186 | */ |
||
187 | private $dataFactory; |
||
188 | |||
189 | /** |
||
190 | * Returns the default instance. |
||
191 | * IMPORTANT: Use only when it is not feasible to inject an instance properly. |
||
192 | * |
||
193 | * @return self |
||
194 | */ |
||
195 | public static function getDefaultInstance() { |
||
196 | static $instance = null; |
||
197 | |||
198 | if ( $instance === null ) { |
||
199 | $wikibaseRepo = WikibaseRepo::getDefaultInstance(); |
||
200 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
||
201 | $titleParser = MediaWikiServices::getInstance()->getTitleParser(); |
||
202 | $violationMessageDeserializer = new ViolationMessageDeserializer( |
||
203 | $wikibaseRepo->getEntityIdParser(), |
||
204 | $wikibaseRepo->getDataValueFactory() |
||
205 | ); |
||
206 | $instance = new self( |
||
207 | $wikibaseRepo->getEntityLookup(), |
||
208 | $wikibaseRepo->getPropertyDataTypeLookup(), |
||
209 | $wikibaseRepo->getStatementGuidParser(), |
||
210 | $config, |
||
211 | new ConstraintParameterParser( |
||
212 | $config, |
||
213 | $wikibaseRepo->getBaseDataModelDeserializerFactory(), |
||
214 | $wikibaseRepo->getConceptBaseUris() |
||
215 | ), |
||
216 | new ViolationMessageSerializer(), |
||
217 | $violationMessageDeserializer, |
||
218 | $wikibaseRepo->getRdfVocabulary(), |
||
219 | $wikibaseRepo->getEntityIdParser(), |
||
220 | $titleParser, |
||
221 | $wikibaseRepo->getUnitConverter(), |
||
222 | $wikibaseRepo->getDataValueFactory(), |
||
223 | $wikibaseRepo->getEntityNamespaceLookup(), |
||
224 | MediaWikiServices::getInstance()->getStatsdDataFactory() |
||
225 | ); |
||
226 | } |
||
227 | |||
228 | return $instance; |
||
229 | } |
||
230 | |||
231 | public function __construct( |
||
232 | EntityLookup $lookup, |
||
233 | PropertyDataTypeLookup $propertyDataTypeLookup, |
||
234 | StatementGuidParser $statementGuidParser, |
||
235 | Config $config, |
||
236 | ConstraintParameterParser $constraintParameterParser, |
||
237 | ViolationMessageSerializer $violationMessageSerializer, |
||
238 | ViolationMessageDeserializer $violationMessageDeserializer, |
||
239 | RdfVocabulary $rdfVocabulary, |
||
240 | EntityIdParser $entityIdParser, |
||
241 | TitleParser $titleParser, |
||
242 | UnitConverter $unitConverter = null, |
||
243 | DataValueFactory $dataValueFactory, |
||
244 | EntityNamespaceLookup $entityNamespaceLookup, |
||
245 | IBufferingStatsdDataFactory $dataFactory |
||
246 | ) { |
||
247 | $this->lookup = $lookup; |
||
248 | $this->propertyDataTypeLookup = $propertyDataTypeLookup; |
||
249 | $this->statementGuidParser = $statementGuidParser; |
||
250 | $this->config = $config; |
||
251 | $this->constraintParameterParser = $constraintParameterParser; |
||
252 | $this->violationMessageSerializer = $violationMessageSerializer; |
||
253 | $this->violationMessageDeserializer = $violationMessageDeserializer; |
||
254 | $this->rdfVocabulary = $rdfVocabulary; |
||
255 | $this->entityIdParser = $entityIdParser; |
||
256 | $this->titleParser = $titleParser; |
||
257 | $this->unitConverter = $unitConverter; |
||
258 | $this->dataValueFactory = $dataValueFactory; |
||
259 | $this->entityNamespaceLookup = $entityNamespaceLookup; |
||
260 | $this->dataFactory = $dataFactory; |
||
261 | } |
||
262 | |||
263 | /** |
||
264 | * @return DelegatingConstraintChecker |
||
265 | */ |
||
266 | public function getConstraintChecker() { |
||
267 | if ( $this->delegatingConstraintChecker === null ) { |
||
268 | $this->delegatingConstraintChecker = new DelegatingConstraintChecker( |
||
269 | $this->lookup, |
||
270 | $this->getConstraintCheckerMap(), |
||
271 | new CachingConstraintLookup( $this->getConstraintRepository() ), |
||
272 | $this->constraintParameterParser, |
||
273 | $this->statementGuidParser, |
||
274 | new LoggingHelper( |
||
275 | $this->dataFactory, |
||
276 | LoggerFactory::getInstance( 'WikibaseQualityConstraints' ), |
||
277 | $this->config |
||
278 | ), |
||
279 | $this->config->get( 'WBQualityConstraintsCheckQualifiers' ), |
||
280 | $this->config->get( 'WBQualityConstraintsCheckReferences' ), |
||
281 | $this->config->get( 'WBQualityConstraintsPropertiesWithViolatingQualifiers' ) |
||
282 | ); |
||
283 | } |
||
284 | |||
285 | return $this->delegatingConstraintChecker; |
||
286 | } |
||
287 | |||
288 | /** |
||
289 | * @return ConstraintChecker[] |
||
290 | */ |
||
291 | private function getConstraintCheckerMap() { |
||
292 | if ( $this->constraintCheckerMap === null ) { |
||
293 | $connectionCheckerHelper = new ConnectionCheckerHelper(); |
||
294 | $rangeCheckerHelper = new RangeCheckerHelper( $this->config, $this->unitConverter ); |
||
295 | if ( $this->config->get( 'WBQualityConstraintsSparqlEndpoint' ) !== '' ) { |
||
296 | $sparqlHelper = new SparqlHelper( |
||
297 | $this->config, |
||
298 | $this->rdfVocabulary, |
||
299 | $this->entityIdParser, |
||
300 | $this->propertyDataTypeLookup, |
||
301 | MediaWikiServices::getInstance()->getMainWANObjectCache(), |
||
302 | $this->violationMessageSerializer, |
||
303 | $this->violationMessageDeserializer, |
||
304 | $this->dataFactory |
||
305 | ); |
||
306 | } else { |
||
307 | $sparqlHelper = null; |
||
308 | } |
||
309 | $typeCheckerHelper = new TypeCheckerHelper( |
||
310 | $this->lookup, |
||
311 | $this->config, |
||
312 | $sparqlHelper, |
||
313 | $this->dataFactory |
||
314 | ); |
||
315 | |||
316 | $this->constraintCheckerMap = [ |
||
317 | $this->config->get( 'WBQualityConstraintsConflictsWithConstraintId' ) |
||
318 | => new ConflictsWithChecker( |
||
319 | $this->lookup, |
||
320 | $this->constraintParameterParser, |
||
321 | $connectionCheckerHelper |
||
322 | ), |
||
323 | $this->config->get( 'WBQualityConstraintsItemRequiresClaimConstraintId' ) |
||
324 | => new ItemChecker( |
||
325 | $this->lookup, |
||
326 | $this->constraintParameterParser, |
||
327 | $connectionCheckerHelper |
||
328 | ), |
||
329 | $this->config->get( 'WBQualityConstraintsValueRequiresClaimConstraintId' ) |
||
330 | => new TargetRequiredClaimChecker( |
||
331 | $this->lookup, |
||
332 | $this->constraintParameterParser, |
||
333 | $connectionCheckerHelper |
||
334 | ), |
||
335 | $this->config->get( 'WBQualityConstraintsSymmetricConstraintId' ) |
||
336 | => new SymmetricChecker( |
||
337 | $this->lookup, |
||
338 | $connectionCheckerHelper |
||
339 | ), |
||
340 | $this->config->get( 'WBQualityConstraintsInverseConstraintId' ) |
||
341 | => new InverseChecker( |
||
342 | $this->lookup, |
||
343 | $this->constraintParameterParser, |
||
344 | $connectionCheckerHelper |
||
345 | ), |
||
346 | $this->config->get( 'WBQualityConstraintsUsedAsQualifierConstraintId' ) |
||
347 | => new QualifierChecker(), |
||
348 | $this->config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' ) |
||
349 | => new QualifiersChecker( |
||
350 | $this->constraintParameterParser |
||
351 | ), |
||
352 | $this->config->get( 'WBQualityConstraintsMandatoryQualifierConstraintId' ) |
||
353 | => new MandatoryQualifiersChecker( |
||
354 | $this->constraintParameterParser |
||
355 | ), |
||
356 | $this->config->get( 'WBQualityConstraintsRangeConstraintId' ) |
||
357 | => new RangeChecker( |
||
358 | $this->propertyDataTypeLookup, |
||
359 | $this->constraintParameterParser, |
||
360 | $rangeCheckerHelper |
||
361 | ), |
||
362 | $this->config->get( 'WBQualityConstraintsDifferenceWithinRangeConstraintId' ) |
||
363 | => new DiffWithinRangeChecker( |
||
364 | $this->constraintParameterParser, |
||
365 | $rangeCheckerHelper, |
||
366 | $this->config |
||
367 | ), |
||
368 | $this->config->get( 'WBQualityConstraintsTypeConstraintId' ) |
||
369 | => new TypeChecker( |
||
370 | $this->lookup, |
||
371 | $this->constraintParameterParser, |
||
372 | $typeCheckerHelper, |
||
373 | $this->config |
||
374 | ), |
||
375 | $this->config->get( 'WBQualityConstraintsValueTypeConstraintId' ) |
||
376 | => new ValueTypeChecker( |
||
377 | $this->lookup, |
||
378 | $this->constraintParameterParser, |
||
379 | $typeCheckerHelper, |
||
380 | $this->config |
||
381 | ), |
||
382 | $this->config->get( 'WBQualityConstraintsSingleValueConstraintId' ) |
||
383 | => new SingleValueChecker( $this->constraintParameterParser ), |
||
384 | $this->config->get( 'WBQualityConstraintsMultiValueConstraintId' ) |
||
385 | => new MultiValueChecker( $this->constraintParameterParser ), |
||
386 | $this->config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ) |
||
387 | => new UniqueValueChecker( |
||
388 | $sparqlHelper |
||
389 | ), |
||
390 | $this->config->get( 'WBQualityConstraintsFormatConstraintId' ) |
||
391 | => new FormatChecker( |
||
392 | $this->constraintParameterParser, |
||
393 | $this->config, |
||
394 | $sparqlHelper |
||
395 | ), |
||
396 | $this->config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ) |
||
397 | => new CommonsLinkChecker( |
||
398 | $this->constraintParameterParser, |
||
399 | $this->titleParser |
||
400 | ), |
||
401 | $this->config->get( 'WBQualityConstraintsOneOfConstraintId' ) |
||
402 | => new OneOfChecker( |
||
403 | $this->constraintParameterParser |
||
404 | ), |
||
405 | $this->config->get( 'WBQualityConstraintsUsedForValuesOnlyConstraintId' ) |
||
406 | => new ValueOnlyChecker(), |
||
407 | $this->config->get( 'WBQualityConstraintsUsedAsReferenceConstraintId' ) |
||
408 | => new ReferenceChecker(), |
||
409 | $this->config->get( 'WBQualityConstraintsNoBoundsConstraintId' ) |
||
410 | => new NoBoundsChecker(), |
||
411 | $this->config->get( 'WBQualityConstraintsAllowedUnitsConstraintId' ) |
||
412 | => new AllowedUnitsChecker( |
||
413 | $this->constraintParameterParser, |
||
414 | $this->unitConverter |
||
415 | ), |
||
416 | $this->config->get( 'WBQualityConstraintsSingleBestValueConstraintId' ) |
||
417 | => new SingleBestValueChecker( $this->constraintParameterParser ), |
||
418 | $this->config->get( 'WBQualityConstraintsAllowedEntityTypesConstraintId' ) |
||
419 | => new EntityTypeChecker( |
||
420 | $this->constraintParameterParser |
||
421 | ), |
||
422 | $this->config->get( 'WBQualityConstraintsNoneOfConstraintId' ) |
||
423 | => new NoneOfChecker( |
||
424 | $this->constraintParameterParser |
||
425 | ), |
||
426 | $this->config->get( 'WBQualityConstraintsIntegerConstraintId' ) |
||
427 | => new IntegerChecker(), |
||
428 | $this->config->get( 'WBQualityConstraintsCitationNeededConstraintId' ) |
||
429 | => new CitationNeededChecker(), |
||
430 | ]; |
||
431 | } |
||
432 | |||
433 | return $this->constraintCheckerMap; |
||
434 | } |
||
435 | |||
436 | /** |
||
437 | * @return ConstraintRepository |
||
438 | */ |
||
439 | public function getConstraintRepository() { |
||
446 | |||
447 | /** |
||
448 | * @return LoggingHelper |
||
449 | */ |
||
450 | public function getLoggingHelper() { |
||
461 | |||
462 | /** |
||
463 | * @return CheckResultSerializer |
||
464 | */ |
||
465 | public function getCheckResultSerializer() { |
||
479 | |||
480 | /** |
||
481 | * @return CheckResultDeserializer |
||
482 | */ |
||
483 | public function getCheckResultDeserializer() { |
||
498 | |||
499 | /** |
||
500 | * @return WikiPageEntityMetaDataAccessor |
||
501 | */ |
||
502 | public function getWikiPageEntityMetaDataAccessor() { |
||
511 | |||
512 | /** |
||
513 | * @return ResultsSource |
||
514 | */ |
||
515 | public function getResultsSource() { |
||
539 | |||
540 | /** |
||
541 | * @return string[] |
||
542 | */ |
||
543 | public function getPossiblyStaleConstraintTypes() { |
||
551 | |||
552 | } |
||
553 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..