@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | */ |
19 | 19 | private $crossCheckResultSerializer; |
20 | 20 | |
21 | - public function __construct( Serializer $crossCheckResultSerializer ) { |
|
21 | + public function __construct(Serializer $crossCheckResultSerializer) { |
|
22 | 22 | $this->crossCheckResultSerializer = $crossCheckResultSerializer; |
23 | 23 | } |
24 | 24 | |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @return bool |
31 | 31 | */ |
32 | - public function isSerializerFor( $object ) { |
|
32 | + public function isSerializerFor($object) { |
|
33 | 33 | return $object instanceof CrossCheckResultList; |
34 | 34 | } |
35 | 35 | |
@@ -41,29 +41,29 @@ discard block |
||
41 | 41 | * @return array |
42 | 42 | * @throws UnsupportedObjectException |
43 | 43 | */ |
44 | - public function serialize( $object ) { |
|
45 | - if ( !$this->isSerializerFor( $object ) ) { |
|
44 | + public function serialize($object) { |
|
45 | + if (!$this->isSerializerFor($object)) { |
|
46 | 46 | throw new UnsupportedObjectException( |
47 | 47 | $object, |
48 | 48 | 'CrossCheckResultListSerializer can only serialize CrossCheckResultList objects.' |
49 | 49 | ); |
50 | 50 | } |
51 | 51 | |
52 | - return $this->getSerialized( $object ); |
|
52 | + return $this->getSerialized($object); |
|
53 | 53 | } |
54 | 54 | |
55 | - private function getSerialized( CrossCheckResultList $resultList ) { |
|
55 | + private function getSerialized(CrossCheckResultList $resultList) { |
|
56 | 56 | $serialization = []; |
57 | - $this->setKeyAttributeName( $serialization, 'property', 'id' ); |
|
57 | + $this->setKeyAttributeName($serialization, 'property', 'id'); |
|
58 | 58 | |
59 | - foreach ( $resultList->getPropertyIds() as $propertyId ) { |
|
59 | + foreach ($resultList->getPropertyIds() as $propertyId) { |
|
60 | 60 | $id = $propertyId->getSerialization(); |
61 | 61 | $resultSerialization = []; |
62 | 62 | |
63 | - $this->setIndexedTagName( $resultSerialization, 'result' ); |
|
63 | + $this->setIndexedTagName($resultSerialization, 'result'); |
|
64 | 64 | |
65 | - foreach ( $resultList->getByPropertyId( $propertyId ) as $result ) { |
|
66 | - $resultSerialization[] = $this->crossCheckResultSerializer->serialize( $result ); |
|
65 | + foreach ($resultList->getByPropertyId($propertyId) as $result) { |
|
66 | + $resultSerialization[] = $this->crossCheckResultSerializer->serialize($result); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | $serialization[$id] = $resultSerialization; |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | */ |
19 | 19 | private $referenceSerializer; |
20 | 20 | |
21 | - public function __construct( Serializer $referenceSerializer ) { |
|
21 | + public function __construct(Serializer $referenceSerializer) { |
|
22 | 22 | $this->referenceSerializer = $referenceSerializer; |
23 | 23 | } |
24 | 24 | |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @return bool |
31 | 31 | */ |
32 | - public function isSerializerFor( $object ) { |
|
32 | + public function isSerializerFor($object) { |
|
33 | 33 | return $object instanceof ReferenceResult; |
34 | 34 | } |
35 | 35 | |
@@ -41,20 +41,20 @@ discard block |
||
41 | 41 | * @return array |
42 | 42 | * @throws UnsupportedObjectException |
43 | 43 | */ |
44 | - public function serialize( $object ) { |
|
45 | - if ( !$this->isSerializerFor( $object ) ) { |
|
44 | + public function serialize($object) { |
|
45 | + if (!$this->isSerializerFor($object)) { |
|
46 | 46 | throw new UnsupportedObjectException( |
47 | 47 | $object, |
48 | 48 | 'ReferenceResultSerializer can only serialize ReferenceResult objects.' |
49 | 49 | ); |
50 | 50 | } |
51 | 51 | |
52 | - return $this->getSerialized( $object ); |
|
52 | + return $this->getSerialized($object); |
|
53 | 53 | } |
54 | 54 | |
55 | - private function getSerialized( ReferenceResult $referenceResult ) { |
|
55 | + private function getSerialized(ReferenceResult $referenceResult) { |
|
56 | 56 | return [ |
57 | - 'reference' => $this->referenceSerializer->serialize( $referenceResult->getReference() ), |
|
57 | + 'reference' => $this->referenceSerializer->serialize($referenceResult->getReference()), |
|
58 | 58 | 'status' => $referenceResult->getStatus() |
59 | 59 | ]; |
60 | 60 | } |
@@ -15,10 +15,10 @@ |
||
15 | 15 | * |
16 | 16 | * @return bool |
17 | 17 | */ |
18 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
19 | - $updater->addExtensionTable( 'wbqev_dump_information', __DIR__ . '/sql/create_wbqev_dump_information.sql' ); |
|
20 | - $updater->addExtensionTable( 'wbqev_external_data', __DIR__ . '/sql/create_wbqev_external_data.sql' ); |
|
21 | - $updater->addExtensionTable( 'wbqev_identifier_properties', __DIR__ . '/sql/create_wbqev_identifier_properties.sql' ); |
|
18 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
19 | + $updater->addExtensionTable('wbqev_dump_information', __DIR__.'/sql/create_wbqev_dump_information.sql'); |
|
20 | + $updater->addExtensionTable('wbqev_external_data', __DIR__.'/sql/create_wbqev_external_data.sql'); |
|
21 | + $updater->addExtensionTable('wbqev_identifier_properties', __DIR__.'/sql/create_wbqev_identifier_properties.sql'); |
|
22 | 22 | |
23 | 23 | return true; |
24 | 24 | } |
@@ -28,18 +28,18 @@ discard block |
||
28 | 28 | * @return DumpMetaInformation[] |
29 | 29 | * @throws InvalidArgumentException |
30 | 30 | */ |
31 | - public function getWithIds( array $dumpIds ) { |
|
32 | - if ( $dumpIds === [] ) { |
|
31 | + public function getWithIds(array $dumpIds) { |
|
32 | + if ($dumpIds === []) { |
|
33 | 33 | return []; |
34 | 34 | } |
35 | 35 | |
36 | - foreach ( $dumpIds as $dumpId ) { |
|
37 | - if ( !is_string( $dumpId ) ) { |
|
38 | - throw new InvalidArgumentException( '$dumpIds must contain only strings.' ); |
|
36 | + foreach ($dumpIds as $dumpId) { |
|
37 | + if (!is_string($dumpId)) { |
|
38 | + throw new InvalidArgumentException('$dumpIds must contain only strings.'); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
42 | - $db = wfGetDB( DB_REPLICA ); |
|
42 | + $db = wfGetDB(DB_REPLICA); |
|
43 | 43 | $result = $db->select( |
44 | 44 | [ |
45 | 45 | self::META_TABLE_NAME, |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | ] |
60 | 60 | ); |
61 | 61 | |
62 | - return $this->buildDumpMetaInformationFromResult( $result ); |
|
62 | + return $this->buildDumpMetaInformationFromResult($result); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -71,20 +71,20 @@ discard block |
||
71 | 71 | * @throws InvalidArgumentException |
72 | 72 | * @return DumpMetaInformation[] |
73 | 73 | */ |
74 | - public function getWithIdentifierProperties( array $identifierPropertyIds ) { |
|
75 | - if ( $identifierPropertyIds === [] ) { |
|
74 | + public function getWithIdentifierProperties(array $identifierPropertyIds) { |
|
75 | + if ($identifierPropertyIds === []) { |
|
76 | 76 | return []; |
77 | 77 | } |
78 | 78 | |
79 | - foreach ( $identifierPropertyIds as $propertyId ) { |
|
80 | - if ( !( $propertyId instanceof PropertyId ) ) { |
|
81 | - throw new InvalidArgumentException( '$identifierProperties must contain only PropertyIds.' ); |
|
79 | + foreach ($identifierPropertyIds as $propertyId) { |
|
80 | + if (!($propertyId instanceof PropertyId)) { |
|
81 | + throw new InvalidArgumentException('$identifierProperties must contain only PropertyIds.'); |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
85 | - $db = wfGetDB( DB_REPLICA ); |
|
85 | + $db = wfGetDB(DB_REPLICA); |
|
86 | 86 | $identifierPropertyIds = array_map( |
87 | - function( PropertyId $id ) { |
|
87 | + function(PropertyId $id) { |
|
88 | 88 | return $id->getSerialization(); |
89 | 89 | }, |
90 | 90 | $identifierPropertyIds |
@@ -97,13 +97,13 @@ discard block |
||
97 | 97 | ] |
98 | 98 | ); |
99 | 99 | $dumpIds = []; |
100 | - foreach ( $result as $row ) { |
|
101 | - if ( !in_array( $row->dump_id, $dumpIds ) ) { |
|
100 | + foreach ($result as $row) { |
|
101 | + if (!in_array($row->dump_id, $dumpIds)) { |
|
102 | 102 | $dumpIds[] = $row->dump_id; |
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
106 | - return $this->getWithIds( $dumpIds ); |
|
106 | + return $this->getWithIds($dumpIds); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * @return DumpMetaInformation[] |
114 | 114 | */ |
115 | 115 | public function getAll() { |
116 | - $db = wfGetDB( DB_REPLICA ); |
|
116 | + $db = wfGetDB(DB_REPLICA); |
|
117 | 117 | $result = $db->select( |
118 | 118 | [ |
119 | 119 | self::META_TABLE_NAME, |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | ] |
132 | 132 | ); |
133 | 133 | |
134 | - return $this->buildDumpMetaInformationFromResult( $result ); |
|
134 | + return $this->buildDumpMetaInformationFromResult($result); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -139,34 +139,34 @@ discard block |
||
139 | 139 | * @return null|array |
140 | 140 | * @throws UnexpectedValueException |
141 | 141 | */ |
142 | - private function buildDumpMetaInformationFromResult( IResultWrapper $result ) { |
|
142 | + private function buildDumpMetaInformationFromResult(IResultWrapper $result) { |
|
143 | 143 | $aggregatedRows = []; |
144 | - foreach ( $result as $row ) { |
|
145 | - if ( array_key_exists( $row->id, $aggregatedRows ) ) { |
|
146 | - $propertyId = new PropertyId( $row->identifier_pid ); |
|
144 | + foreach ($result as $row) { |
|
145 | + if (array_key_exists($row->id, $aggregatedRows)) { |
|
146 | + $propertyId = new PropertyId($row->identifier_pid); |
|
147 | 147 | $aggregatedRows[$row->id]->identifier_pid[] = $propertyId; |
148 | 148 | } else { |
149 | - if ( $row->identifier_pid !== null ) { |
|
150 | - $propertyId = new PropertyId( $row->identifier_pid ); |
|
151 | - $row->identifier_pid = [ $propertyId ]; |
|
149 | + if ($row->identifier_pid !== null) { |
|
150 | + $propertyId = new PropertyId($row->identifier_pid); |
|
151 | + $row->identifier_pid = [$propertyId]; |
|
152 | 152 | } |
153 | 153 | $aggregatedRows[$row->id] = $row; |
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
157 | 157 | $dumpMetaInformation = []; |
158 | - foreach ( $aggregatedRows as $row ) { |
|
158 | + foreach ($aggregatedRows as $row) { |
|
159 | 159 | $dumpId = $row->id; |
160 | - $sourceItemId = new ItemId( $row->source_qid ); |
|
161 | - $importDate = wfTimestamp( TS_MW, $row->import_date ); |
|
160 | + $sourceItemId = new ItemId($row->source_qid); |
|
161 | + $importDate = wfTimestamp(TS_MW, $row->import_date); |
|
162 | 162 | $language = $row->language; |
163 | 163 | $sourceUrl = $row->source_url; |
164 | 164 | $size = (int)$row->size; |
165 | - $licenseItemId = new ItemId( $row->license_qid ); |
|
165 | + $licenseItemId = new ItemId($row->license_qid); |
|
166 | 166 | $identifierPropertyIds = $row->identifier_pid; |
167 | 167 | |
168 | 168 | $dumpMetaInformation[$row->dump_id] = |
169 | - new DumpMetaInformation( $dumpId, |
|
169 | + new DumpMetaInformation($dumpId, |
|
170 | 170 | $sourceItemId, |
171 | 171 | $identifierPropertyIds, |
172 | 172 | $importDate, |
@@ -185,22 +185,22 @@ discard block |
||
185 | 185 | * |
186 | 186 | * @param DumpMetaInformation $dumpMetaInformation |
187 | 187 | */ |
188 | - public function save( DumpMetaInformation $dumpMetaInformation ) { |
|
189 | - $db = wfGetDB( DB_REPLICA ); |
|
188 | + public function save(DumpMetaInformation $dumpMetaInformation) { |
|
189 | + $db = wfGetDB(DB_REPLICA); |
|
190 | 190 | $dumpId = $dumpMetaInformation->getDumpId(); |
191 | - $accumulator = $this->getDumpInformationFields( $db, $dumpMetaInformation ); |
|
191 | + $accumulator = $this->getDumpInformationFields($db, $dumpMetaInformation); |
|
192 | 192 | |
193 | 193 | $existing = $db->selectRow( |
194 | 194 | self::META_TABLE_NAME, |
195 | - [ 'id' ], |
|
196 | - [ 'id' => $dumpId ] |
|
195 | + ['id'], |
|
196 | + ['id' => $dumpId] |
|
197 | 197 | ); |
198 | 198 | |
199 | - if ( $existing ) { |
|
199 | + if ($existing) { |
|
200 | 200 | $db->update( |
201 | 201 | self::META_TABLE_NAME, |
202 | 202 | $accumulator, |
203 | - [ 'id' => $dumpId ] |
|
203 | + ['id' => $dumpId] |
|
204 | 204 | ); |
205 | 205 | } else { |
206 | 206 | $db->insert( |
@@ -211,12 +211,12 @@ discard block |
||
211 | 211 | |
212 | 212 | $db->delete( |
213 | 213 | self::IDENTIFIER_PROPERTIES_TABLE_NAME, |
214 | - [ 'dump_id' => $dumpId ] |
|
214 | + ['dump_id' => $dumpId] |
|
215 | 215 | ); |
216 | 216 | $db->insert( |
217 | 217 | self::IDENTIFIER_PROPERTIES_TABLE_NAME, |
218 | 218 | array_map( |
219 | - function ( PropertyId $identifierPropertyId ) use ( $dumpId ) { |
|
219 | + function(PropertyId $identifierPropertyId) use ($dumpId) { |
|
220 | 220 | return [ |
221 | 221 | 'dump_id' => $dumpId, |
222 | 222 | 'identifier_pid' => $identifierPropertyId->getSerialization() |
@@ -232,11 +232,11 @@ discard block |
||
232 | 232 | * @param DumpMetaInformation $dumpMetaInformation |
233 | 233 | * @return array |
234 | 234 | */ |
235 | - private function getDumpInformationFields( IDatabase $db, DumpMetaInformation $dumpMetaInformation ) { |
|
235 | + private function getDumpInformationFields(IDatabase $db, DumpMetaInformation $dumpMetaInformation) { |
|
236 | 236 | return [ |
237 | 237 | 'id' => $dumpMetaInformation->getDumpId(), |
238 | 238 | 'source_qid' => $dumpMetaInformation->getSourceItemId()->getSerialization(), |
239 | - 'import_date' => $db->timestamp( $dumpMetaInformation->getImportDate() ), |
|
239 | + 'import_date' => $db->timestamp($dumpMetaInformation->getImportDate()), |
|
240 | 240 | 'language' => $dumpMetaInformation->getLanguageCode(), |
241 | 241 | 'source_url' => $dumpMetaInformation->getSourceUrl(), |
242 | 242 | 'size' => $dumpMetaInformation->getSize(), |
@@ -172,7 +172,7 @@ |
||
172 | 172 | /** |
173 | 173 | * Writes output for CrossCheckResultList |
174 | 174 | * |
175 | - * @param array $resultLists |
|
175 | + * @param \WikibaseQuality\ExternalValidation\CrossCheck\Result\CrossCheckResultList[] $resultLists |
|
176 | 176 | */ |
177 | 177 | private function writeResultOutput( array $resultLists ) { |
178 | 178 | $serializer = $this->serializerFactory->newCrossCheckResultListSerializer(); |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @return self |
66 | 66 | */ |
67 | - public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) { |
|
67 | + public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') { |
|
68 | 68 | $repo = WikibaseRepo::getDefaultInstance(); |
69 | 69 | $externalValidationServices = ExternalValidationServices::getDefaultInstance(); |
70 | 70 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | $repo->getStatementGuidValidator(), |
77 | 77 | $externalValidationServices->getCrossCheckInteractor(), |
78 | 78 | $externalValidationServices->getSerializerFactory(), |
79 | - $repo->getApiHelperFactory( RequestContext::getMain() ) |
|
79 | + $repo->getApiHelperFactory(RequestContext::getMain()) |
|
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
@@ -100,14 +100,14 @@ discard block |
||
100 | 100 | SerializerFactory $serializerFactory, |
101 | 101 | ApiHelperFactory $apiHelperFactory |
102 | 102 | ) { |
103 | - parent::__construct( $main, $name, $prefix ); |
|
103 | + parent::__construct($main, $name, $prefix); |
|
104 | 104 | |
105 | 105 | $this->entityIdParser = $entityIdParser; |
106 | 106 | $this->statementGuidValidator = $statementGuidValidator; |
107 | 107 | $this->crossCheckInteractor = $crossCheckInteractor; |
108 | 108 | $this->serializerFactory = $serializerFactory; |
109 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
110 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
109 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
110 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -116,34 +116,34 @@ discard block |
||
116 | 116 | public function execute() { |
117 | 117 | $params = $this->extractRequestParams(); |
118 | 118 | |
119 | - if ( $params['entities'] && $params['claims'] ) { |
|
119 | + if ($params['entities'] && $params['claims']) { |
|
120 | 120 | $this->errorReporter->dieError( |
121 | 121 | 'Either provide the ids of entities or ids of claims, that should be cross-checked.', |
122 | 122 | 'param-invalid' |
123 | 123 | ); |
124 | 124 | throw new LogicException(); |
125 | - } elseif ( $params['entities'] ) { |
|
126 | - $entityIds = $this->parseEntityIds( $params['entities'] ); |
|
127 | - if ( $params['properties'] ) { |
|
128 | - $propertyIds = $this->parseEntityIds( $params['properties'] ); |
|
129 | - $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIdWithProperties( $entityIds, $propertyIds ); |
|
125 | + } elseif ($params['entities']) { |
|
126 | + $entityIds = $this->parseEntityIds($params['entities']); |
|
127 | + if ($params['properties']) { |
|
128 | + $propertyIds = $this->parseEntityIds($params['properties']); |
|
129 | + $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIdWithProperties($entityIds, $propertyIds); |
|
130 | 130 | } else { |
131 | - $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIds( $entityIds ); |
|
131 | + $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIds($entityIds); |
|
132 | 132 | } |
133 | - } elseif ( $params['claims'] ) { |
|
133 | + } elseif ($params['claims']) { |
|
134 | 134 | $guids = $params['claims']; |
135 | - $this->assertAreValidClaimGuids( $guids ); |
|
136 | - $resultLists = $this->crossCheckInteractor->crossCheckStatementsByGuids( $guids ); |
|
135 | + $this->assertAreValidClaimGuids($guids); |
|
136 | + $resultLists = $this->crossCheckInteractor->crossCheckStatementsByGuids($guids); |
|
137 | 137 | } else { |
138 | 138 | $this->errorReporter->dieWithError( |
139 | - [ 'wikibase-api-param-missing', 'entities|claims' ], |
|
139 | + ['wikibase-api-param-missing', 'entities|claims'], |
|
140 | 140 | 'param-missing' |
141 | 141 | ); |
142 | 142 | throw new LogicException(); |
143 | 143 | } |
144 | 144 | |
145 | 145 | // Print result lists |
146 | - $this->writeResultOutput( $resultLists ); |
|
146 | + $this->writeResultOutput($resultLists); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -151,9 +151,9 @@ discard block |
||
151 | 151 | * |
152 | 152 | * @return EntityId[] |
153 | 153 | */ |
154 | - private function parseEntityIds( array $entityIds ) { |
|
154 | + private function parseEntityIds(array $entityIds) { |
|
155 | 155 | return array_map( |
156 | - [ $this->entityIdParser, 'parse' ], |
|
156 | + [$this->entityIdParser, 'parse'], |
|
157 | 157 | $entityIds |
158 | 158 | ); |
159 | 159 | } |
@@ -161,10 +161,10 @@ discard block |
||
161 | 161 | /** |
162 | 162 | * @param string[] $guids |
163 | 163 | */ |
164 | - private function assertAreValidClaimGuids( array $guids ) { |
|
165 | - foreach ( $guids as $guid ) { |
|
166 | - if ( $this->statementGuidValidator->validateFormat( $guid ) === false ) { |
|
167 | - $this->errorReporter->dieError( 'Invalid claim guid.', 'invalid-guid' ); |
|
164 | + private function assertAreValidClaimGuids(array $guids) { |
|
165 | + foreach ($guids as $guid) { |
|
166 | + if ($this->statementGuidValidator->validateFormat($guid) === false) { |
|
167 | + $this->errorReporter->dieError('Invalid claim guid.', 'invalid-guid'); |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | } |
@@ -174,13 +174,13 @@ discard block |
||
174 | 174 | * |
175 | 175 | * @param array $resultLists |
176 | 176 | */ |
177 | - private function writeResultOutput( array $resultLists ) { |
|
177 | + private function writeResultOutput(array $resultLists) { |
|
178 | 178 | $serializer = $this->serializerFactory->newCrossCheckResultListSerializer(); |
179 | 179 | |
180 | 180 | $output = []; |
181 | - foreach ( $resultLists as $entityId => $resultList ) { |
|
182 | - if ( $resultList ) { |
|
183 | - $serializedResultList = $serializer->serialize( $resultList ); |
|
181 | + foreach ($resultLists as $entityId => $resultList) { |
|
182 | + if ($resultList) { |
|
183 | + $serializedResultList = $serializer->serialize($resultList); |
|
184 | 184 | |
185 | 185 | $output[$entityId] = $serializedResultList; |
186 | 186 | } else { |
@@ -190,10 +190,10 @@ discard block |
||
190 | 190 | } |
191 | 191 | } |
192 | 192 | |
193 | - $this->getResult()->setIndexedTagName( $output, 'entity' ); |
|
194 | - $this->getResult()->setArrayType( $output, 'kvp', 'id' ); |
|
195 | - $this->getResult()->addValue( null, 'results', $output ); |
|
196 | - $this->resultBuilder->markSuccess( 1 ); |
|
193 | + $this->getResult()->setIndexedTagName($output, 'entity'); |
|
194 | + $this->getResult()->setArrayType($output, 'kvp', 'id'); |
|
195 | + $this->getResult()->addValue(null, 'results', $output); |
|
196 | + $this->resultBuilder->markSuccess(1); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -1,11 +1,11 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( function_exists( 'wfLoadExtension' ) ) { |
|
4 | - wfLoadExtension( 'WikibaseQualityExternalValidation', __DIR__ . '/extension.json' ); |
|
3 | +if (function_exists('wfLoadExtension')) { |
|
4 | + wfLoadExtension('WikibaseQualityExternalValidation', __DIR__.'/extension.json'); |
|
5 | 5 | // Keep i18n globals so mergeMessageFileList.php doesn't break |
6 | - $GLOBALS['wgMessagesDirs']['WikibaseQualityExternalValidation'] = __DIR__ . '/i18n'; |
|
6 | + $GLOBALS['wgMessagesDirs']['WikibaseQualityExternalValidation'] = __DIR__.'/i18n'; |
|
7 | 7 | $GLOBALS['wgExtensionMessagesFiles']['WikibaseQualityExternalValidationAlias'] = |
8 | - __DIR__ . '/WikibaseQualityExternalValidation.alias.php'; |
|
8 | + __DIR__.'/WikibaseQualityExternalValidation.alias.php'; |
|
9 | 9 | /* wfWarn( |
10 | 10 | 'Deprecated PHP entry point used for WikibaseQualityConstraints extension. ' . |
11 | 11 | 'Please use wfLoadExtension instead, ' . |
@@ -13,5 +13,5 @@ discard block |
||
13 | 13 | ); */ |
14 | 14 | return; |
15 | 15 | } else { |
16 | - die( 'This version of the WikibaseQualityExternalValidation extension requires MediaWiki 1.25+' ); |
|
16 | + die('This version of the WikibaseQualityExternalValidation extension requires MediaWiki 1.25+'); |
|
17 | 17 | } |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | * @throws InvalidArgumentException |
30 | 30 | * @return string One of the ComparisonResult::STATUS_... constants. |
31 | 31 | */ |
32 | - public function compare( DataValue $value, DataValue $comparativeValue ) { |
|
33 | - if ( !$this->canCompare( $value, $comparativeValue ) ) { |
|
34 | - throw new InvalidArgumentException( 'Given values can not be compared using this comparer.' ); |
|
32 | + public function compare(DataValue $value, DataValue $comparativeValue) { |
|
33 | + if (!$this->canCompare($value, $comparativeValue)) { |
|
34 | + throw new InvalidArgumentException('Given values can not be compared using this comparer.'); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -41,15 +41,15 @@ discard block |
||
41 | 41 | |
42 | 42 | $result = ComparisonResult::STATUS_MISMATCH; |
43 | 43 | |
44 | - if ( !preg_match( '/^([-+]?)(\d*)((\d{4}\b).*)/', $value->getTime(), $localMatches ) |
|
45 | - || !preg_match( '/^([-+]?)(\d*)((\d{4}\b).*)/', $comparativeValue->getTime(), $externalMatches ) |
|
44 | + if (!preg_match('/^([-+]?)(\d*)((\d{4}\b).*)/', $value->getTime(), $localMatches) |
|
45 | + || !preg_match('/^([-+]?)(\d*)((\d{4}\b).*)/', $comparativeValue->getTime(), $externalMatches) |
|
46 | 46 | ) { |
47 | 47 | return ComparisonResult::STATUS_MISMATCH; |
48 | 48 | } |
49 | - list( , $localSign, $localYearHigh, $localMwTime, $localYearLow ) = $localMatches; |
|
50 | - list( , $externalSign, $externalYearHigh, $externalMwTime, $externalYearLow ) = $externalMatches; |
|
51 | - if ( $localSign !== $externalSign && ( $localYearHigh . $localYearLow !== '0000' |
|
52 | - || $externalYearHigh . $externalYearLow !== '0000' ) |
|
49 | + list(, $localSign, $localYearHigh, $localMwTime, $localYearLow) = $localMatches; |
|
50 | + list(, $externalSign, $externalYearHigh, $externalMwTime, $externalYearLow) = $externalMatches; |
|
51 | + if ($localSign !== $externalSign && ($localYearHigh.$localYearLow !== '0000' |
|
52 | + || $externalYearHigh.$externalYearLow !== '0000') |
|
53 | 53 | ) { |
54 | 54 | return ComparisonResult::STATUS_MISMATCH; |
55 | 55 | } |
@@ -58,24 +58,24 @@ discard block |
||
58 | 58 | $externalYearHigh = $externalYearHigh === '' ? 0 : (float)$externalYearHigh; |
59 | 59 | |
60 | 60 | try { |
61 | - $localTimestamp = new MWTimestamp( $localMwTime ); |
|
62 | - $externalTimestamp = new MWTimestamp( $externalMwTime ); |
|
63 | - $diff = $localTimestamp->diff( $externalTimestamp ); |
|
64 | - $diff->y += abs( $localYearHigh - $externalYearHigh ) * 10000; |
|
61 | + $localTimestamp = new MWTimestamp($localMwTime); |
|
62 | + $externalTimestamp = new MWTimestamp($externalMwTime); |
|
63 | + $diff = $localTimestamp->diff($externalTimestamp); |
|
64 | + $diff->y += abs($localYearHigh - $externalYearHigh) * 10000; |
|
65 | 65 | |
66 | - if ( $value->getPrecision() === $comparativeValue->getPrecision() |
|
67 | - && $this->resultOfDiffWithPrecision( $diff, $value->getPrecision() ) |
|
66 | + if ($value->getPrecision() === $comparativeValue->getPrecision() |
|
67 | + && $this->resultOfDiffWithPrecision($diff, $value->getPrecision()) |
|
68 | 68 | ) { |
69 | 69 | $result = ComparisonResult::STATUS_MATCH; |
70 | 70 | } elseif ( |
71 | 71 | $this->resultOfDiffWithPrecision( |
72 | 72 | $diff, |
73 | - min( $value->getPrecision(), $comparativeValue->getPrecision() ) |
|
73 | + min($value->getPrecision(), $comparativeValue->getPrecision()) |
|
74 | 74 | ) |
75 | 75 | ) { |
76 | 76 | $result = ComparisonResult::STATUS_PARTIAL_MATCH; |
77 | 77 | } |
78 | - } catch ( TimestampException $ex ) { |
|
78 | + } catch (TimestampException $ex) { |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | return $result; |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @return bool |
91 | 91 | */ |
92 | - private function resultOfDiffWithPrecision( DateInterval $diff, $precision ) { |
|
92 | + private function resultOfDiffWithPrecision(DateInterval $diff, $precision) { |
|
93 | 93 | $result = true; |
94 | 94 | |
95 | - switch ( $precision ) { |
|
95 | + switch ($precision) { |
|
96 | 96 | case TimeValue::PRECISION_SECOND: |
97 | 97 | $result = $diff->s === 0; |
98 | 98 | // Fall through with no break/return. This is critical for this algorithm. |
@@ -136,10 +136,10 @@ discard block |
||
136 | 136 | * |
137 | 137 | * @return ValueParser |
138 | 138 | */ |
139 | - protected function getExternalValueParser( DumpMetaInformation $dumpMetaInformation ) { |
|
139 | + protected function getExternalValueParser(DumpMetaInformation $dumpMetaInformation) { |
|
140 | 140 | $parserOptions = new ParserOptions(); |
141 | - $parserOptions->setOption( ValueParser::OPT_LANG, $dumpMetaInformation->getLanguageCode() ); |
|
142 | - $timeParserFactory = new TimeParserFactory( $parserOptions ); |
|
141 | + $parserOptions->setOption(ValueParser::OPT_LANG, $dumpMetaInformation->getLanguageCode()); |
|
142 | + $timeParserFactory = new TimeParserFactory($parserOptions); |
|
143 | 143 | |
144 | 144 | return $timeParserFactory->getTimeParser(); |
145 | 145 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * |
153 | 153 | * @return bool |
154 | 154 | */ |
155 | - public function canCompare( DataValue $value, DataValue $comparativeValue ) { |
|
155 | + public function canCompare(DataValue $value, DataValue $comparativeValue) { |
|
156 | 156 | return $value instanceof TimeValue && $comparativeValue instanceof TimeValue; |
157 | 157 | } |
158 | 158 |
@@ -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 | } |