@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * @param DataValueComparer[] $dataValueComparers |
22 | 22 | */ |
23 | - public function __construct( array $dataValueComparers = [] ) { |
|
24 | - $this->assertAreDataValueComparer( $dataValueComparers ); |
|
23 | + public function __construct(array $dataValueComparers = []) { |
|
24 | + $this->assertAreDataValueComparer($dataValueComparers); |
|
25 | 25 | $this->dataValueComparers = $dataValueComparers; |
26 | 26 | } |
27 | 27 | |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @throws InvalidArgumentException |
32 | 32 | */ |
33 | - protected function assertAreDataValueComparer( array $dataValueComparers ) { |
|
34 | - foreach ( $dataValueComparers as $dataValueComparer ) { |
|
35 | - if ( !is_object( $dataValueComparer ) || !( $dataValueComparer instanceof DataValueComparer ) ) { |
|
33 | + protected function assertAreDataValueComparer(array $dataValueComparers) { |
|
34 | + foreach ($dataValueComparers as $dataValueComparer) { |
|
35 | + if (!is_object($dataValueComparer) || !($dataValueComparer instanceof DataValueComparer)) { |
|
36 | 36 | throw new InvalidArgumentException( |
37 | 37 | 'All $dataValueComparers need to implement the DataValueComparer interface' |
38 | 38 | ); |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return bool |
50 | 50 | */ |
51 | - public function canCompare( DataValue $value, DataValue $comparativeValue ) { |
|
52 | - foreach ( $this->dataValueComparers as $dataValueComparer ) { |
|
53 | - if ( $dataValueComparer->canCompare( $value, $comparativeValue ) ) { |
|
51 | + public function canCompare(DataValue $value, DataValue $comparativeValue) { |
|
52 | + foreach ($this->dataValueComparers as $dataValueComparer) { |
|
53 | + if ($dataValueComparer->canCompare($value, $comparativeValue)) { |
|
54 | 54 | return true; |
55 | 55 | } |
56 | 56 | } |
@@ -67,10 +67,10 @@ discard block |
||
67 | 67 | * @throws InvalidArgumentException |
68 | 68 | * @return string One of the ComparisonResult::STATUS_... constants. |
69 | 69 | */ |
70 | - public function compare( DataValue $value, DataValue $comparativeValue ) { |
|
71 | - foreach ( $this->dataValueComparers as $dataValueComparer ) { |
|
72 | - if ( $dataValueComparer->canCompare( $value, $comparativeValue ) ) { |
|
73 | - return $dataValueComparer->compare( $value, $comparativeValue ); |
|
70 | + public function compare(DataValue $value, DataValue $comparativeValue) { |
|
71 | + foreach ($this->dataValueComparers as $dataValueComparer) { |
|
72 | + if ($dataValueComparer->canCompare($value, $comparativeValue)) { |
|
73 | + return $dataValueComparer->compare($value, $comparativeValue); |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 |
@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | '$identifierPropertyIds' |
100 | 100 | ); |
101 | 101 | |
102 | - $this->setDumpId( $dumpId ); |
|
102 | + $this->setDumpId($dumpId); |
|
103 | 103 | $this->sourceItemId = $sourceItemId; |
104 | 104 | $this->identifierPropertyIds = $identifierPropertyIds; |
105 | - $this->setImportDate( $importDate ); |
|
106 | - $this->setLanguageCode( $languageCode ); |
|
107 | - $this->setSourceUrl( $sourceUrl ); |
|
108 | - $this->setSize( $size ); |
|
105 | + $this->setImportDate($importDate); |
|
106 | + $this->setLanguageCode($languageCode); |
|
107 | + $this->setSourceUrl($sourceUrl); |
|
108 | + $this->setSize($size); |
|
109 | 109 | $this->licenseItemId = $licenseItemId; |
110 | 110 | } |
111 | 111 | |
@@ -170,11 +170,11 @@ discard block |
||
170 | 170 | * |
171 | 171 | * @throws InvalidArgumentException |
172 | 172 | */ |
173 | - private function setDumpId( $dumpId ) { |
|
174 | - Assert::parameterType( 'string', $dumpId, '$dumpId' ); |
|
175 | - $length = strlen( $dumpId ); |
|
176 | - if ( $length < 1 || $length > 25 ) { |
|
177 | - throw new InvalidArgumentException( '$dumpId must be between 1 and 25 characters.' ); |
|
173 | + private function setDumpId($dumpId) { |
|
174 | + Assert::parameterType('string', $dumpId, '$dumpId'); |
|
175 | + $length = strlen($dumpId); |
|
176 | + if ($length < 1 || $length > 25) { |
|
177 | + throw new InvalidArgumentException('$dumpId must be between 1 and 25 characters.'); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | $this->dumpId = $dumpId; |
@@ -185,10 +185,10 @@ discard block |
||
185 | 185 | * |
186 | 186 | * @throws InvalidArgumentException |
187 | 187 | */ |
188 | - private function setLanguageCode( $languageCode ) { |
|
189 | - Assert::parameterType( 'string', $languageCode, '$languageCode' ); |
|
190 | - if ( !Language::isValidCode( $languageCode ) ) { |
|
191 | - throw new InvalidArgumentException( '$languageCode is not valid.' ); |
|
188 | + private function setLanguageCode($languageCode) { |
|
189 | + Assert::parameterType('string', $languageCode, '$languageCode'); |
|
190 | + if (!Language::isValidCode($languageCode)) { |
|
191 | + throw new InvalidArgumentException('$languageCode is not valid.'); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | $this->languageCode = $languageCode; |
@@ -199,12 +199,12 @@ discard block |
||
199 | 199 | * |
200 | 200 | * @throws InvalidArgumentException |
201 | 201 | */ |
202 | - private function setImportDate( $importDate ) { |
|
203 | - Assert::parameterType( 'string', $importDate, '$importDate' ); |
|
202 | + private function setImportDate($importDate) { |
|
203 | + Assert::parameterType('string', $importDate, '$importDate'); |
|
204 | 204 | |
205 | - $timestamp = wfTimestamp( TS_MW, $importDate ); |
|
206 | - if ( !$timestamp ) { |
|
207 | - throw new InvalidArgumentException( '$updatedAt has invalid timestamp format.' ); |
|
205 | + $timestamp = wfTimestamp(TS_MW, $importDate); |
|
206 | + if (!$timestamp) { |
|
207 | + throw new InvalidArgumentException('$updatedAt has invalid timestamp format.'); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | $this->importDate = $importDate; |
@@ -215,13 +215,13 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @throws InvalidArgumentException |
217 | 217 | */ |
218 | - private function setSourceUrl( $sourceUrl ) { |
|
219 | - Assert::parameterType( 'string', $sourceUrl, '$sourceUrl' ); |
|
220 | - if ( strlen( $sourceUrl ) > 300 ) { |
|
221 | - throw new InvalidArgumentException( '$sourceUrl must not be longer than 300 characters.' ); |
|
218 | + private function setSourceUrl($sourceUrl) { |
|
219 | + Assert::parameterType('string', $sourceUrl, '$sourceUrl'); |
|
220 | + if (strlen($sourceUrl) > 300) { |
|
221 | + throw new InvalidArgumentException('$sourceUrl must not be longer than 300 characters.'); |
|
222 | 222 | } |
223 | - if ( !filter_var( $sourceUrl, FILTER_VALIDATE_URL ) ) { |
|
224 | - throw new InvalidArgumentException( '$sourceUrl is not a valid url.' ); |
|
223 | + if (!filter_var($sourceUrl, FILTER_VALIDATE_URL)) { |
|
224 | + throw new InvalidArgumentException('$sourceUrl is not a valid url.'); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | $this->sourceUrl = $sourceUrl; |
@@ -232,10 +232,10 @@ discard block |
||
232 | 232 | * |
233 | 233 | * @throws InvalidArgumentException |
234 | 234 | */ |
235 | - private function setSize( $size ) { |
|
236 | - Assert::parameterType( 'integer', $size, '$size' ); |
|
237 | - if ( $size <= 0 ) { |
|
238 | - throw new InvalidArgumentException( '$size must be positive integer.' ); |
|
235 | + private function setSize($size) { |
|
236 | + Assert::parameterType('integer', $size, '$size'); |
|
237 | + if ($size <= 0) { |
|
238 | + throw new InvalidArgumentException('$size must be positive integer.'); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | $this->size = $size; |
@@ -73,8 +73,8 @@ |
||
73 | 73 | ComparisonResult $comparisonResult, |
74 | 74 | ReferenceResult $referenceResult |
75 | 75 | ) { |
76 | - Assert::parameterType( 'string', $claimGuid, '$claimGuid' ); |
|
77 | - Assert::parameterType( 'string', $externalId, '$externalId' ); |
|
76 | + Assert::parameterType('string', $claimGuid, '$claimGuid'); |
|
77 | + Assert::parameterType('string', $externalId, '$externalId'); |
|
78 | 78 | |
79 | 79 | $this->propertyId = $propertyId; |
80 | 80 | $this->claimGuid = $claimGuid; |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @fixme inject specific things needed here instead of the WikibaseRepo factory. (T112105) |
74 | 74 | */ |
75 | - public function __construct( WikibaseRepo $wikibaseRepo ) { |
|
75 | + public function __construct(WikibaseRepo $wikibaseRepo) { |
|
76 | 76 | $this->wikibaseRepo = $wikibaseRepo; |
77 | 77 | } |
78 | 78 | |
@@ -85,10 +85,10 @@ discard block |
||
85 | 85 | public static function getDefaultInstance() { |
86 | 86 | static $instance = null; |
87 | 87 | |
88 | - if ( $instance === null ) { |
|
88 | + if ($instance === null) { |
|
89 | 89 | $wikibaseRepo = WikibaseRepo::getDefaultInstance(); |
90 | 90 | |
91 | - $instance = new self( $wikibaseRepo ); |
|
91 | + $instance = new self($wikibaseRepo); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | return $instance; |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @return CrossChecker |
99 | 99 | */ |
100 | 100 | public function getCrossChecker() { |
101 | - if ( $this->crossChecker === null ) { |
|
101 | + if ($this->crossChecker === null) { |
|
102 | 102 | $this->crossChecker = new CrossChecker( |
103 | 103 | $this->wikibaseRepo->getEntityLookup(), |
104 | 104 | $this->getComparativeValueParserFactory(), |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * @return CrossCheckInteractor |
117 | 117 | */ |
118 | 118 | public function getCrossCheckInteractor() { |
119 | - if ( $this->crossCheckInteractor === null ) { |
|
119 | + if ($this->crossCheckInteractor === null) { |
|
120 | 120 | $this->crossCheckInteractor = new CrossCheckInteractor( |
121 | 121 | $this->wikibaseRepo->getEntityLookup(), |
122 | 122 | $this->wikibaseRepo->getStatementGuidParser(), |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | * @return ComparativeValueParserFactory |
132 | 132 | */ |
133 | 133 | public function getComparativeValueParserFactory() { |
134 | - if ( $this->comparativeValueParserFactory === null ) { |
|
134 | + if ($this->comparativeValueParserFactory === null) { |
|
135 | 135 | $this->comparativeValueParserFactory = new ComparativeValueParserFactory( |
136 | 136 | $this->wikibaseRepo->getDataTypeDefinitions(), |
137 | 137 | new StringNormalizer() |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * @return DataValueComparerFactory |
146 | 146 | */ |
147 | 147 | public function getDataValueComparerFactory() { |
148 | - if ( $this->dataValueComparerFactory === null ) { |
|
148 | + if ($this->dataValueComparerFactory === null) { |
|
149 | 149 | $this->dataValueComparerFactory = new DataValueComparerFactory( |
150 | 150 | $this->wikibaseRepo->getStore()->getTermIndex(), |
151 | 151 | $this->wikibaseRepo->getStringNormalizer() |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * @return DumpMetaInformationLookup |
160 | 160 | */ |
161 | 161 | public function getDumpMetaInformationLookup() { |
162 | - if ( $this->dumpMetaInformationLookup === null ) { |
|
162 | + if ($this->dumpMetaInformationLookup === null) { |
|
163 | 163 | $this->dumpMetaInformationLookup = new SqlDumpMetaInformationRepo(); |
164 | 164 | } |
165 | 165 | |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | * @return DumpMetaInformationStore |
171 | 171 | */ |
172 | 172 | public function getDumpMetaInformationStore() { |
173 | - if ( $this->dumpMetaInformationStore === null ) { |
|
173 | + if ($this->dumpMetaInformationStore === null) { |
|
174 | 174 | $this->dumpMetaInformationStore = new SqlDumpMetaInformationRepo(); |
175 | 175 | } |
176 | 176 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * @return ExternalDataRepo |
182 | 182 | */ |
183 | 183 | public function getExternalDataRepo() { |
184 | - if ( $this->externalDataRepo === null ) { |
|
184 | + if ($this->externalDataRepo === null) { |
|
185 | 185 | $this->externalDataRepo = new ExternalDataRepo(); |
186 | 186 | } |
187 | 187 | |
@@ -192,9 +192,9 @@ discard block |
||
192 | 192 | * @return SerializerFactory |
193 | 193 | */ |
194 | 194 | public function getSerializerFactory() { |
195 | - if ( $this->serializerFactory === null ) { |
|
195 | + if ($this->serializerFactory === null) { |
|
196 | 196 | $dataValueSerializer = new DataValueSerializer(); |
197 | - $dataModelSerializerFactory = new \Wikibase\DataModel\SerializerFactory( $dataValueSerializer ); |
|
197 | + $dataModelSerializerFactory = new \Wikibase\DataModel\SerializerFactory($dataValueSerializer); |
|
198 | 198 | $this->serializerFactory = new SerializerFactory( |
199 | 199 | $dataValueSerializer, |
200 | 200 | $dataModelSerializerFactory->newReferenceSerializer() |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @return self |
67 | 67 | */ |
68 | - public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) { |
|
68 | + public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') { |
|
69 | 69 | $repo = WikibaseRepo::getDefaultInstance(); |
70 | 70 | $externalValidationServices = ExternalValidationServices::getDefaultInstance(); |
71 | 71 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | $repo->getStatementGuidValidator(), |
78 | 78 | $externalValidationServices->getCrossCheckInteractor(), |
79 | 79 | $externalValidationServices->getSerializerFactory(), |
80 | - $repo->getApiHelperFactory( RequestContext::getMain() ) |
|
80 | + $repo->getApiHelperFactory(RequestContext::getMain()) |
|
81 | 81 | ); |
82 | 82 | } |
83 | 83 | |
@@ -101,14 +101,14 @@ discard block |
||
101 | 101 | SerializerFactory $serializerFactory, |
102 | 102 | ApiHelperFactory $apiHelperFactory |
103 | 103 | ) { |
104 | - parent::__construct( $main, $name, $prefix ); |
|
104 | + parent::__construct($main, $name, $prefix); |
|
105 | 105 | |
106 | 106 | $this->entityIdParser = $entityIdParser; |
107 | 107 | $this->statementGuidValidator = $statementGuidValidator; |
108 | 108 | $this->crossCheckInteractor = $crossCheckInteractor; |
109 | 109 | $this->serializerFactory = $serializerFactory; |
110 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
111 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
110 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
111 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -117,34 +117,34 @@ discard block |
||
117 | 117 | public function execute() { |
118 | 118 | $params = $this->extractRequestParams(); |
119 | 119 | |
120 | - if ( $params['entities'] && $params['claims'] ) { |
|
120 | + if ($params['entities'] && $params['claims']) { |
|
121 | 121 | $this->errorReporter->dieError( |
122 | 122 | 'Either provide the ids of entities or ids of claims, that should be cross-checked.', |
123 | 123 | 'param-invalid' |
124 | 124 | ); |
125 | 125 | throw new LogicException(); |
126 | - } elseif ( $params['entities'] ) { |
|
127 | - $entityIds = $this->parseEntityIds( $params['entities'] ); |
|
128 | - if ( $params['properties'] ) { |
|
129 | - $propertyIds = $this->parseEntityIds( $params['properties'] ); |
|
130 | - $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIdWithProperties( $entityIds, $propertyIds ); |
|
126 | + } elseif ($params['entities']) { |
|
127 | + $entityIds = $this->parseEntityIds($params['entities']); |
|
128 | + if ($params['properties']) { |
|
129 | + $propertyIds = $this->parseEntityIds($params['properties']); |
|
130 | + $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIdWithProperties($entityIds, $propertyIds); |
|
131 | 131 | } else { |
132 | - $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIds( $entityIds ); |
|
132 | + $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIds($entityIds); |
|
133 | 133 | } |
134 | - } elseif ( $params['claims'] ) { |
|
134 | + } elseif ($params['claims']) { |
|
135 | 135 | $guids = $params['claims']; |
136 | - $this->assertAreValidClaimGuids( $guids ); |
|
137 | - $resultLists = $this->crossCheckInteractor->crossCheckStatementsByGuids( $guids ); |
|
136 | + $this->assertAreValidClaimGuids($guids); |
|
137 | + $resultLists = $this->crossCheckInteractor->crossCheckStatementsByGuids($guids); |
|
138 | 138 | } else { |
139 | 139 | $this->errorReporter->dieWithError( |
140 | - [ 'wikibase-api-param-missing', 'entities|claims' ], |
|
140 | + ['wikibase-api-param-missing', 'entities|claims'], |
|
141 | 141 | 'param-missing' |
142 | 142 | ); |
143 | 143 | throw new LogicException(); |
144 | 144 | } |
145 | 145 | |
146 | 146 | // Print result lists |
147 | - $this->writeResultOutput( $resultLists ); |
|
147 | + $this->writeResultOutput($resultLists); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | * |
153 | 153 | * @return EntityId[] |
154 | 154 | */ |
155 | - private function parseEntityIds( array $entityIds ) { |
|
155 | + private function parseEntityIds(array $entityIds) { |
|
156 | 156 | return array_map( |
157 | - [ $this->entityIdParser, 'parse' ], |
|
157 | + [$this->entityIdParser, 'parse'], |
|
158 | 158 | $entityIds |
159 | 159 | ); |
160 | 160 | } |
@@ -162,10 +162,10 @@ discard block |
||
162 | 162 | /** |
163 | 163 | * @param string[] $guids |
164 | 164 | */ |
165 | - private function assertAreValidClaimGuids( array $guids ) { |
|
166 | - foreach ( $guids as $guid ) { |
|
167 | - if ( $this->statementGuidValidator->validateFormat( $guid ) === false ) { |
|
168 | - $this->errorReporter->dieError( 'Invalid claim guid.', 'invalid-guid' ); |
|
165 | + private function assertAreValidClaimGuids(array $guids) { |
|
166 | + foreach ($guids as $guid) { |
|
167 | + if ($this->statementGuidValidator->validateFormat($guid) === false) { |
|
168 | + $this->errorReporter->dieError('Invalid claim guid.', 'invalid-guid'); |
|
169 | 169 | } |
170 | 170 | } |
171 | 171 | } |
@@ -177,13 +177,13 @@ discard block |
||
177 | 177 | * |
178 | 178 | * @return array |
179 | 179 | */ |
180 | - private function writeResultOutput( array $resultLists ) { |
|
180 | + private function writeResultOutput(array $resultLists) { |
|
181 | 181 | $serializer = $this->serializerFactory->newCrossCheckResultListSerializer(); |
182 | 182 | |
183 | 183 | $output = []; |
184 | - foreach ( $resultLists as $entityId => $resultList ) { |
|
185 | - if ( $resultList ) { |
|
186 | - $serializedResultList = $serializer->serialize( $resultList ); |
|
184 | + foreach ($resultLists as $entityId => $resultList) { |
|
185 | + if ($resultList) { |
|
186 | + $serializedResultList = $serializer->serialize($resultList); |
|
187 | 187 | |
188 | 188 | $output[$entityId] = $serializedResultList; |
189 | 189 | } else { |
@@ -193,10 +193,10 @@ discard block |
||
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
196 | - $this->getResult()->setIndexedTagName( $output, 'entity' ); |
|
197 | - $this->getResult()->setArrayType( $output, 'kvp', 'id' ); |
|
198 | - $this->getResult()->addValue( null, 'results', $output ); |
|
199 | - $this->resultBuilder->markSuccess( 1 ); |
|
196 | + $this->getResult()->setIndexedTagName($output, 'entity'); |
|
197 | + $this->getResult()->setArrayType($output, 'kvp', 'id'); |
|
198 | + $this->getResult()->addValue(null, 'results', $output); |
|
199 | + $this->resultBuilder->markSuccess(1); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
@@ -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'][] = [ |
10 | 10 | 'path' => __FILE__, |
@@ -17,9 +17,9 @@ discard block |
||
17 | 17 | ]; |
18 | 18 | |
19 | 19 | // Initialize localization and aliases |
20 | - $GLOBALS['wgMessagesDirs']['WikibaseQualityExternalValidation'] = __DIR__ . '/i18n'; |
|
20 | + $GLOBALS['wgMessagesDirs']['WikibaseQualityExternalValidation'] = __DIR__.'/i18n'; |
|
21 | 21 | $GLOBALS['wgExtensionMessagesFiles']['WikibaseQualityExternalValidationAlias'] = |
22 | - __DIR__ . '/WikibaseQualityExternalValidation.alias.php'; |
|
22 | + __DIR__.'/WikibaseQualityExternalValidation.alias.php'; |
|
23 | 23 | |
24 | 24 | // Initalize hooks for creating database tables |
25 | 25 | $GLOBALS['wgHooks']['LoadExtensionSchemaUpdates'][] = |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | // Define API modules |
39 | 39 | $GLOBALS['wgAPIModules']['wbqevcrosscheck'] = [ |
40 | 40 | 'class' => WikibaseQuality\ExternalValidation\Api\RunCrossCheck::class, |
41 | - 'factory' => function( ApiMain $main, $action ) { |
|
42 | - return WikibaseQuality\ExternalValidation\Api\RunCrossCheck::newFromGlobalState( $main, $action ); |
|
41 | + 'factory' => function(ApiMain $main, $action) { |
|
42 | + return WikibaseQuality\ExternalValidation\Api\RunCrossCheck::newFromGlobalState($main, $action); |
|
43 | 43 | } |
44 | 44 | ]; |
45 | 45 |
@@ -52,13 +52,13 @@ discard block |
||
52 | 52 | public function import() { |
53 | 53 | $dumpIds = $this->insertMetaInformation(); |
54 | 54 | |
55 | - $this->log( "\nDelete old database entries...\n" ); |
|
55 | + $this->log("\nDelete old database entries...\n"); |
|
56 | 56 | |
57 | - foreach ( $dumpIds as $dumpId ) { |
|
58 | - $this->externalDataRepo->deleteOfDump( $dumpId, $this->importSettings->getBatchSize() ); |
|
57 | + foreach ($dumpIds as $dumpId) { |
|
58 | + $this->externalDataRepo->deleteOfDump($dumpId, $this->importSettings->getBatchSize()); |
|
59 | 59 | } |
60 | 60 | |
61 | - $this->log( "\n" ); |
|
61 | + $this->log("\n"); |
|
62 | 62 | |
63 | 63 | $this->insertExternalValues(); |
64 | 64 | } |
@@ -69,52 +69,52 @@ discard block |
||
69 | 69 | * @return array |
70 | 70 | */ |
71 | 71 | protected function insertMetaInformation() { |
72 | - $this->log( "Insert new dump meta information\n" ); |
|
72 | + $this->log("Insert new dump meta information\n"); |
|
73 | 73 | |
74 | - $csvFile = fopen( $this->importSettings->getDumpInformationFilePath(), 'rb' ); |
|
75 | - if ( !$csvFile ) { |
|
76 | - exit( 'Error while reading CSV file.' ); |
|
74 | + $csvFile = fopen($this->importSettings->getDumpInformationFilePath(), 'rb'); |
|
75 | + if (!$csvFile) { |
|
76 | + exit('Error while reading CSV file.'); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | $i = 0; |
80 | 80 | $dumpIds = []; |
81 | - while ( $data = fgetcsv( $csvFile ) ) { |
|
81 | + while ($data = fgetcsv($csvFile)) { |
|
82 | 82 | $identifierPropertyIds = array_map( |
83 | - function ( $propertyId ) { |
|
84 | - return new PropertyId( $propertyId ); |
|
83 | + function($propertyId) { |
|
84 | + return new PropertyId($propertyId); |
|
85 | 85 | }, |
86 | - json_decode( $data[2] ) |
|
86 | + json_decode($data[2]) |
|
87 | 87 | ); |
88 | 88 | try { |
89 | 89 | $dumpMetaInformation = new DumpMetaInformation( |
90 | 90 | $data[0], |
91 | - new ItemId( $data[1] ), |
|
91 | + new ItemId($data[1]), |
|
92 | 92 | $identifierPropertyIds, |
93 | 93 | $data[3], |
94 | 94 | $data[4], |
95 | 95 | $data[5], |
96 | - intval( $data[6] ), |
|
97 | - new ItemId( $data[7] ) |
|
96 | + intval($data[6]), |
|
97 | + new ItemId($data[7]) |
|
98 | 98 | ); |
99 | - } catch ( \InvalidArgumentException $e ) { |
|
100 | - exit( 'Input file has bad formatted values.' ); |
|
99 | + } catch (\InvalidArgumentException $e) { |
|
100 | + exit('Input file has bad formatted values.'); |
|
101 | 101 | } |
102 | 102 | $dumpIds[] = $dumpMetaInformation->getDumpId(); |
103 | 103 | |
104 | 104 | try { |
105 | - $this->dumpMetaInformationStore->save( $dumpMetaInformation ); |
|
106 | - } catch ( DBError $e ) { |
|
107 | - exit( 'Unknown database error occurred.' ); |
|
105 | + $this->dumpMetaInformationStore->save($dumpMetaInformation); |
|
106 | + } catch (DBError $e) { |
|
107 | + exit('Unknown database error occurred.'); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | $i++; |
111 | - $this->log( "\r\033[K" ); |
|
112 | - $this->log( "$i rows inserted or updated" ); |
|
111 | + $this->log("\r\033[K"); |
|
112 | + $this->log("$i rows inserted or updated"); |
|
113 | 113 | } |
114 | 114 | |
115 | - fclose( $csvFile ); |
|
115 | + fclose($csvFile); |
|
116 | 116 | |
117 | - $this->log( "\n" ); |
|
117 | + $this->log("\n"); |
|
118 | 118 | |
119 | 119 | return $dumpIds; |
120 | 120 | } |
@@ -123,31 +123,31 @@ discard block |
||
123 | 123 | * Inserts external values stored in csv file into database |
124 | 124 | */ |
125 | 125 | private function insertExternalValues() { |
126 | - $this->log( "Insert new data values\n" ); |
|
126 | + $this->log("Insert new data values\n"); |
|
127 | 127 | |
128 | - $csvFile = fopen( $this->importSettings->getExternalValuesFilePath(), 'rb' ); |
|
129 | - if ( !$csvFile ) { |
|
130 | - exit( 'Error while reading CSV file.' ); |
|
128 | + $csvFile = fopen($this->importSettings->getExternalValuesFilePath(), 'rb'); |
|
129 | + if (!$csvFile) { |
|
130 | + exit('Error while reading CSV file.'); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | $i = 0; |
134 | 134 | $accumulator = []; |
135 | - while ( true ) { |
|
136 | - $data = fgetcsv( $csvFile ); |
|
137 | - if ( $data === false || ++$i % $this->importSettings->getBatchSize() === 0 ) { |
|
135 | + while (true) { |
|
136 | + $data = fgetcsv($csvFile); |
|
137 | + if ($data === false || ++$i % $this->importSettings->getBatchSize() === 0) { |
|
138 | 138 | try { |
139 | - $this->externalDataRepo->insertBatch( $accumulator ); |
|
140 | - } catch ( DBError $e ) { |
|
141 | - exit( 'Unknown database error occurred.' ); |
|
139 | + $this->externalDataRepo->insertBatch($accumulator); |
|
140 | + } catch (DBError $e) { |
|
141 | + exit('Unknown database error occurred.'); |
|
142 | 142 | } |
143 | 143 | wfGetLBFactory()->waitForReplication(); |
144 | 144 | |
145 | - $this->log( "\r\033[K" ); |
|
146 | - $this->log( "$i rows inserted" ); |
|
145 | + $this->log("\r\033[K"); |
|
146 | + $this->log("$i rows inserted"); |
|
147 | 147 | |
148 | 148 | $accumulator = []; |
149 | 149 | |
150 | - if ( $data === false ) { |
|
150 | + if ($data === false) { |
|
151 | 151 | break; |
152 | 152 | } |
153 | 153 | } |
@@ -155,16 +155,16 @@ discard block |
||
155 | 155 | $accumulator[] = $data; |
156 | 156 | } |
157 | 157 | |
158 | - fclose( $csvFile ); |
|
158 | + fclose($csvFile); |
|
159 | 159 | |
160 | - $this->log( "\n" ); |
|
160 | + $this->log("\n"); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
164 | 164 | * @param string $text |
165 | 165 | */ |
166 | - private function log( $text ) { |
|
167 | - if ( !$this->importSettings->isQuiet() ) { |
|
166 | + private function log($text) { |
|
167 | + if (!$this->importSettings->isQuiet()) { |
|
168 | 168 | print $text; |
169 | 169 | } |
170 | 170 | } |
@@ -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( count( $dumpIds ) > 0, '$dumpIds', '$dumpIds has to contain at least one element.' ); |
|
32 | - Assert::parameter( count( $externalIds ) > 0, '$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(count($dumpIds) > 0, '$dumpIds', '$dumpIds has to contain at least one element.'); |
|
32 | + Assert::parameter(count($externalIds) > 0, '$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,21 +117,21 @@ 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 | - $db = wfGetDB( DB_MASTER ); |
|
125 | - if ( $db->getType() === 'sqlite' ) { |
|
126 | - $db->delete( self::TABLE_NAME, [ 'dump_id' => $dumpId ] ); |
|
124 | + $db = wfGetDB(DB_MASTER); |
|
125 | + if ($db->getType() === 'sqlite') { |
|
126 | + $db->delete(self::TABLE_NAME, ['dump_id' => $dumpId]); |
|
127 | 127 | } else { |
128 | 128 | do { |
129 | - $db->commit( __METHOD__, 'flush' ); |
|
129 | + $db->commit(__METHOD__, 'flush'); |
|
130 | 130 | wfGetLBFactory()->waitForReplication(); |
131 | - $table = $db->tableName( self::TABLE_NAME ); |
|
132 | - $condition = 'dump_id = ' . $db->addQuotes( $dumpId ); |
|
133 | - $db->query( sprintf( 'DELETE FROM %s WHERE %s LIMIT %d', $table, $condition, $batchSize ) ); |
|
134 | - } while ( $db->affectedRows() > 0 ); |
|
131 | + $table = $db->tableName(self::TABLE_NAME); |
|
132 | + $condition = 'dump_id = '.$db->addQuotes($dumpId); |
|
133 | + $db->query(sprintf('DELETE FROM %s WHERE %s LIMIT %d', $table, $condition, $batchSize)); |
|
134 | + } while ($db->affectedRows() > 0); |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | private $crossChecker; |
39 | 39 | |
40 | - public function __construct( EntityLookup $entityLookup, StatementGuidParser $statementGuidParser, CrossChecker $crossChecker ) { |
|
40 | + public function __construct(EntityLookup $entityLookup, StatementGuidParser $statementGuidParser, CrossChecker $crossChecker) { |
|
41 | 41 | $this->entityLookup = $entityLookup; |
42 | 42 | $this->statementGuidParser = $statementGuidParser; |
43 | 43 | $this->crossChecker = $crossChecker; |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @return CrossCheckResultList|null |
52 | 52 | */ |
53 | - public function crossCheckEntityById( EntityId $entityId ) { |
|
54 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
53 | + public function crossCheckEntityById(EntityId $entityId) { |
|
54 | + $entity = $this->entityLookup->getEntity($entityId); |
|
55 | 55 | |
56 | - if ( $entity instanceof StatementListProvider ) { |
|
57 | - return $this->crossCheckStatements( $entity->getStatements() ); |
|
56 | + if ($entity instanceof StatementListProvider) { |
|
57 | + return $this->crossCheckStatements($entity->getStatements()); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | return null; |
@@ -67,12 +67,12 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @return CrossCheckResultList[] |
69 | 69 | */ |
70 | - public function crossCheckEntitiesByIds( array $entityIds ) { |
|
71 | - Assert::parameterElementType( EntityId::class, $entityIds, '$entityIds' ); |
|
70 | + public function crossCheckEntitiesByIds(array $entityIds) { |
|
71 | + Assert::parameterElementType(EntityId::class, $entityIds, '$entityIds'); |
|
72 | 72 | |
73 | 73 | $results = []; |
74 | - foreach ( $entityIds as $entityId ) { |
|
75 | - $results[$entityId->getSerialization()] = $this->crossCheckEntityById( $entityId ); |
|
74 | + foreach ($entityIds as $entityId) { |
|
75 | + $results[$entityId->getSerialization()] = $this->crossCheckEntityById($entityId); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | return $results; |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @return CrossCheckResultList |
87 | 87 | */ |
88 | - public function crossCheckStatements( StatementList $statements ) { |
|
89 | - return $this->crossChecker->crossCheckStatements( $statements, $statements ); |
|
88 | + public function crossCheckStatements(StatementList $statements) { |
|
89 | + return $this->crossChecker->crossCheckStatements($statements, $statements); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -97,14 +97,14 @@ discard block |
||
97 | 97 | * @return CrossCheckResultList[] |
98 | 98 | * @throws InvalidArgumentException |
99 | 99 | */ |
100 | - public function crossCheckEntities( array $entities ) { |
|
101 | - Assert::parameterElementType( EntityDocument::class, $entities, '$entities' ); |
|
100 | + public function crossCheckEntities(array $entities) { |
|
101 | + Assert::parameterElementType(EntityDocument::class, $entities, '$entities'); |
|
102 | 102 | |
103 | 103 | $results = []; |
104 | - foreach ( $entities as $entity ) { |
|
104 | + foreach ($entities as $entity) { |
|
105 | 105 | $entityId = $entity->getId()->getSerialization(); |
106 | - if ( $entity instanceof StatementListProvider ) { |
|
107 | - $results[$entityId] = $this->crossCheckStatements( $entity->getStatements() ); |
|
106 | + if ($entity instanceof StatementListProvider) { |
|
107 | + $results[$entityId] = $this->crossCheckStatements($entity->getStatements()); |
|
108 | 108 | } |
109 | 109 | } |
110 | 110 | |
@@ -120,13 +120,13 @@ discard block |
||
120 | 120 | * @return CrossCheckResultList|null |
121 | 121 | * @throws InvalidArgumentException |
122 | 122 | */ |
123 | - public function crossCheckEntityByIdWithProperties( EntityId $entityId, array $propertyIds ) { |
|
124 | - Assert::parameterElementType( PropertyId::class, $propertyIds, '$propertyIds' ); |
|
123 | + public function crossCheckEntityByIdWithProperties(EntityId $entityId, array $propertyIds) { |
|
124 | + Assert::parameterElementType(PropertyId::class, $propertyIds, '$propertyIds'); |
|
125 | 125 | |
126 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
126 | + $entity = $this->entityLookup->getEntity($entityId); |
|
127 | 127 | |
128 | - if ( $entity instanceof StatementListProvider ) { |
|
129 | - return $this->crossCheckStatementsWithProperties( $entity->getStatements(), $propertyIds ); |
|
128 | + if ($entity instanceof StatementListProvider) { |
|
129 | + return $this->crossCheckStatementsWithProperties($entity->getStatements(), $propertyIds); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | return null; |
@@ -141,13 +141,13 @@ discard block |
||
141 | 141 | * @return CrossCheckResultList[] |
142 | 142 | * @throws InvalidArgumentException |
143 | 143 | */ |
144 | - public function crossCheckEntitiesByIdWithProperties( array $entityIds, array $propertyIds ) { |
|
145 | - Assert::parameterElementType( EntityId::class, $entityIds, '$entityIds' ); |
|
146 | - Assert::parameterElementType( PropertyId::class, $propertyIds, '$propertyIds' ); |
|
144 | + public function crossCheckEntitiesByIdWithProperties(array $entityIds, array $propertyIds) { |
|
145 | + Assert::parameterElementType(EntityId::class, $entityIds, '$entityIds'); |
|
146 | + Assert::parameterElementType(PropertyId::class, $propertyIds, '$propertyIds'); |
|
147 | 147 | |
148 | 148 | $results = []; |
149 | - foreach ( $entityIds as $entityId ) { |
|
150 | - $results[$entityId->getSerialization()] = $this->crossCheckEntityByIdWithProperties( $entityId, $propertyIds ); |
|
149 | + foreach ($entityIds as $entityId) { |
|
150 | + $results[$entityId->getSerialization()] = $this->crossCheckEntityByIdWithProperties($entityId, $propertyIds); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | return $results; |
@@ -162,17 +162,17 @@ discard block |
||
162 | 162 | * @return CrossCheckResultList |
163 | 163 | * @throws InvalidArgumentException |
164 | 164 | */ |
165 | - public function crossCheckStatementsWithProperties( StatementList $entityStatements, array $propertyIds ) { |
|
166 | - Assert::parameterElementType( PropertyId::class, $propertyIds, '$propertyIds' ); |
|
165 | + public function crossCheckStatementsWithProperties(StatementList $entityStatements, array $propertyIds) { |
|
166 | + Assert::parameterElementType(PropertyId::class, $propertyIds, '$propertyIds'); |
|
167 | 167 | |
168 | 168 | $statements = new StatementList(); |
169 | - foreach ( $entityStatements->toArray() as $statement ) { |
|
170 | - if ( in_array( $statement->getPropertyId(), $propertyIds ) ) { |
|
171 | - $statements->addStatement( $statement ); |
|
169 | + foreach ($entityStatements->toArray() as $statement) { |
|
170 | + if (in_array($statement->getPropertyId(), $propertyIds)) { |
|
171 | + $statements->addStatement($statement); |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
175 | - return $this->crossChecker->crossCheckStatements( $entityStatements, $statements ); |
|
175 | + return $this->crossChecker->crossCheckStatements($entityStatements, $statements); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -184,14 +184,14 @@ discard block |
||
184 | 184 | * @return CrossCheckResultList[] |
185 | 185 | * @throws InvalidArgumentException |
186 | 186 | */ |
187 | - public function crossCheckEntitiesWithProperties( array $entities, array $propertyIds ) { |
|
188 | - Assert::parameterElementType( EntityDocument::class, $entities, '$entities' ); |
|
189 | - Assert::parameterElementType( PropertyId::class, $propertyIds, '$propertyIds' ); |
|
187 | + public function crossCheckEntitiesWithProperties(array $entities, array $propertyIds) { |
|
188 | + Assert::parameterElementType(EntityDocument::class, $entities, '$entities'); |
|
189 | + Assert::parameterElementType(PropertyId::class, $propertyIds, '$propertyIds'); |
|
190 | 190 | |
191 | 191 | $results = []; |
192 | - foreach ( $entities as $entity ) { |
|
192 | + foreach ($entities as $entity) { |
|
193 | 193 | $entityId = $entity->getId()->getSerialization(); |
194 | - if ( $entity instanceof StatementListProvider ) { |
|
194 | + if ($entity instanceof StatementListProvider) { |
|
195 | 195 | $results[$entityId] = $this->crossCheckStatementsWithProperties( |
196 | 196 | $entity->getStatements(), |
197 | 197 | $propertyIds |
@@ -210,12 +210,12 @@ discard block |
||
210 | 210 | * @return CrossCheckResultList |
211 | 211 | * @throws InvalidArgumentException |
212 | 212 | */ |
213 | - public function crossCheckStatementByGuid( $guid ) { |
|
214 | - $this->assertIsString( $guid, '$guid' ); |
|
213 | + public function crossCheckStatementByGuid($guid) { |
|
214 | + $this->assertIsString($guid, '$guid'); |
|
215 | 215 | |
216 | - $resultList = $this->crossCheckStatementsByGuids( [ $guid ] ); |
|
216 | + $resultList = $this->crossCheckStatementsByGuids([$guid]); |
|
217 | 217 | |
218 | - return reset( $resultList ); |
|
218 | + return reset($resultList); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -226,21 +226,21 @@ discard block |
||
226 | 226 | * @return CrossCheckResultList[] |
227 | 227 | * @throws InvalidArgumentException |
228 | 228 | */ |
229 | - public function crossCheckStatementsByGuids( array $guids ) { |
|
230 | - $this->assertIsArrayOfStrings( $guids, '$guids' ); |
|
229 | + public function crossCheckStatementsByGuids(array $guids) { |
|
230 | + $this->assertIsArrayOfStrings($guids, '$guids'); |
|
231 | 231 | |
232 | 232 | $entityIds = []; |
233 | 233 | $groupedStatementGuids = []; |
234 | - foreach ( $guids as $guid ) { |
|
235 | - $serializedEntityId = $this->statementGuidParser->parse( $guid )->getEntityId(); |
|
234 | + foreach ($guids as $guid) { |
|
235 | + $serializedEntityId = $this->statementGuidParser->parse($guid)->getEntityId(); |
|
236 | 236 | $entityIds[$serializedEntityId->getSerialization()] = $serializedEntityId; |
237 | 237 | $groupedStatementGuids[$serializedEntityId->getSerialization()][] = $guid; |
238 | 238 | } |
239 | 239 | |
240 | 240 | $resultLists = []; |
241 | - foreach ( $groupedStatementGuids as $serializedEntityId => $guidsOfEntity ) { |
|
242 | - $entityId = $entityIds[ $serializedEntityId ]; |
|
243 | - $resultLists[ $serializedEntityId ] = $this->crossCheckClaimsOfEntity( $entityId, $guidsOfEntity ); |
|
241 | + foreach ($groupedStatementGuids as $serializedEntityId => $guidsOfEntity) { |
|
242 | + $entityId = $entityIds[$serializedEntityId]; |
|
243 | + $resultLists[$serializedEntityId] = $this->crossCheckClaimsOfEntity($entityId, $guidsOfEntity); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | return $resultLists; |
@@ -252,18 +252,18 @@ discard block |
||
252 | 252 | * |
253 | 253 | * @return CrossCheckResultList|null |
254 | 254 | */ |
255 | - private function crossCheckClaimsOfEntity( EntityId $entityId, array $guids ) { |
|
256 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
255 | + private function crossCheckClaimsOfEntity(EntityId $entityId, array $guids) { |
|
256 | + $entity = $this->entityLookup->getEntity($entityId); |
|
257 | 257 | |
258 | - if ( $entity instanceof StatementListProvider ) { |
|
258 | + if ($entity instanceof StatementListProvider) { |
|
259 | 259 | $statements = new StatementList(); |
260 | - foreach ( $entity->getStatements()->toArray() as $statement ) { |
|
261 | - if ( in_array( $statement->getGuid(), $guids ) ) { |
|
262 | - $statements->addStatement( $statement ); |
|
260 | + foreach ($entity->getStatements()->toArray() as $statement) { |
|
261 | + if (in_array($statement->getGuid(), $guids)) { |
|
262 | + $statements->addStatement($statement); |
|
263 | 263 | } |
264 | 264 | } |
265 | 265 | |
266 | - return $this->crossChecker->crossCheckStatements( $entity->getStatements(), $statements ); |
|
266 | + return $this->crossChecker->crossCheckStatements($entity->getStatements(), $statements); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | return null; |
@@ -275,9 +275,9 @@ discard block |
||
275 | 275 | * |
276 | 276 | * @throws InvalidArgumentException |
277 | 277 | */ |
278 | - private function assertIsString( $string, $parameterName ) { |
|
279 | - if ( !is_string( $string ) ) { |
|
280 | - throw new InvalidArgumentException( "$parameterName must be string." ); |
|
278 | + private function assertIsString($string, $parameterName) { |
|
279 | + if (!is_string($string)) { |
|
280 | + throw new InvalidArgumentException("$parameterName must be string."); |
|
281 | 281 | } |
282 | 282 | } |
283 | 283 | |
@@ -287,10 +287,10 @@ discard block |
||
287 | 287 | * |
288 | 288 | * @throws InvalidArgumentException |
289 | 289 | */ |
290 | - private function assertIsArrayOfStrings( array $strings, $parameterName ) { |
|
291 | - foreach ( $strings as $string ) { |
|
292 | - if ( !is_string( $string ) ) { |
|
293 | - throw new InvalidArgumentException( "Each element of $parameterName must be string." ); |
|
290 | + private function assertIsArrayOfStrings(array $strings, $parameterName) { |
|
291 | + foreach ($strings as $string) { |
|
292 | + if (!is_string($string)) { |
|
293 | + throw new InvalidArgumentException("Each element of $parameterName must be string."); |
|
294 | 294 | } |
295 | 295 | } |
296 | 296 | } |