@@ -83,27 +83,27 @@ discard block |
||
83 | 83 | * |
84 | 84 | * @throws InvalidArgumentException |
85 | 85 | */ |
86 | - public function __construct( $dumpId, |
|
86 | + public function __construct($dumpId, |
|
87 | 87 | ItemId $sourceItemId, |
88 | 88 | array $identifierPropertyIds, |
89 | 89 | $importDate, |
90 | 90 | $languageCode, |
91 | 91 | $sourceUrl, |
92 | 92 | $size, |
93 | - ItemId $licenseItemId ) { |
|
93 | + ItemId $licenseItemId) { |
|
94 | 94 | Assert::parameterElementType( |
95 | 95 | PropertyId::class, |
96 | 96 | $identifierPropertyIds, |
97 | 97 | '$identifierPropertyIds' |
98 | 98 | ); |
99 | 99 | |
100 | - $this->setDumpId( $dumpId ); |
|
100 | + $this->setDumpId($dumpId); |
|
101 | 101 | $this->sourceItemId = $sourceItemId; |
102 | 102 | $this->identifierPropertyIds = $identifierPropertyIds; |
103 | - $this->setImportDate( $importDate ); |
|
104 | - $this->setLanguageCode( $languageCode ); |
|
105 | - $this->setSourceUrl( $sourceUrl ); |
|
106 | - $this->setSize( $size ); |
|
103 | + $this->setImportDate($importDate); |
|
104 | + $this->setLanguageCode($languageCode); |
|
105 | + $this->setSourceUrl($sourceUrl); |
|
106 | + $this->setSize($size); |
|
107 | 107 | $this->licenseItemId = $licenseItemId; |
108 | 108 | } |
109 | 109 | |
@@ -168,10 +168,10 @@ discard block |
||
168 | 168 | * |
169 | 169 | * @throws InvalidArgumentException |
170 | 170 | */ |
171 | - private function setDumpId( $dumpId ) { |
|
172 | - Assert::parameterType( 'string', $dumpId, '$dumpId' ); |
|
173 | - $length = strlen( $dumpId ); |
|
174 | - if ( $length < 1 || $length > 25 ) { |
|
171 | + private function setDumpId($dumpId) { |
|
172 | + Assert::parameterType('string', $dumpId, '$dumpId'); |
|
173 | + $length = strlen($dumpId); |
|
174 | + if ($length < 1 || $length > 25) { |
|
175 | 175 | throw new InvalidArgumentException('$dumpId must be between 1 and 25 characters.'); |
176 | 176 | } |
177 | 177 | |
@@ -183,10 +183,10 @@ discard block |
||
183 | 183 | * |
184 | 184 | * @throws InvalidArgumentException |
185 | 185 | */ |
186 | - private function setLanguageCode( $languageCode ) { |
|
187 | - Assert::parameterType( 'string', $languageCode, '$languageCode' ); |
|
188 | - if( !Language::isValidCode( $languageCode ) ) { |
|
189 | - throw new InvalidArgumentException( '$languageCode is not valid.' ); |
|
186 | + private function setLanguageCode($languageCode) { |
|
187 | + Assert::parameterType('string', $languageCode, '$languageCode'); |
|
188 | + if (!Language::isValidCode($languageCode)) { |
|
189 | + throw new InvalidArgumentException('$languageCode is not valid.'); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | $this->languageCode = $languageCode; |
@@ -197,12 +197,12 @@ discard block |
||
197 | 197 | * |
198 | 198 | * @throws InvalidArgumentException |
199 | 199 | */ |
200 | - private function setImportDate( $importDate ) { |
|
201 | - Assert::parameterType( 'string', $importDate, '$importDate' ); |
|
200 | + private function setImportDate($importDate) { |
|
201 | + Assert::parameterType('string', $importDate, '$importDate'); |
|
202 | 202 | |
203 | - $timestamp = wfTimestamp( TS_MW, $importDate ); |
|
204 | - if( !$timestamp ) { |
|
205 | - throw new InvalidArgumentException( '$updatedAt has invalid timestamp format.' ); |
|
203 | + $timestamp = wfTimestamp(TS_MW, $importDate); |
|
204 | + if (!$timestamp) { |
|
205 | + throw new InvalidArgumentException('$updatedAt has invalid timestamp format.'); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | $this->importDate = $importDate; |
@@ -213,13 +213,13 @@ discard block |
||
213 | 213 | * |
214 | 214 | * @throws InvalidArgumentException |
215 | 215 | */ |
216 | - private function setSourceUrl( $sourceUrl ) { |
|
217 | - Assert::parameterType( 'string', $sourceUrl, '$sourceUrl' ); |
|
218 | - if( strlen( $sourceUrl ) > 300 ) { |
|
219 | - throw new InvalidArgumentException( '$sourceUrl must not be longer than 300 characters.' ); |
|
216 | + private function setSourceUrl($sourceUrl) { |
|
217 | + Assert::parameterType('string', $sourceUrl, '$sourceUrl'); |
|
218 | + if (strlen($sourceUrl) > 300) { |
|
219 | + throw new InvalidArgumentException('$sourceUrl must not be longer than 300 characters.'); |
|
220 | 220 | } |
221 | - if( !filter_var($sourceUrl, FILTER_VALIDATE_URL) ) { |
|
222 | - throw new InvalidArgumentException( '$sourceUrl is not a valid url.' ); |
|
221 | + if (!filter_var($sourceUrl, FILTER_VALIDATE_URL)) { |
|
222 | + throw new InvalidArgumentException('$sourceUrl is not a valid url.'); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | $this->sourceUrl = $sourceUrl; |
@@ -230,10 +230,10 @@ discard block |
||
230 | 230 | * |
231 | 231 | * @throws InvalidArgumentException |
232 | 232 | */ |
233 | - private function setSize( $size ) { |
|
234 | - Assert::parameterType( 'integer', $size, '$size' ); |
|
235 | - if( $size <= 0 ) { |
|
236 | - throw new InvalidArgumentException( '$size must be positive integer.' ); |
|
233 | + private function setSize($size) { |
|
234 | + Assert::parameterType('integer', $size, '$size'); |
|
235 | + if ($size <= 0) { |
|
236 | + throw new InvalidArgumentException('$size must be positive integer.'); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | $this->size = $size; |
@@ -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,31 +265,31 @@ 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 | - } elseif ( in_array( ComparisonResult::STATUS_PARTIAL_MATCH, $results ) ) { |
|
288 | + } elseif (in_array(ComparisonResult::STATUS_PARTIAL_MATCH, $results)) { |
|
289 | 289 | $result = ComparisonResult::STATUS_PARTIAL_MATCH; |
290 | 290 | } |
291 | 291 | |
292 | - return new ComparisonResult( $dataValue, $comparativeValues, $result ); |
|
292 | + return new ComparisonResult($dataValue, $comparativeValues, $result); |
|
293 | 293 | } |
294 | 294 | } |
295 | 295 | |
@@ -309,13 +309,13 @@ discard block |
||
309 | 309 | ComparativeValueParser $comparativeValueParser |
310 | 310 | ) { |
311 | 311 | $parsedValues = array(); |
312 | - foreach ( $externalValues as $externalValue ) { |
|
312 | + foreach ($externalValues as $externalValue) { |
|
313 | 313 | try { |
314 | - $parsedValue = $comparativeValueParser->parse( $externalValue, $dataValue->getType() ); |
|
315 | - if( $parsedValue ) { |
|
314 | + $parsedValue = $comparativeValueParser->parse($externalValue, $dataValue->getType()); |
|
315 | + if ($parsedValue) { |
|
316 | 316 | $parsedValues[] = $parsedValue; |
317 | 317 | } |
318 | - } catch ( ParseException $e ) { |
|
318 | + } catch (ParseException $e) { |
|
319 | 319 | } |
320 | 320 | } |
321 | 321 | |
@@ -330,12 +330,12 @@ discard block |
||
330 | 330 | * |
331 | 331 | * @return string[] |
332 | 332 | */ |
333 | - private function getExternalIds( StatementList $statements, PropertyId $identifierPropertyId ) { |
|
333 | + private function getExternalIds(StatementList $statements, PropertyId $identifierPropertyId) { |
|
334 | 334 | $externalIds = array(); |
335 | - $identifierStatements = $statements->getByPropertyId( $identifierPropertyId ); |
|
336 | - $values = $this->getDataValues( $identifierStatements ); |
|
337 | - foreach ( $values as $value ) { |
|
338 | - if ( $value instanceof StringValue ) { |
|
335 | + $identifierStatements = $statements->getByPropertyId($identifierPropertyId); |
|
336 | + $values = $this->getDataValues($identifierStatements); |
|
337 | + foreach ($values as $value) { |
|
338 | + if ($value instanceof StringValue) { |
|
339 | 339 | $externalIds[] = $value->getValue(); |
340 | 340 | } |
341 | 341 | } |
@@ -347,16 +347,16 @@ discard block |
||
347 | 347 | * @param PropertyId $identifierPropertyId |
348 | 348 | * @return bool |
349 | 349 | */ |
350 | - private function isIdentifierProperty( PropertyId $identifierPropertyId ) { |
|
350 | + private function isIdentifierProperty(PropertyId $identifierPropertyId) { |
|
351 | 351 | global $wgWBQEVInstanceOfPID, $wgWBQEVIdentifierPropertyQID; |
352 | 352 | /** @var Property $property */ |
353 | - $property = $this->entityLookup->getEntity( $identifierPropertyId ); |
|
354 | - $instanceOfPropertyId = new PropertyId( $wgWBQEVInstanceOfPID ); |
|
355 | - $statements = $property->getStatements()->getByPropertyId( $instanceOfPropertyId ); |
|
356 | - $values = $this->getDataValues( $statements ); |
|
357 | - foreach ( $values as $value ) { |
|
358 | - if( $value instanceof EntityIdValue ) { |
|
359 | - if( $value->getEntityId()->getSerialization() === $wgWBQEVIdentifierPropertyQID ) { |
|
353 | + $property = $this->entityLookup->getEntity($identifierPropertyId); |
|
354 | + $instanceOfPropertyId = new PropertyId($wgWBQEVInstanceOfPID); |
|
355 | + $statements = $property->getStatements()->getByPropertyId($instanceOfPropertyId); |
|
356 | + $values = $this->getDataValues($statements); |
|
357 | + foreach ($values as $value) { |
|
358 | + if ($value instanceof EntityIdValue) { |
|
359 | + if ($value->getEntityId()->getSerialization() === $wgWBQEVIdentifierPropertyQID) { |
|
360 | 360 | return true; |
361 | 361 | } |
362 | 362 | } |
@@ -371,12 +371,12 @@ discard block |
||
371 | 371 | * @param StatementList $statementList |
372 | 372 | * @return DataValue[] |
373 | 373 | */ |
374 | - private function getDataValues( StatementList $statementList ) { |
|
374 | + private function getDataValues(StatementList $statementList) { |
|
375 | 375 | $dataValues = array(); |
376 | 376 | |
377 | - foreach ( $statementList->toArray() as $statement ) { |
|
377 | + foreach ($statementList->toArray() as $statement) { |
|
378 | 378 | $mainSnak = $statement->getMainSnak(); |
379 | - if ( $mainSnak instanceof PropertyValueSnak ) { |
|
379 | + if ($mainSnak instanceof PropertyValueSnak) { |
|
380 | 380 | $dataValues[] = $mainSnak->getDataValue(); |
381 | 381 | } |
382 | 382 | } |