@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | EntityIdHtmlLinkFormatterFactory $entityIdHtmlLinkFormatterFactory, |
54 | 54 | DumpMetaInformationLookup $dumpMetaInformationRepo |
55 | 55 | ) { |
56 | - parent::__construct( 'ExternalDatabases' ); |
|
56 | + parent::__construct('ExternalDatabases'); |
|
57 | 57 | |
58 | 58 | $this->entityIdLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( |
59 | - new LanguageLabelDescriptionLookup( $termLookup, $this->getLanguage()->getCode() ) |
|
59 | + new LanguageLabelDescriptionLookup($termLookup, $this->getLanguage()->getCode()) |
|
60 | 60 | ); |
61 | 61 | |
62 | 62 | $this->dumpMetaInformationRepo = $dumpMetaInformationRepo; |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @return string |
78 | 78 | */ |
79 | 79 | public function getDescription() { |
80 | - return $this->msg( 'wbqev-externaldbs' )->text(); |
|
80 | + return $this->msg('wbqev-externaldbs')->text(); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -85,51 +85,51 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @param string|null $subPage |
87 | 87 | */ |
88 | - public function execute( $subPage ) { |
|
88 | + public function execute($subPage) { |
|
89 | 89 | $out = $this->getOutput(); |
90 | 90 | |
91 | 91 | $this->setHeaders(); |
92 | 92 | |
93 | 93 | $out->addHTML( |
94 | - Html::openElement( 'p' ) |
|
95 | - . $this->msg( 'wbqev-externaldbs-instructions' )->parse() |
|
96 | - . Html::closeElement( 'p' ) |
|
97 | - . Html::openElement( 'h3' ) |
|
98 | - . $this->msg( 'wbqev-externaldbs-overview-headline' )->parse() |
|
99 | - . Html::closeElement( 'h3' ) |
|
94 | + Html::openElement('p') |
|
95 | + . $this->msg('wbqev-externaldbs-instructions')->parse() |
|
96 | + . Html::closeElement('p') |
|
97 | + . Html::openElement('h3') |
|
98 | + . $this->msg('wbqev-externaldbs-overview-headline')->parse() |
|
99 | + . Html::closeElement('h3') |
|
100 | 100 | ); |
101 | 101 | |
102 | 102 | $dumps = $this->dumpMetaInformationRepo->getAll(); |
103 | - if ( $dumps !== [] ) { |
|
103 | + if ($dumps !== []) { |
|
104 | 104 | $groupedDumpMetaInformation = []; |
105 | - foreach ( $dumps as $dump ) { |
|
105 | + foreach ($dumps as $dump) { |
|
106 | 106 | $sourceItemId = $dump->getSourceItemId()->getSerialization(); |
107 | 107 | $groupedDumpMetaInformation[$sourceItemId][] = $dump; |
108 | 108 | } |
109 | 109 | |
110 | 110 | $table = new HtmlTableBuilder( |
111 | 111 | [ |
112 | - $this->msg( 'wbqev-externaldbs-name' )->escaped(), |
|
113 | - $this->msg( 'wbqev-externaldbs-id' )->escaped(), |
|
114 | - $this->msg( 'wbqev-externaldbs-import-date' )->escaped(), |
|
115 | - $this->msg( 'wbqev-externaldbs-language' )->escaped(), |
|
116 | - $this->msg( 'wbqev-externaldbs-source-urls' )->escaped(), |
|
117 | - $this->msg( 'wbqev-externaldbs-size' )->escaped(), |
|
118 | - $this->msg( 'wbqev-externaldbs-license' )->escaped() |
|
112 | + $this->msg('wbqev-externaldbs-name')->escaped(), |
|
113 | + $this->msg('wbqev-externaldbs-id')->escaped(), |
|
114 | + $this->msg('wbqev-externaldbs-import-date')->escaped(), |
|
115 | + $this->msg('wbqev-externaldbs-language')->escaped(), |
|
116 | + $this->msg('wbqev-externaldbs-source-urls')->escaped(), |
|
117 | + $this->msg('wbqev-externaldbs-size')->escaped(), |
|
118 | + $this->msg('wbqev-externaldbs-license')->escaped() |
|
119 | 119 | ], |
120 | 120 | true |
121 | 121 | ); |
122 | 122 | |
123 | - foreach ( $groupedDumpMetaInformation as $dumpMetaInformation ) { |
|
124 | - $table->appendRows( $this->getRowGroup( $dumpMetaInformation ) ); |
|
123 | + foreach ($groupedDumpMetaInformation as $dumpMetaInformation) { |
|
124 | + $table->appendRows($this->getRowGroup($dumpMetaInformation)); |
|
125 | 125 | } |
126 | 126 | |
127 | - $out->addHTML( $table->toHtml() ); |
|
127 | + $out->addHTML($table->toHtml()); |
|
128 | 128 | } else { |
129 | 129 | $out->addHTML( |
130 | - Html::openElement( 'p' ) |
|
131 | - . $this->msg( 'wbqev-externaldbs-no-databases' )->escaped() |
|
132 | - . Html::closeElement( 'p' ) |
|
130 | + Html::openElement('p') |
|
131 | + . $this->msg('wbqev-externaldbs-no-databases')->escaped() |
|
132 | + . Html::closeElement('p') |
|
133 | 133 | ); |
134 | 134 | } |
135 | 135 | } |
@@ -141,12 +141,12 @@ discard block |
||
141 | 141 | * |
142 | 142 | * @return array |
143 | 143 | */ |
144 | - private function getRowGroup( array $dumpMetaInformationGroup ) { |
|
144 | + private function getRowGroup(array $dumpMetaInformationGroup) { |
|
145 | 145 | $rows = []; |
146 | 146 | |
147 | - foreach ( $dumpMetaInformationGroup as $dumpMetaInformation ) { |
|
147 | + foreach ($dumpMetaInformationGroup as $dumpMetaInformation) { |
|
148 | 148 | $dumpId = $dumpMetaInformation->getDumpId(); |
149 | - $importDate = $this->getLanguage()->timeanddate( $dumpMetaInformation->getImportDate() ); |
|
149 | + $importDate = $this->getLanguage()->timeanddate($dumpMetaInformation->getImportDate()); |
|
150 | 150 | $language = Language::fetchLanguageName( |
151 | 151 | $dumpMetaInformation->getLanguageCode(), |
152 | 152 | $this->getLanguage()->getCode() |
@@ -155,23 +155,23 @@ discard block |
||
155 | 155 | $dumpMetaInformation->getSourceUrl(), |
156 | 156 | $dumpMetaInformation->getSourceUrl() |
157 | 157 | ); |
158 | - $size = $this->getLanguage()->formatSize( $dumpMetaInformation->getSize() ); |
|
159 | - $license = $this->entityIdLinkFormatter->formatEntityId( $dumpMetaInformation->getLicenseItemId() ); |
|
158 | + $size = $this->getLanguage()->formatSize($dumpMetaInformation->getSize()); |
|
159 | + $license = $this->entityIdLinkFormatter->formatEntityId($dumpMetaInformation->getLicenseItemId()); |
|
160 | 160 | $rows[] = [ |
161 | - new HtmlTableCellBuilder( $dumpId ), |
|
162 | - new HtmlTableCellBuilder( $importDate ), |
|
163 | - new HtmlTableCellBuilder( $language ), |
|
164 | - new HtmlTableCellBuilder( $sourceUrl, [], true ), |
|
165 | - new HtmlTableCellBuilder( $size ), |
|
166 | - new HtmlTableCellBuilder( $license, [], true ) |
|
161 | + new HtmlTableCellBuilder($dumpId), |
|
162 | + new HtmlTableCellBuilder($importDate), |
|
163 | + new HtmlTableCellBuilder($language), |
|
164 | + new HtmlTableCellBuilder($sourceUrl, [], true), |
|
165 | + new HtmlTableCellBuilder($size), |
|
166 | + new HtmlTableCellBuilder($license, [], true) |
|
167 | 167 | ]; |
168 | 168 | } |
169 | 169 | |
170 | 170 | array_unshift( |
171 | 171 | $rows[0], |
172 | 172 | new HtmlTableCellBuilder( |
173 | - $this->entityIdLinkFormatter->formatEntityId( $dumpMetaInformationGroup[0]->getSourceItemId() ), |
|
174 | - [ 'rowspan' => (string)count( $dumpMetaInformationGroup ) ], |
|
173 | + $this->entityIdLinkFormatter->formatEntityId($dumpMetaInformationGroup[0]->getSourceItemId()), |
|
174 | + ['rowspan' => (string)count($dumpMetaInformationGroup)], |
|
175 | 175 | true |
176 | 176 | ) |
177 | 177 | ); |
@@ -24,23 +24,23 @@ discard block |
||
24 | 24 | * @param PropertyId[] $propertyIds |
25 | 25 | * @return array |
26 | 26 | */ |
27 | - public function getExternalData( array $dumpIds, array $externalIds, array $propertyIds ) { |
|
28 | - Assert::parameterElementType( 'string', $dumpIds, '$dumpIds' ); |
|
29 | - Assert::parameterElementType( 'string', $externalIds, '$externalIds' ); |
|
30 | - Assert::parameterElementType( PropertyId::class, $propertyIds, '$propertyIds' ); |
|
31 | - Assert::parameter( $dumpIds !== [], '$dumpIds', '$dumpIds has to contain at least one element.' ); |
|
32 | - Assert::parameter( $externalIds !== [], '$externalIds', '$externalIds has to contain at least one element.' ); |
|
27 | + public function getExternalData(array $dumpIds, array $externalIds, array $propertyIds) { |
|
28 | + Assert::parameterElementType('string', $dumpIds, '$dumpIds'); |
|
29 | + Assert::parameterElementType('string', $externalIds, '$externalIds'); |
|
30 | + Assert::parameterElementType(PropertyId::class, $propertyIds, '$propertyIds'); |
|
31 | + Assert::parameter($dumpIds !== [], '$dumpIds', '$dumpIds has to contain at least one element.'); |
|
32 | + Assert::parameter($externalIds !== [], '$externalIds', '$externalIds has to contain at least one element.'); |
|
33 | 33 | |
34 | 34 | $conditions = [ |
35 | 35 | 'dump_id' => $dumpIds, |
36 | 36 | 'external_id' => $externalIds |
37 | 37 | ]; |
38 | - if ( $propertyIds ) { |
|
38 | + if ($propertyIds) { |
|
39 | 39 | $conditions['pid'] = $propertyIds; |
40 | 40 | } |
41 | 41 | |
42 | 42 | $externalData = []; |
43 | - $db = wfGetDB( DB_REPLICA ); |
|
43 | + $db = wfGetDB(DB_REPLICA); |
|
44 | 44 | $result = $db->select( |
45 | 45 | self::TABLE_NAME, |
46 | 46 | [ |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | $conditions |
53 | 53 | ); |
54 | 54 | |
55 | - foreach ( $result as $row ) { |
|
55 | + foreach ($result as $row) { |
|
56 | 56 | $externalData[$row->dump_id][$row->external_id][$row->pid][] = $row->external_value; |
57 | 57 | } |
58 | 58 | |
@@ -68,13 +68,13 @@ discard block |
||
68 | 68 | * @param string $externalValue |
69 | 69 | * @return bool |
70 | 70 | */ |
71 | - public function insert( $dumpId, $externalId, PropertyId $propertyId, $externalValue ) { |
|
72 | - Assert::parameterType( 'string', $dumpId, '$dumpId' ); |
|
73 | - Assert::parameterType( 'string', $externalId, '$externalId' ); |
|
74 | - Assert::parameterType( 'string', $externalValue, '$externalValue' ); |
|
71 | + public function insert($dumpId, $externalId, PropertyId $propertyId, $externalValue) { |
|
72 | + Assert::parameterType('string', $dumpId, '$dumpId'); |
|
73 | + Assert::parameterType('string', $externalId, '$externalId'); |
|
74 | + Assert::parameterType('string', $externalValue, '$externalValue'); |
|
75 | 75 | |
76 | - $externalDataBatch = [ func_get_args() ]; |
|
77 | - return $this->insertBatch( $externalDataBatch ); |
|
76 | + $externalDataBatch = [func_get_args()]; |
|
77 | + return $this->insertBatch($externalDataBatch); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -84,10 +84,10 @@ discard block |
||
84 | 84 | * @throws DBError |
85 | 85 | * @return bool |
86 | 86 | */ |
87 | - public function insertBatch( array $externalDataBatch ) { |
|
88 | - $db = wfGetDB( DB_MASTER ); |
|
87 | + public function insertBatch(array $externalDataBatch) { |
|
88 | + $db = wfGetDB(DB_MASTER); |
|
89 | 89 | $accumulator = array_map( |
90 | - function ( $externalData ) use ( $db ) { |
|
90 | + function($externalData) use ($db) { |
|
91 | 91 | return [ |
92 | 92 | 'dump_id' => $externalData[0], |
93 | 93 | 'external_id' => $externalData[1], |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | |
101 | 101 | try { |
102 | 102 | $db->begin(); |
103 | - $result = $db->insert( self::TABLE_NAME, $accumulator ); |
|
103 | + $result = $db->insert(self::TABLE_NAME, $accumulator); |
|
104 | 104 | $db->commit(); |
105 | - } catch ( DBError $ex ) { |
|
105 | + } catch (DBError $ex) { |
|
106 | 106 | $db->rollback(); |
107 | 107 | throw $ex; |
108 | 108 | } |
@@ -117,22 +117,22 @@ discard block |
||
117 | 117 | * @param int $batchSize |
118 | 118 | * @throws \Wikimedia\Rdbms\DBUnexpectedError |
119 | 119 | */ |
120 | - public function deleteOfDump( $dumpId, $batchSize = 1000 ) { |
|
121 | - Assert::parameterType( 'string', $dumpId, '$dumpId' ); |
|
122 | - Assert::parameterType( 'integer', $batchSize, 'batchSize' ); |
|
120 | + public function deleteOfDump($dumpId, $batchSize = 1000) { |
|
121 | + Assert::parameterType('string', $dumpId, '$dumpId'); |
|
122 | + Assert::parameterType('integer', $batchSize, 'batchSize'); |
|
123 | 123 | |
124 | 124 | $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); |
125 | - $db = $lbFactory->getMainLB()->getConnection( DB_MASTER ); |
|
126 | - if ( $db->getType() === 'sqlite' ) { |
|
127 | - $db->delete( self::TABLE_NAME, [ 'dump_id' => $dumpId ] ); |
|
125 | + $db = $lbFactory->getMainLB()->getConnection(DB_MASTER); |
|
126 | + if ($db->getType() === 'sqlite') { |
|
127 | + $db->delete(self::TABLE_NAME, ['dump_id' => $dumpId]); |
|
128 | 128 | } else { |
129 | 129 | do { |
130 | - $db->commit( __METHOD__, 'flush' ); |
|
130 | + $db->commit(__METHOD__, 'flush'); |
|
131 | 131 | $lbFactory->waitForReplication(); |
132 | - $table = $db->tableName( self::TABLE_NAME ); |
|
133 | - $condition = 'dump_id = ' . $db->addQuotes( $dumpId ); |
|
134 | - $db->query( sprintf( 'DELETE FROM %s WHERE %s LIMIT %d', $table, $condition, $batchSize ) ); |
|
135 | - } while ( $db->affectedRows() > 0 ); |
|
132 | + $table = $db->tableName(self::TABLE_NAME); |
|
133 | + $condition = 'dump_id = '.$db->addQuotes($dumpId); |
|
134 | + $db->query(sprintf('DELETE FROM %s WHERE %s LIMIT %d', $table, $condition, $batchSize)); |
|
135 | + } while ($db->affectedRows() > 0); |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 |
@@ -86,22 +86,22 @@ discard block |
||
86 | 86 | * @return CrossCheckResultList |
87 | 87 | * @throws InvalidArgumentException |
88 | 88 | */ |
89 | - public function crossCheckStatements( StatementList $entityStatements, StatementList $statements ) { |
|
89 | + public function crossCheckStatements(StatementList $entityStatements, StatementList $statements) { |
|
90 | 90 | $statementsOfEntity = $entityStatements->toArray(); |
91 | 91 | |
92 | - foreach ( $statements as $statement ) { |
|
93 | - if ( !in_array( $statement, $statementsOfEntity ) ) { |
|
94 | - throw new InvalidArgumentException( 'All statements in $statements must belong to the entity.' ); |
|
92 | + foreach ($statements as $statement) { |
|
93 | + if (!in_array($statement, $statementsOfEntity)) { |
|
94 | + throw new InvalidArgumentException('All statements in $statements must belong to the entity.'); |
|
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
98 | 98 | $resultList = new CrossCheckResultList(); |
99 | - if ( !$statements->isEmpty() ) { |
|
100 | - $applicableDumps = $this->getApplicableDumps( $entityStatements ); |
|
101 | - foreach ( $applicableDumps as $identifierPropertyId => $dumpMetaInformationList ) { |
|
102 | - $identifierPropertyId = new PropertyId( $identifierPropertyId ); |
|
99 | + if (!$statements->isEmpty()) { |
|
100 | + $applicableDumps = $this->getApplicableDumps($entityStatements); |
|
101 | + foreach ($applicableDumps as $identifierPropertyId => $dumpMetaInformationList) { |
|
102 | + $identifierPropertyId = new PropertyId($identifierPropertyId); |
|
103 | 103 | |
104 | - if ( $this->isIdentifierProperty( $identifierPropertyId ) ) { |
|
104 | + if ($this->isIdentifierProperty($identifierPropertyId)) { |
|
105 | 105 | $resultList->merge( |
106 | 106 | $this->crossCheckStatementsWithIdentifier( |
107 | 107 | $entityStatements, |
@@ -124,17 +124,17 @@ discard block |
||
124 | 124 | * |
125 | 125 | * @return array[] |
126 | 126 | */ |
127 | - private function getApplicableDumps( StatementList $statements ) { |
|
127 | + private function getApplicableDumps(StatementList $statements) { |
|
128 | 128 | $applicableDumps = []; |
129 | 129 | $identifierPropertyIds = $statements->getPropertyIds(); |
130 | 130 | $dumpMetaInformation = $this->dumpMetaInformationLookup->getWithIdentifierProperties( |
131 | 131 | $identifierPropertyIds |
132 | 132 | ); |
133 | 133 | |
134 | - foreach ( $dumpMetaInformation as $dump ) { |
|
135 | - foreach ( $dump->getIdentifierPropertyIds() as $identifierPropertyId ) { |
|
134 | + foreach ($dumpMetaInformation as $dump) { |
|
135 | + foreach ($dump->getIdentifierPropertyIds() as $identifierPropertyId) { |
|
136 | 136 | $serialization = $identifierPropertyId->getSerialization(); |
137 | - $applicableDumps[ $serialization ][ $dump->getDumpId() ] = $dump; |
|
137 | + $applicableDumps[$serialization][$dump->getDumpId()] = $dump; |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
@@ -159,36 +159,36 @@ discard block |
||
159 | 159 | ) { |
160 | 160 | $resultList = new CrossCheckResultList(); |
161 | 161 | |
162 | - $externalIds = $this->getExternalIds( $entityStatements, $identifierPropertyId ); |
|
163 | - if ( !$externalIds ) { |
|
162 | + $externalIds = $this->getExternalIds($entityStatements, $identifierPropertyId); |
|
163 | + if (!$externalIds) { |
|
164 | 164 | return $resultList; |
165 | 165 | } |
166 | 166 | |
167 | 167 | $dumpIds = array_map( |
168 | - function ( DumpMetaInformation $dumpMetaInformation ) { |
|
168 | + function(DumpMetaInformation $dumpMetaInformation) { |
|
169 | 169 | return $dumpMetaInformation->getDumpId(); |
170 | 170 | }, |
171 | 171 | $dumpMetaInformationList |
172 | 172 | ); |
173 | - $externalData = $this->externalDataRepo->getExternalData( $dumpIds, $externalIds, $statements->getPropertyIds() ); |
|
173 | + $externalData = $this->externalDataRepo->getExternalData($dumpIds, $externalIds, $statements->getPropertyIds()); |
|
174 | 174 | |
175 | - foreach ( $externalData as $dumpId => $externalDataPerDump ) { |
|
176 | - $dumpMetaInformation = $dumpMetaInformationList[ $dumpId ]; |
|
175 | + foreach ($externalData as $dumpId => $externalDataPerDump) { |
|
176 | + $dumpMetaInformation = $dumpMetaInformationList[$dumpId]; |
|
177 | 177 | $comparativeValueParser = $this->valueParserFactory->newComparativeValueParser( |
178 | 178 | $dumpMetaInformation->getLanguageCode() |
179 | 179 | ); |
180 | 180 | |
181 | - foreach ( $externalDataPerDump as $externalId => $externalDataPerId ) { |
|
181 | + foreach ($externalDataPerDump as $externalId => $externalDataPerId) { |
|
182 | 182 | $externalId = (string)$externalId; |
183 | - foreach ( $externalDataPerId as $propertyId => $externalValues ) { |
|
184 | - $propertyId = new PropertyId( $propertyId ); |
|
183 | + foreach ($externalDataPerId as $propertyId => $externalValues) { |
|
184 | + $propertyId = new PropertyId($propertyId); |
|
185 | 185 | $resultList->merge( |
186 | 186 | $this->crossCheckExternalValues( |
187 | 187 | $dumpMetaInformation, |
188 | 188 | $identifierPropertyId, |
189 | 189 | $externalId, |
190 | 190 | $externalValues, |
191 | - $statements->getByPropertyId( $propertyId ), |
|
191 | + $statements->getByPropertyId($propertyId), |
|
192 | 192 | $comparativeValueParser |
193 | 193 | ) |
194 | 194 | ); |
@@ -219,10 +219,10 @@ discard block |
||
219 | 219 | ) { |
220 | 220 | $resultList = new CrossCheckResultList(); |
221 | 221 | |
222 | - foreach ( $statements->toArray() as $statement ) { |
|
223 | - $comparisonResult = $this->compareStatement( $statement, $externalValues, $comparativeValueParser ); |
|
222 | + foreach ($statements->toArray() as $statement) { |
|
223 | + $comparisonResult = $this->compareStatement($statement, $externalValues, $comparativeValueParser); |
|
224 | 224 | |
225 | - if ( $comparisonResult ) { |
|
225 | + if ($comparisonResult) { |
|
226 | 226 | $referencesResult = $this->referenceHandler->checkForReferences( |
227 | 227 | $statement, |
228 | 228 | $identifierPropertyId, |
@@ -256,31 +256,31 @@ discard block |
||
256 | 256 | * @return ComparisonResult|bool |
257 | 257 | */ |
258 | 258 | private function compareStatement( |
259 | - Statement $statement,array $externalValues, |
|
259 | + Statement $statement, array $externalValues, |
|
260 | 260 | ComparativeValueParser $comparativeValueParser |
261 | 261 | ) { |
262 | 262 | $mainSnak = $statement->getMainSnak(); |
263 | - if ( $mainSnak instanceof PropertyValueSnak ) { |
|
263 | + if ($mainSnak instanceof PropertyValueSnak) { |
|
264 | 264 | $dataValue = $mainSnak->getDataValue(); |
265 | 265 | |
266 | 266 | $results = []; |
267 | - $comparativeValues = $this->parseExternalValues( $dataValue, $externalValues, $comparativeValueParser ); |
|
268 | - foreach ( $comparativeValues as $comparativeValue ) { |
|
269 | - $result = $this->dataValueComparer->compare( $dataValue, $comparativeValue ); |
|
270 | - if ( $result ) { |
|
267 | + $comparativeValues = $this->parseExternalValues($dataValue, $externalValues, $comparativeValueParser); |
|
268 | + foreach ($comparativeValues as $comparativeValue) { |
|
269 | + $result = $this->dataValueComparer->compare($dataValue, $comparativeValue); |
|
270 | + if ($result) { |
|
271 | 271 | $results[] = $result; |
272 | 272 | } |
273 | 273 | } |
274 | 274 | |
275 | - if ( $results ) { |
|
275 | + if ($results) { |
|
276 | 276 | $result = ComparisonResult::STATUS_MISMATCH; |
277 | - if ( in_array( ComparisonResult::STATUS_MATCH, $results ) ) { |
|
277 | + if (in_array(ComparisonResult::STATUS_MATCH, $results)) { |
|
278 | 278 | $result = ComparisonResult::STATUS_MATCH; |
279 | - } elseif ( in_array( ComparisonResult::STATUS_PARTIAL_MATCH, $results ) ) { |
|
279 | + } elseif (in_array(ComparisonResult::STATUS_PARTIAL_MATCH, $results)) { |
|
280 | 280 | $result = ComparisonResult::STATUS_PARTIAL_MATCH; |
281 | 281 | } |
282 | 282 | |
283 | - return new ComparisonResult( $dataValue, $comparativeValues, $result ); |
|
283 | + return new ComparisonResult($dataValue, $comparativeValues, $result); |
|
284 | 284 | } |
285 | 285 | } |
286 | 286 | |
@@ -300,13 +300,13 @@ discard block |
||
300 | 300 | ComparativeValueParser $comparativeValueParser |
301 | 301 | ) { |
302 | 302 | $parsedValues = []; |
303 | - foreach ( $externalValues as $externalValue ) { |
|
303 | + foreach ($externalValues as $externalValue) { |
|
304 | 304 | try { |
305 | - $parsedValue = $comparativeValueParser->parse( $externalValue, $dataValue->getType() ); |
|
306 | - if ( $parsedValue ) { |
|
305 | + $parsedValue = $comparativeValueParser->parse($externalValue, $dataValue->getType()); |
|
306 | + if ($parsedValue) { |
|
307 | 307 | $parsedValues[] = $parsedValue; |
308 | 308 | } |
309 | - } catch ( ParseException $e ) { |
|
309 | + } catch (ParseException $e) { |
|
310 | 310 | } |
311 | 311 | } |
312 | 312 | |
@@ -321,12 +321,12 @@ discard block |
||
321 | 321 | * |
322 | 322 | * @return string[] |
323 | 323 | */ |
324 | - private function getExternalIds( StatementList $statements, PropertyId $identifierPropertyId ) { |
|
324 | + private function getExternalIds(StatementList $statements, PropertyId $identifierPropertyId) { |
|
325 | 325 | $externalIds = []; |
326 | - $identifierStatements = $statements->getByPropertyId( $identifierPropertyId ); |
|
327 | - $values = $this->getDataValues( $identifierStatements ); |
|
328 | - foreach ( $values as $value ) { |
|
329 | - if ( $value instanceof StringValue ) { |
|
326 | + $identifierStatements = $statements->getByPropertyId($identifierPropertyId); |
|
327 | + $values = $this->getDataValues($identifierStatements); |
|
328 | + foreach ($values as $value) { |
|
329 | + if ($value instanceof StringValue) { |
|
330 | 330 | $externalIds[] = $value->getValue(); |
331 | 331 | } |
332 | 332 | } |
@@ -338,15 +338,15 @@ discard block |
||
338 | 338 | * @param PropertyId $identifierPropertyId |
339 | 339 | * @return bool |
340 | 340 | */ |
341 | - private function isIdentifierProperty( PropertyId $identifierPropertyId ) { |
|
341 | + private function isIdentifierProperty(PropertyId $identifierPropertyId) { |
|
342 | 342 | global $wgWBQEVInstanceOfPID, $wgWBQEVIdentifierPropertyQID; |
343 | 343 | /** @var Property $property */ |
344 | - $property = $this->entityLookup->getEntity( $identifierPropertyId ); |
|
345 | - $instanceOfPropertyId = new PropertyId( $wgWBQEVInstanceOfPID ); |
|
346 | - $statements = $property->getStatements()->getByPropertyId( $instanceOfPropertyId ); |
|
347 | - $values = $this->getDataValues( $statements ); |
|
348 | - foreach ( $values as $value ) { |
|
349 | - if ( $value instanceof EntityIdValue |
|
344 | + $property = $this->entityLookup->getEntity($identifierPropertyId); |
|
345 | + $instanceOfPropertyId = new PropertyId($wgWBQEVInstanceOfPID); |
|
346 | + $statements = $property->getStatements()->getByPropertyId($instanceOfPropertyId); |
|
347 | + $values = $this->getDataValues($statements); |
|
348 | + foreach ($values as $value) { |
|
349 | + if ($value instanceof EntityIdValue |
|
350 | 350 | && $value->getEntityId()->getSerialization() === $wgWBQEVIdentifierPropertyQID |
351 | 351 | ) { |
352 | 352 | return true; |
@@ -362,12 +362,12 @@ discard block |
||
362 | 362 | * @param StatementList $statementList |
363 | 363 | * @return DataValue[] |
364 | 364 | */ |
365 | - private function getDataValues( StatementList $statementList ) { |
|
365 | + private function getDataValues(StatementList $statementList) { |
|
366 | 366 | $dataValues = []; |
367 | 367 | |
368 | - foreach ( $statementList->toArray() as $statement ) { |
|
368 | + foreach ($statementList->toArray() as $statement) { |
|
369 | 369 | $mainSnak = $statement->getMainSnak(); |
370 | - if ( $mainSnak instanceof PropertyValueSnak ) { |
|
370 | + if ($mainSnak instanceof PropertyValueSnak) { |
|
371 | 371 | $dataValues[] = $mainSnak->getDataValue(); |
372 | 372 | } |
373 | 373 | } |
@@ -39,16 +39,16 @@ discard block |
||
39 | 39 | $externalId, |
40 | 40 | DumpMetaInformation $dumpMetaInformation |
41 | 41 | ) { |
42 | - Assert::parameterType( 'string', $externalId, '$externalId' ); |
|
42 | + Assert::parameterType('string', $externalId, '$externalId'); |
|
43 | 43 | |
44 | - if ( $statement->getReferences()->isEmpty() ) { |
|
44 | + if ($statement->getReferences()->isEmpty()) { |
|
45 | 45 | $status = ReferenceResult::STATUS_REFERENCES_MISSING; |
46 | 46 | } else { |
47 | 47 | $status = ReferenceResult::STATUS_REFERENCES_STATED; |
48 | 48 | } |
49 | 49 | |
50 | - $externalReference = $this->buildReference( $identifierPropertyId, $externalId, $dumpMetaInformation ); |
|
51 | - return new ReferenceResult( $status, $externalReference ); |
|
50 | + $externalReference = $this->buildReference($identifierPropertyId, $externalId, $dumpMetaInformation); |
|
51 | + return new ReferenceResult($status, $externalReference); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -59,17 +59,17 @@ discard block |
||
59 | 59 | * @param DumpMetaInformation $dumpMetaInformation |
60 | 60 | * @return Reference |
61 | 61 | */ |
62 | - private function buildReference( PropertyId $identifierPropertyId, $externalId, DumpMetaInformation $dumpMetaInformation ) { |
|
62 | + private function buildReference(PropertyId $identifierPropertyId, $externalId, DumpMetaInformation $dumpMetaInformation) { |
|
63 | 63 | global $wgWBQEVStatedInPID; |
64 | 64 | |
65 | 65 | $sourceItemId = $dumpMetaInformation->getSourceItemId(); |
66 | 66 | $statedInAuthoritySnak = new PropertyValueSnak( |
67 | - new PropertyId( $wgWBQEVStatedInPID ), |
|
68 | - new EntityIdValue( $sourceItemId ) |
|
67 | + new PropertyId($wgWBQEVStatedInPID), |
|
68 | + new EntityIdValue($sourceItemId) |
|
69 | 69 | ); |
70 | 70 | $authorityWithExternalIdSnak = new PropertyValueSnak( |
71 | 71 | $identifierPropertyId, |
72 | - new StringValue( $externalId ) |
|
72 | + new StringValue($externalId) |
|
73 | 73 | ); |
74 | 74 | |
75 | 75 | return new Reference( |