@@ -95,22 +95,22 @@ discard block |
||
95 | 95 | * @return CrossCheckResultList |
96 | 96 | * @throws InvalidArgumentException |
97 | 97 | */ |
98 | - public function crossCheckStatements( StatementList $entityStatements, StatementList $statements ) { |
|
98 | + public function crossCheckStatements(StatementList $entityStatements, StatementList $statements) { |
|
99 | 99 | $statementsOfEntity = $entityStatements->toArray(); |
100 | 100 | |
101 | - foreach ( $statements as $statement ) { |
|
102 | - if ( !in_array( $statement, $statementsOfEntity ) ) { |
|
103 | - throw new InvalidArgumentException( 'All statements in $statements must belong to the entity.' ); |
|
101 | + foreach ($statements as $statement) { |
|
102 | + if (!in_array($statement, $statementsOfEntity)) { |
|
103 | + throw new InvalidArgumentException('All statements in $statements must belong to the entity.'); |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
107 | 107 | $resultList = new CrossCheckResultList(); |
108 | - if ( $statements->count() > 0 ) { |
|
109 | - $applicableDumps = $this->getApplicableDumps( $entityStatements ); |
|
110 | - foreach ( $applicableDumps as $identifierPropertyId => $dumpMetaInformationList ) { |
|
111 | - $identifierPropertyId = new PropertyId( $identifierPropertyId ); |
|
108 | + if ($statements->count() > 0) { |
|
109 | + $applicableDumps = $this->getApplicableDumps($entityStatements); |
|
110 | + foreach ($applicableDumps as $identifierPropertyId => $dumpMetaInformationList) { |
|
111 | + $identifierPropertyId = new PropertyId($identifierPropertyId); |
|
112 | 112 | |
113 | - if( $this->isIdentifierProperty( $identifierPropertyId ) ) { |
|
113 | + if ($this->isIdentifierProperty($identifierPropertyId)) { |
|
114 | 114 | $resultList->merge( |
115 | 115 | $this->crossCheckStatementsWithIdentifier( |
116 | 116 | $entityStatements, |
@@ -133,17 +133,17 @@ discard block |
||
133 | 133 | * |
134 | 134 | * @return array[] |
135 | 135 | */ |
136 | - private function getApplicableDumps( StatementList $statements ) { |
|
136 | + private function getApplicableDumps(StatementList $statements) { |
|
137 | 137 | $applicableDumps = array(); |
138 | 138 | $identifierPropertyIds = $statements->getPropertyIds(); |
139 | 139 | $dumpMetaInformation = $this->dumpMetaInformationLookup->getWithIdentifierProperties( |
140 | 140 | $identifierPropertyIds |
141 | 141 | ); |
142 | 142 | |
143 | - foreach ( $dumpMetaInformation as $dump ) { |
|
144 | - foreach ( $dump->getIdentifierPropertyIds() as $identifierPropertyId ) { |
|
143 | + foreach ($dumpMetaInformation as $dump) { |
|
144 | + foreach ($dump->getIdentifierPropertyIds() as $identifierPropertyId) { |
|
145 | 145 | $serialization = $identifierPropertyId->getSerialization(); |
146 | - $applicableDumps[ $serialization ][ $dump->getDumpId() ] = $dump; |
|
146 | + $applicableDumps[$serialization][$dump->getDumpId()] = $dump; |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | |
@@ -168,36 +168,36 @@ discard block |
||
168 | 168 | ) { |
169 | 169 | $resultList = new CrossCheckResultList(); |
170 | 170 | |
171 | - $externalIds = $this->getExternalIds( $entityStatements, $identifierPropertyId ); |
|
172 | - if( !$externalIds ) { |
|
171 | + $externalIds = $this->getExternalIds($entityStatements, $identifierPropertyId); |
|
172 | + if (!$externalIds) { |
|
173 | 173 | return $resultList; |
174 | 174 | } |
175 | 175 | |
176 | 176 | $dumpIds = array_map( |
177 | - function ( DumpMetaInformation $dumpMetaInformation ) { |
|
177 | + function(DumpMetaInformation $dumpMetaInformation) { |
|
178 | 178 | return $dumpMetaInformation->getDumpId(); |
179 | 179 | }, |
180 | 180 | $dumpMetaInformationList |
181 | 181 | ); |
182 | - $externalData = $this->externalDataRepo->getExternalData( $dumpIds, $externalIds, $statements->getPropertyIds() ); |
|
182 | + $externalData = $this->externalDataRepo->getExternalData($dumpIds, $externalIds, $statements->getPropertyIds()); |
|
183 | 183 | |
184 | - foreach ( $externalData as $dumpId => $externalDataPerDump ) { |
|
185 | - $dumpMetaInformation = $dumpMetaInformationList[ $dumpId ]; |
|
184 | + foreach ($externalData as $dumpId => $externalDataPerDump) { |
|
185 | + $dumpMetaInformation = $dumpMetaInformationList[$dumpId]; |
|
186 | 186 | $comparativeValueParser = $this->valueParserFactory->newComparativeValueParser( |
187 | 187 | $dumpMetaInformation->getLanguageCode() |
188 | 188 | ); |
189 | 189 | |
190 | - foreach ( $externalDataPerDump as $externalId => $externalDataPerId ) { |
|
190 | + foreach ($externalDataPerDump as $externalId => $externalDataPerId) { |
|
191 | 191 | $externalId = (string)$externalId; |
192 | - foreach ( $externalDataPerId as $propertyId => $externalValues ) { |
|
193 | - $propertyId = new PropertyId( $propertyId ); |
|
192 | + foreach ($externalDataPerId as $propertyId => $externalValues) { |
|
193 | + $propertyId = new PropertyId($propertyId); |
|
194 | 194 | $resultList->merge( |
195 | 195 | $this->crossCheckExternalValues( |
196 | 196 | $dumpMetaInformation, |
197 | 197 | $identifierPropertyId, |
198 | 198 | $externalId, |
199 | 199 | $externalValues, |
200 | - $statements->getByPropertyId( $propertyId ), |
|
200 | + $statements->getByPropertyId($propertyId), |
|
201 | 201 | $comparativeValueParser |
202 | 202 | ) |
203 | 203 | ); |
@@ -228,10 +228,10 @@ discard block |
||
228 | 228 | ) { |
229 | 229 | $resultList = new CrossCheckResultList(); |
230 | 230 | |
231 | - foreach ( $statements->toArray() as $statement ) { |
|
232 | - $comparisonResult = $this->compareStatement( $statement, $externalValues, $comparativeValueParser ); |
|
231 | + foreach ($statements->toArray() as $statement) { |
|
232 | + $comparisonResult = $this->compareStatement($statement, $externalValues, $comparativeValueParser); |
|
233 | 233 | |
234 | - if ( $comparisonResult ) { |
|
234 | + if ($comparisonResult) { |
|
235 | 235 | $referencesResult = $this->referenceHandler->checkForReferences( |
236 | 236 | $statement, |
237 | 237 | $identifierPropertyId, |
@@ -265,32 +265,32 @@ discard block |
||
265 | 265 | * @return ComparisonResult|bool |
266 | 266 | */ |
267 | 267 | private function compareStatement( |
268 | - Statement $statement,array $externalValues, |
|
268 | + Statement $statement, array $externalValues, |
|
269 | 269 | ComparativeValueParser $comparativeValueParser |
270 | 270 | ) { |
271 | 271 | $mainSnak = $statement->getMainSnak(); |
272 | - if ( $mainSnak instanceof PropertyValueSnak ) { |
|
272 | + if ($mainSnak instanceof PropertyValueSnak) { |
|
273 | 273 | $dataValue = $mainSnak->getDataValue(); |
274 | 274 | |
275 | 275 | $results = array(); |
276 | - $comparativeValues = $this->parseExternalValues( $dataValue, $externalValues, $comparativeValueParser ); |
|
277 | - foreach ( $comparativeValues as $comparativeValue ) { |
|
278 | - $result = $this->dataValueComparer->compare( $dataValue, $comparativeValue ); |
|
279 | - if( $result ) { |
|
276 | + $comparativeValues = $this->parseExternalValues($dataValue, $externalValues, $comparativeValueParser); |
|
277 | + foreach ($comparativeValues as $comparativeValue) { |
|
278 | + $result = $this->dataValueComparer->compare($dataValue, $comparativeValue); |
|
279 | + if ($result) { |
|
280 | 280 | $results[] = $result; |
281 | 281 | } |
282 | 282 | } |
283 | 283 | |
284 | - if( $results ) { |
|
284 | + if ($results) { |
|
285 | 285 | $result = ComparisonResult::STATUS_MISMATCH; |
286 | - if( in_array( ComparisonResult::STATUS_MATCH, $results ) ) { |
|
286 | + if (in_array(ComparisonResult::STATUS_MATCH, $results)) { |
|
287 | 287 | $result = ComparisonResult::STATUS_MATCH; |
288 | 288 | } |
289 | - elseif( in_array( ComparisonResult::STATUS_PARTIAL_MATCH, $results ) ) { |
|
289 | + elseif (in_array(ComparisonResult::STATUS_PARTIAL_MATCH, $results)) { |
|
290 | 290 | $result = ComparisonResult::STATUS_PARTIAL_MATCH; |
291 | 291 | } |
292 | 292 | |
293 | - return new ComparisonResult( $dataValue, $comparativeValues, $result ); |
|
293 | + return new ComparisonResult($dataValue, $comparativeValues, $result); |
|
294 | 294 | } |
295 | 295 | } |
296 | 296 | |
@@ -310,14 +310,14 @@ discard block |
||
310 | 310 | ComparativeValueParser $comparativeValueParser |
311 | 311 | ) { |
312 | 312 | $parsedValues = array(); |
313 | - foreach ( $externalValues as $externalValue ) { |
|
313 | + foreach ($externalValues as $externalValue) { |
|
314 | 314 | try { |
315 | - $parsedValue = $comparativeValueParser->parse( $externalValue, $dataValue->getType() ); |
|
316 | - if( $parsedValue ) { |
|
315 | + $parsedValue = $comparativeValueParser->parse($externalValue, $dataValue->getType()); |
|
316 | + if ($parsedValue) { |
|
317 | 317 | $parsedValues[] = $parsedValue; |
318 | 318 | } |
319 | 319 | } |
320 | - catch( ParseException $e ) {} |
|
320 | + catch (ParseException $e) {} |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | return $parsedValues; |
@@ -331,12 +331,12 @@ discard block |
||
331 | 331 | * |
332 | 332 | * @return string[] |
333 | 333 | */ |
334 | - private function getExternalIds( StatementList $statements, PropertyId $identifierPropertyId ) { |
|
334 | + private function getExternalIds(StatementList $statements, PropertyId $identifierPropertyId) { |
|
335 | 335 | $externalIds = array(); |
336 | - $identifierStatements = $statements->getByPropertyId( $identifierPropertyId ); |
|
337 | - $values = $this->getDataValues( $identifierStatements ); |
|
338 | - foreach ( $values as $value ) { |
|
339 | - if ( $value instanceof StringValue ) { |
|
336 | + $identifierStatements = $statements->getByPropertyId($identifierPropertyId); |
|
337 | + $values = $this->getDataValues($identifierStatements); |
|
338 | + foreach ($values as $value) { |
|
339 | + if ($value instanceof StringValue) { |
|
340 | 340 | $externalIds[] = $value->getValue(); |
341 | 341 | } |
342 | 342 | } |
@@ -348,16 +348,16 @@ discard block |
||
348 | 348 | * @param PropertyId $identifierPropertyId |
349 | 349 | * @return bool |
350 | 350 | */ |
351 | - private function isIdentifierProperty( PropertyId $identifierPropertyId ) { |
|
351 | + private function isIdentifierProperty(PropertyId $identifierPropertyId) { |
|
352 | 352 | global $wgWBQEVInstanceOfPID, $wgWBQEVIdentifierPropertyQID; |
353 | 353 | /** @var Property $property */ |
354 | - $property = $this->entityLookup->getEntity( $identifierPropertyId ); |
|
355 | - $instanceOfPropertyId = new PropertyId( $wgWBQEVInstanceOfPID ); |
|
356 | - $statements = $property->getStatements()->getByPropertyId( $instanceOfPropertyId ); |
|
357 | - $values = $this->getDataValues( $statements ); |
|
358 | - foreach ( $values as $value ) { |
|
359 | - if( $value instanceof EntityIdValue ) { |
|
360 | - if( $value->getEntityId()->getSerialization() === $wgWBQEVIdentifierPropertyQID ) { |
|
354 | + $property = $this->entityLookup->getEntity($identifierPropertyId); |
|
355 | + $instanceOfPropertyId = new PropertyId($wgWBQEVInstanceOfPID); |
|
356 | + $statements = $property->getStatements()->getByPropertyId($instanceOfPropertyId); |
|
357 | + $values = $this->getDataValues($statements); |
|
358 | + foreach ($values as $value) { |
|
359 | + if ($value instanceof EntityIdValue) { |
|
360 | + if ($value->getEntityId()->getSerialization() === $wgWBQEVIdentifierPropertyQID) { |
|
361 | 361 | return true; |
362 | 362 | } |
363 | 363 | } |
@@ -372,12 +372,12 @@ discard block |
||
372 | 372 | * @param StatementList $statementList |
373 | 373 | * @return DataValue[] |
374 | 374 | */ |
375 | - private function getDataValues( StatementList $statementList ){ |
|
375 | + private function getDataValues(StatementList $statementList) { |
|
376 | 376 | $dataValues = array(); |
377 | 377 | |
378 | - foreach ( $statementList->toArray() as $statement ) { |
|
378 | + foreach ($statementList->toArray() as $statement) { |
|
379 | 379 | $mainSnak = $statement->getMainSnak(); |
380 | - if ( $mainSnak instanceof PropertyValueSnak ) { |
|
380 | + if ($mainSnak instanceof PropertyValueSnak) { |
|
381 | 381 | $dataValues[] = $mainSnak->getDataValue(); |
382 | 382 | } |
383 | 383 | } |
@@ -34,17 +34,17 @@ discard block |
||
34 | 34 | * @throws InvalidArgumentException |
35 | 35 | * @return ReferenceResult |
36 | 36 | */ |
37 | - public function checkForReferences( Statement $statement, PropertyId $identifierPropertyId, $externalId, DumpMetaInformation $dumpMetaInformation ) { |
|
38 | - Assert::parameterType( 'string', $externalId, '$externalId' ); |
|
37 | + public function checkForReferences(Statement $statement, PropertyId $identifierPropertyId, $externalId, DumpMetaInformation $dumpMetaInformation) { |
|
38 | + Assert::parameterType('string', $externalId, '$externalId'); |
|
39 | 39 | |
40 | - if ( count( $statement->getReferences() ) === 0 ) { |
|
40 | + if (count($statement->getReferences()) === 0) { |
|
41 | 41 | $status = ReferenceResult::STATUS_REFERENCES_MISSING; |
42 | 42 | } else { |
43 | 43 | $status = ReferenceResult::STATUS_REFERENCES_STATED; |
44 | 44 | } |
45 | 45 | |
46 | - $externalReference = $this->buildReference( $identifierPropertyId, $externalId, $dumpMetaInformation ); |
|
47 | - return new ReferenceResult( $status, $externalReference ); |
|
46 | + $externalReference = $this->buildReference($identifierPropertyId, $externalId, $dumpMetaInformation); |
|
47 | + return new ReferenceResult($status, $externalReference); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -55,17 +55,17 @@ discard block |
||
55 | 55 | * @param DumpMetaInformation $dumpMetaInformation |
56 | 56 | * @return Reference |
57 | 57 | */ |
58 | - private function buildReference( PropertyId $identifierPropertyId, $externalId, DumpMetaInformation $dumpMetaInformation ) { |
|
58 | + private function buildReference(PropertyId $identifierPropertyId, $externalId, DumpMetaInformation $dumpMetaInformation) { |
|
59 | 59 | global $wgWBQEVStatedInPID; |
60 | 60 | |
61 | 61 | $sourceItemId = $dumpMetaInformation->getSourceItemId(); |
62 | 62 | $statedInAuthoritySnak = new PropertyValueSnak( |
63 | - new PropertyId( $wgWBQEVStatedInPID ), |
|
64 | - new EntityIdValue( $sourceItemId ) |
|
63 | + new PropertyId($wgWBQEVStatedInPID), |
|
64 | + new EntityIdValue($sourceItemId) |
|
65 | 65 | ); |
66 | 66 | $authorityWithExternalIdSnak = new PropertyValueSnak( |
67 | 67 | $identifierPropertyId, |
68 | - new StringValue( $externalId ) |
|
68 | + new StringValue($externalId) |
|
69 | 69 | ); |
70 | 70 | |
71 | 71 | return new Reference( |
@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { |
|
4 | - require_once __DIR__ . '/vendor/autoload.php'; |
|
3 | +if (is_readable(__DIR__.'/vendor/autoload.php')) { |
|
4 | + require_once __DIR__.'/vendor/autoload.php'; |
|
5 | 5 | } |
6 | 6 | |
7 | -call_user_func( function () { |
|
7 | +call_user_func(function() { |
|
8 | 8 | // Set credits |
9 | 9 | $GLOBALS['wgExtensionCredits']['wikibase'][] = array( |
10 | 10 | 'path' => __FILE__, |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | ); |
18 | 18 | |
19 | 19 | // Initialize localization and aliases |
20 | - $GLOBALS['wgMessagesDirs']['WikibaseQualityExternalValidation'] = __DIR__ . '/i18n'; |
|
21 | - $GLOBALS['wgExtensionMessagesFiles']['WikibaseQualityExternalValidationAlias'] = __DIR__ . '/WikibaseQualityExternalValidation.alias.php'; |
|
20 | + $GLOBALS['wgMessagesDirs']['WikibaseQualityExternalValidation'] = __DIR__.'/i18n'; |
|
21 | + $GLOBALS['wgExtensionMessagesFiles']['WikibaseQualityExternalValidationAlias'] = __DIR__.'/WikibaseQualityExternalValidation.alias.php'; |
|
22 | 22 | |
23 | 23 | // Initalize hooks for creating database tables |
24 | 24 | $GLOBALS['wgHooks']['LoadExtensionSchemaUpdates'][] = 'WikibaseQualityExternalValidationHooks::onCreateSchema'; |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | // Define API modules |
34 | 34 | $GLOBALS['wgAPIModules']['wbqevcrosscheck'] = array( |
35 | 35 | 'class' => 'WikibaseQuality\ExternalValidation\Api\RunCrossCheck', |
36 | - 'factory' => function( ApiMain $main, $action ) { |
|
37 | - return \WikibaseQuality\ExternalValidation\Api\RunCrossCheck::newFromGlobalState( $main, $action ); |
|
36 | + 'factory' => function(ApiMain $main, $action) { |
|
37 | + return \WikibaseQuality\ExternalValidation\Api\RunCrossCheck::newFromGlobalState($main, $action); |
|
38 | 38 | } |
39 | 39 | ); |
40 | 40 |