@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | CheckResultsRendererFactory $checkResultsRendererFactory, |
117 | 117 | IBufferingStatsdDataFactory $dataFactory |
118 | 118 | ) { |
119 | - parent::__construct( $main, $name ); |
|
119 | + parent::__construct($main, $name); |
|
120 | 120 | $this->entityIdParser = $entityIdParser; |
121 | 121 | $this->statementGuidValidator = $statementGuidValidator; |
122 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
123 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
122 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
123 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
124 | 124 | $this->resultsSource = $resultsSource; |
125 | 125 | $this->checkResultsRendererFactory = $checkResultsRendererFactory; |
126 | 126 | $this->dataFactory = $dataFactory; |
@@ -136,14 +136,14 @@ discard block |
||
136 | 136 | |
137 | 137 | $params = $this->extractRequestParams(); |
138 | 138 | |
139 | - $this->validateParameters( $params ); |
|
140 | - $entityIds = $this->parseEntityIds( $params ); |
|
141 | - $claimIds = $this->parseClaimIds( $params ); |
|
139 | + $this->validateParameters($params); |
|
140 | + $entityIds = $this->parseEntityIds($params); |
|
141 | + $claimIds = $this->parseClaimIds($params); |
|
142 | 142 | $constraintIDs = $params[self::PARAM_CONSTRAINT_ID]; |
143 | 143 | $statuses = $params[self::PARAM_STATUS]; |
144 | 144 | |
145 | 145 | $checkResultsRenderer = $this->checkResultsRendererFactory |
146 | - ->getCheckResultsRenderer( $this->getLanguage() ); |
|
146 | + ->getCheckResultsRenderer($this->getLanguage()); |
|
147 | 147 | |
148 | 148 | $this->getResult()->addValue( |
149 | 149 | null, |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | ) |
158 | 158 | )->getArray() |
159 | 159 | ); |
160 | - $this->resultBuilder->markSuccess( 1 ); |
|
160 | + $this->resultBuilder->markSuccess(1); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -165,24 +165,24 @@ discard block |
||
165 | 165 | * |
166 | 166 | * @return EntityId[] |
167 | 167 | */ |
168 | - private function parseEntityIds( array $params ) { |
|
168 | + private function parseEntityIds(array $params) { |
|
169 | 169 | $ids = $params[self::PARAM_ID]; |
170 | 170 | |
171 | - if ( $ids === null ) { |
|
171 | + if ($ids === null) { |
|
172 | 172 | return []; |
173 | - } elseif ( $ids === [] ) { |
|
173 | + } elseif ($ids === []) { |
|
174 | 174 | $this->errorReporter->dieError( |
175 | - 'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
175 | + 'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
176 | 176 | } |
177 | 177 | |
178 | - return array_map( function ( $id ) { |
|
178 | + return array_map(function($id) { |
|
179 | 179 | try { |
180 | - return $this->entityIdParser->parse( $id ); |
|
181 | - } catch ( EntityIdParsingException $e ) { |
|
180 | + return $this->entityIdParser->parse($id); |
|
181 | + } catch (EntityIdParsingException $e) { |
|
182 | 182 | $this->errorReporter->dieError( |
183 | - "Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] ); |
|
183 | + "Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] ); |
|
184 | 184 | } |
185 | - }, $ids ); |
|
185 | + }, $ids); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -190,35 +190,35 @@ discard block |
||
190 | 190 | * |
191 | 191 | * @return string[] |
192 | 192 | */ |
193 | - private function parseClaimIds( array $params ) { |
|
193 | + private function parseClaimIds(array $params) { |
|
194 | 194 | $ids = $params[self::PARAM_CLAIM_ID]; |
195 | 195 | |
196 | - if ( $ids === null ) { |
|
196 | + if ($ids === null) { |
|
197 | 197 | return []; |
198 | - } elseif ( $ids === [] ) { |
|
198 | + } elseif ($ids === []) { |
|
199 | 199 | $this->errorReporter->dieError( |
200 | - 'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
200 | + 'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
201 | 201 | } |
202 | 202 | |
203 | - foreach ( $ids as $id ) { |
|
204 | - if ( !$this->statementGuidValidator->validate( $id ) ) { |
|
203 | + foreach ($ids as $id) { |
|
204 | + if (!$this->statementGuidValidator->validate($id)) { |
|
205 | 205 | $this->errorReporter->dieError( |
206 | - "Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] ); |
|
206 | + "Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] ); |
|
207 | 207 | } |
208 | 208 | } |
209 | 209 | |
210 | 210 | return $ids; |
211 | 211 | } |
212 | 212 | |
213 | - private function validateParameters( array $params ) { |
|
214 | - if ( $params[self::PARAM_CONSTRAINT_ID] !== null |
|
215 | - && empty( $params[self::PARAM_CONSTRAINT_ID] ) |
|
213 | + private function validateParameters(array $params) { |
|
214 | + if ($params[self::PARAM_CONSTRAINT_ID] !== null |
|
215 | + && empty($params[self::PARAM_CONSTRAINT_ID]) |
|
216 | 216 | ) { |
217 | 217 | $paramConstraintId = self::PARAM_CONSTRAINT_ID; |
218 | 218 | $this->errorReporter->dieError( |
219 | 219 | "If $paramConstraintId is specified, it must be nonempty.", 'no-data' ); |
220 | 220 | } |
221 | - if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) { |
|
221 | + if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) { |
|
222 | 222 | $paramId = self::PARAM_ID; |
223 | 223 | $paramClaimId = self::PARAM_CLAIM_ID; |
224 | 224 | $this->errorReporter->dieError( |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | ], |
260 | 260 | ApiBase::PARAM_ISMULTI => true, |
261 | 261 | ApiBase::PARAM_ALL => true, |
262 | - ApiBase::PARAM_DFLT => implode( '|', CachingResultsSource::CACHED_STATUSES ), |
|
262 | + ApiBase::PARAM_DFLT => implode('|', CachingResultsSource::CACHED_STATUSES), |
|
263 | 263 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [], |
264 | 264 | ], |
265 | 265 | ]; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Message; |
6 | 6 | |
@@ -41,14 +41,14 @@ discard block |
||
41 | 41 | $this->valueFormatterFactory = $valueFormatterFactory; |
42 | 42 | } |
43 | 43 | |
44 | - public function getViolationMessageRenderer( Language $language ): ViolationMessageRenderer { |
|
44 | + public function getViolationMessageRenderer(Language $language): ViolationMessageRenderer { |
|
45 | 45 | $formatterOptions = new FormatterOptions(); |
46 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
46 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
47 | 47 | return new MultilingualTextViolationMessageRenderer( |
48 | 48 | $this->entityIdHtmlLinkFormatterFactory |
49 | - ->getEntityIdFormatter( $language ), |
|
49 | + ->getEntityIdFormatter($language), |
|
50 | 50 | $this->valueFormatterFactory |
51 | - ->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ), |
|
51 | + ->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions), |
|
52 | 52 | $this->messageLocalizer, |
53 | 53 | $this->config |
54 | 54 | ); |
@@ -11,10 +11,10 @@ discard block |
||
11 | 11 | use Wikimedia\Rdbms\ILBFactory; |
12 | 12 | |
13 | 13 | // @codeCoverageIgnoreStart |
14 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
15 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
14 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
15 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
16 | 16 | |
17 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
17 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
18 | 18 | // @codeCoverageIgnoreEnd |
19 | 19 | |
20 | 20 | /** |
@@ -46,57 +46,57 @@ discard block |
||
46 | 46 | |
47 | 47 | public function __construct() { |
48 | 48 | parent::__construct(); |
49 | - $this->newUpdateConstraintsTableJob = static function ( $propertyIdSerialization ) { |
|
49 | + $this->newUpdateConstraintsTableJob = static function($propertyIdSerialization) { |
|
50 | 50 | return UpdateConstraintsTableJob::newFromGlobalState( |
51 | 51 | Title::newMainPage(), |
52 | - [ 'propertyId' => $propertyIdSerialization ] |
|
52 | + ['propertyId' => $propertyIdSerialization] |
|
53 | 53 | ); |
54 | 54 | }; |
55 | 55 | |
56 | - $this->addDescription( 'Imports property constraints from statements on properties' ); |
|
57 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
58 | - $this->setBatchSize( 10 ); |
|
56 | + $this->addDescription('Imports property constraints from statements on properties'); |
|
57 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
58 | + $this->setBatchSize(10); |
|
59 | 59 | |
60 | 60 | // Wikibase classes are not yet loaded, so setup services in a callback run in execute |
61 | 61 | // that can be overridden in tests. |
62 | - $this->setupServices = function () { |
|
62 | + $this->setupServices = function() { |
|
63 | 63 | $services = MediaWikiServices::getInstance(); |
64 | - $this->propertyInfoLookup = WikibaseRepo::getStore( $services )->getPropertyInfoLookup(); |
|
64 | + $this->propertyInfoLookup = WikibaseRepo::getStore($services)->getPropertyInfoLookup(); |
|
65 | 65 | $this->lbFactory = $services->getDBLoadBalancerFactory(); |
66 | 66 | }; |
67 | 67 | } |
68 | 68 | |
69 | 69 | public function execute() { |
70 | - ( $this->setupServices )(); |
|
71 | - if ( !$this->getConfig()->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) ) { |
|
72 | - $this->error( 'Constraint statements are not enabled. Aborting.' ); |
|
70 | + ($this->setupServices)(); |
|
71 | + if (!$this->getConfig()->get('WBQualityConstraintsEnableConstraintsImportFromStatements')) { |
|
72 | + $this->error('Constraint statements are not enabled. Aborting.'); |
|
73 | 73 | return; |
74 | 74 | } |
75 | 75 | |
76 | 76 | $propertyInfos = $this->propertyInfoLookup->getAllPropertyInfo(); |
77 | - $propertyIds = array_keys( $propertyInfos ); |
|
77 | + $propertyIds = array_keys($propertyInfos); |
|
78 | 78 | |
79 | - foreach ( array_chunk( $propertyIds, $this->getBatchSize() ) as $propertyIdsChunk ) { |
|
80 | - foreach ( $propertyIdsChunk as $propertyIdSerialization ) { |
|
81 | - $this->output( sprintf( |
|
79 | + foreach (array_chunk($propertyIds, $this->getBatchSize()) as $propertyIdsChunk) { |
|
80 | + foreach ($propertyIdsChunk as $propertyIdSerialization) { |
|
81 | + $this->output(sprintf( |
|
82 | 82 | 'Importing constraint statements for % 6s... ', |
83 | 83 | $propertyIdSerialization ), |
84 | 84 | $propertyIdSerialization |
85 | 85 | ); |
86 | - $startTime = microtime( true ); |
|
87 | - $job = call_user_func( $this->newUpdateConstraintsTableJob, $propertyIdSerialization ); |
|
86 | + $startTime = microtime(true); |
|
87 | + $job = call_user_func($this->newUpdateConstraintsTableJob, $propertyIdSerialization); |
|
88 | 88 | $job->run(); |
89 | - $endTime = microtime( true ); |
|
90 | - $millis = ( $endTime - $startTime ) * 1000; |
|
91 | - $this->output( sprintf( 'done in % 6.2f ms.', $millis ), $propertyIdSerialization ); |
|
89 | + $endTime = microtime(true); |
|
90 | + $millis = ($endTime - $startTime) * 1000; |
|
91 | + $this->output(sprintf('done in % 6.2f ms.', $millis), $propertyIdSerialization); |
|
92 | 92 | } |
93 | 93 | |
94 | - $this->output( 'Waiting for replication... ', 'waitForReplication' ); |
|
95 | - $startTime = microtime( true ); |
|
94 | + $this->output('Waiting for replication... ', 'waitForReplication'); |
|
95 | + $startTime = microtime(true); |
|
96 | 96 | $this->lbFactory->waitForReplication(); |
97 | - $endTime = microtime( true ); |
|
98 | - $millis = ( $endTime - $startTime ) * 1000; |
|
99 | - $this->output( sprintf( 'done in % 6.2f ms.', $millis ), 'waitForReplication' ); |
|
97 | + $endTime = microtime(true); |
|
98 | + $millis = ($endTime - $startTime) * 1000; |
|
99 | + $this->output(sprintf('done in % 6.2f ms.', $millis), 'waitForReplication'); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 |
@@ -142,14 +142,14 @@ discard block |
||
142 | 142 | ) { |
143 | 143 | $results = []; |
144 | 144 | $metadatas = []; |
145 | - if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
145 | + if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
146 | 146 | $storedEntityIds = []; |
147 | - foreach ( $entityIds as $entityId ) { |
|
148 | - $storedResults = $this->getStoredResults( $entityId ); |
|
149 | - if ( $storedResults !== null ) { |
|
150 | - $this->loggingHelper->logCheckConstraintsCacheHit( $entityId ); |
|
151 | - foreach ( $storedResults->getArray() as $checkResult ) { |
|
152 | - if ( $this->statusSelected( $statuses, $checkResult ) ) { |
|
147 | + foreach ($entityIds as $entityId) { |
|
148 | + $storedResults = $this->getStoredResults($entityId); |
|
149 | + if ($storedResults !== null) { |
|
150 | + $this->loggingHelper->logCheckConstraintsCacheHit($entityId); |
|
151 | + foreach ($storedResults->getArray() as $checkResult) { |
|
152 | + if ($this->statusSelected($statuses, $checkResult)) { |
|
153 | 153 | $results[] = $checkResult; |
154 | 154 | } |
155 | 155 | } |
@@ -157,19 +157,19 @@ discard block |
||
157 | 157 | $storedEntityIds[] = $entityId; |
158 | 158 | } |
159 | 159 | } |
160 | - $entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) ); |
|
160 | + $entityIds = array_values(array_diff($entityIds, $storedEntityIds)); |
|
161 | 161 | } |
162 | - if ( $entityIds !== [] || $claimIds !== [] ) { |
|
163 | - if ( $entityIds !== [] ) { |
|
164 | - $this->loggingHelper->logCheckConstraintsCacheMisses( $entityIds ); |
|
162 | + if ($entityIds !== [] || $claimIds !== []) { |
|
163 | + if ($entityIds !== []) { |
|
164 | + $this->loggingHelper->logCheckConstraintsCacheMisses($entityIds); |
|
165 | 165 | } |
166 | - $response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
167 | - $results = array_merge( $results, $response->getArray() ); |
|
166 | + $response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
167 | + $results = array_merge($results, $response->getArray()); |
|
168 | 168 | $metadatas[] = $response->getMetadata(); |
169 | 169 | } |
170 | 170 | return new CachedCheckResults( |
171 | 171 | $results, |
172 | - Metadata::merge( $metadatas ) |
|
172 | + Metadata::merge($metadatas) |
|
173 | 173 | ); |
174 | 174 | } |
175 | 175 | |
@@ -192,13 +192,13 @@ discard block |
||
192 | 192 | ?array $constraintIds, |
193 | 193 | array $statuses |
194 | 194 | ) { |
195 | - if ( $claimIds !== [] ) { |
|
195 | + if ($claimIds !== []) { |
|
196 | 196 | return false; |
197 | 197 | } |
198 | - if ( $constraintIds !== null ) { |
|
198 | + if ($constraintIds !== null) { |
|
199 | 199 | return false; |
200 | 200 | } |
201 | - if ( array_diff( $statuses, self::CACHED_STATUSES ) !== [] ) { |
|
201 | + if (array_diff($statuses, self::CACHED_STATUSES) !== []) { |
|
202 | 202 | return false; |
203 | 203 | } |
204 | 204 | return true; |
@@ -213,8 +213,8 @@ discard block |
||
213 | 213 | * @param CheckResult $result |
214 | 214 | * @return bool |
215 | 215 | */ |
216 | - private function statusSelected( array $statuses, CheckResult $result ) { |
|
217 | - return in_array( $result->getStatus(), $statuses, true ) || |
|
216 | + private function statusSelected(array $statuses, CheckResult $result) { |
|
217 | + return in_array($result->getStatus(), $statuses, true) || |
|
218 | 218 | $result instanceof NullResult; |
219 | 219 | } |
220 | 220 | |
@@ -231,11 +231,11 @@ discard block |
||
231 | 231 | ?array $constraintIds, |
232 | 232 | array $statuses |
233 | 233 | ) { |
234 | - $results = $this->resultsSource->getResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
234 | + $results = $this->resultsSource->getResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
235 | 235 | |
236 | - if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
237 | - foreach ( $entityIds as $entityId ) { |
|
238 | - $this->storeResults( $entityId, $results ); |
|
236 | + if ($this->canStoreResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
237 | + foreach ($entityIds as $entityId) { |
|
238 | + $this->storeResults($entityId, $results); |
|
239 | 239 | } |
240 | 240 | } |
241 | 241 | |
@@ -266,10 +266,10 @@ discard block |
||
266 | 266 | ?array $constraintIds, |
267 | 267 | array $statuses |
268 | 268 | ) { |
269 | - if ( $constraintIds !== null ) { |
|
269 | + if ($constraintIds !== null) { |
|
270 | 270 | return false; |
271 | 271 | } |
272 | - if ( array_diff( self::CACHED_STATUSES, $statuses ) !== [] ) { |
|
272 | + if (array_diff(self::CACHED_STATUSES, $statuses) !== []) { |
|
273 | 273 | return false; |
274 | 274 | } |
275 | 275 | return true; |
@@ -283,21 +283,21 @@ discard block |
||
283 | 283 | * May include check results for other entity IDs as well, |
284 | 284 | * or check results with statuses that we’re not interested in caching. |
285 | 285 | */ |
286 | - private function storeResults( EntityId $entityId, CachedCheckResults $results ) { |
|
286 | + private function storeResults(EntityId $entityId, CachedCheckResults $results) { |
|
287 | 287 | $latestRevisionIds = $this->getLatestRevisionIds( |
288 | 288 | $results->getMetadata()->getDependencyMetadata()->getEntityIds() |
289 | 289 | ); |
290 | - if ( $latestRevisionIds === null ) { |
|
290 | + if ($latestRevisionIds === null) { |
|
291 | 291 | return; |
292 | 292 | } |
293 | 293 | |
294 | 294 | $resultSerializations = []; |
295 | - foreach ( $results->getArray() as $checkResult ) { |
|
296 | - if ( $checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization() ) { |
|
295 | + foreach ($results->getArray() as $checkResult) { |
|
296 | + if ($checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization()) { |
|
297 | 297 | continue; |
298 | 298 | } |
299 | - if ( $this->statusSelected( self::CACHED_STATUSES, $checkResult ) ) { |
|
300 | - $resultSerializations[] = $this->checkResultSerializer->serialize( $checkResult ); |
|
299 | + if ($this->statusSelected(self::CACHED_STATUSES, $checkResult)) { |
|
300 | + $resultSerializations[] = $this->checkResultSerializer->serialize($checkResult); |
|
301 | 301 | } |
302 | 302 | } |
303 | 303 | |
@@ -306,11 +306,11 @@ discard block |
||
306 | 306 | 'latestRevisionIds' => $latestRevisionIds, |
307 | 307 | ]; |
308 | 308 | $futureTime = $results->getMetadata()->getDependencyMetadata()->getFutureTime(); |
309 | - if ( $futureTime !== null ) { |
|
309 | + if ($futureTime !== null) { |
|
310 | 310 | $value['futureTime'] = $futureTime->getArrayValue(); |
311 | 311 | } |
312 | 312 | |
313 | - $this->cache->set( $entityId, $value, $this->ttlInSeconds ); |
|
313 | + $this->cache->set($entityId, $value, $this->ttlInSeconds); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | /** |
@@ -324,31 +324,30 @@ discard block |
||
324 | 324 | EntityId $entityId, |
325 | 325 | $forRevision = 0 |
326 | 326 | ) { |
327 | - $value = $this->cache->get( $entityId, $curTTL, [], $asOf ); |
|
328 | - $now = call_user_func( $this->microtime, true ); |
|
327 | + $value = $this->cache->get($entityId, $curTTL, [], $asOf); |
|
328 | + $now = call_user_func($this->microtime, true); |
|
329 | 329 | |
330 | - $dependencyMetadata = $this->checkDependencyMetadata( $value, |
|
331 | - [ $entityId->getSerialization() => $forRevision ] ); |
|
332 | - if ( $dependencyMetadata === null ) { |
|
330 | + $dependencyMetadata = $this->checkDependencyMetadata($value, |
|
331 | + [$entityId->getSerialization() => $forRevision]); |
|
332 | + if ($dependencyMetadata === null) { |
|
333 | 333 | return null; |
334 | 334 | } |
335 | 335 | |
336 | - $ageInSeconds = (int)ceil( $now - $asOf ); |
|
336 | + $ageInSeconds = (int) ceil($now - $asOf); |
|
337 | 337 | $cachingMetadata = $ageInSeconds > 0 ? |
338 | - CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) : |
|
339 | - CachingMetadata::fresh(); |
|
338 | + CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh(); |
|
340 | 339 | |
341 | 340 | $results = []; |
342 | - foreach ( $value['results'] as $resultSerialization ) { |
|
343 | - $results[] = $this->deserializeCheckResult( $resultSerialization, $cachingMetadata ); |
|
341 | + foreach ($value['results'] as $resultSerialization) { |
|
342 | + $results[] = $this->deserializeCheckResult($resultSerialization, $cachingMetadata); |
|
344 | 343 | } |
345 | 344 | |
346 | 345 | return new CachedCheckResults( |
347 | 346 | $results, |
348 | - Metadata::merge( [ |
|
349 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
350 | - Metadata::ofDependencyMetadata( $dependencyMetadata ), |
|
351 | - ] ) |
|
347 | + Metadata::merge([ |
|
348 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
349 | + Metadata::ofDependencyMetadata($dependencyMetadata), |
|
350 | + ]) |
|
352 | 351 | ); |
353 | 352 | } |
354 | 353 | |
@@ -364,43 +363,43 @@ discard block |
||
364 | 363 | * @return DependencyMetadata|null the dependency metadata, |
365 | 364 | * or null if $value should no longer be used |
366 | 365 | */ |
367 | - private function checkDependencyMetadata( $value, $paramRevs ) { |
|
368 | - if ( $value === false ) { |
|
366 | + private function checkDependencyMetadata($value, $paramRevs) { |
|
367 | + if ($value === false) { |
|
369 | 368 | return null; |
370 | 369 | } |
371 | 370 | |
372 | - if ( array_key_exists( 'futureTime', $value ) ) { |
|
373 | - $futureTime = TimeValue::newFromArray( $value['futureTime'] ); |
|
374 | - if ( !$this->timeValueComparer->isFutureTime( $futureTime ) ) { |
|
371 | + if (array_key_exists('futureTime', $value)) { |
|
372 | + $futureTime = TimeValue::newFromArray($value['futureTime']); |
|
373 | + if (!$this->timeValueComparer->isFutureTime($futureTime)) { |
|
375 | 374 | return null; |
376 | 375 | } |
377 | - $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime( $futureTime ); |
|
376 | + $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime($futureTime); |
|
378 | 377 | } else { |
379 | 378 | $futureTimeDependencyMetadata = DependencyMetadata::blank(); |
380 | 379 | } |
381 | 380 | |
382 | - foreach ( $paramRevs as $id => $revision ) { |
|
383 | - if ( $revision > 0 ) { |
|
384 | - $value['latestRevisionIds'][$id] = min( $revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX ); |
|
381 | + foreach ($paramRevs as $id => $revision) { |
|
382 | + if ($revision > 0) { |
|
383 | + $value['latestRevisionIds'][$id] = min($revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX); |
|
385 | 384 | } |
386 | 385 | } |
387 | 386 | |
388 | 387 | $dependedEntityIds = array_map( |
389 | - [ $this->entityIdParser, "parse" ], |
|
390 | - array_keys( $value['latestRevisionIds'] ) |
|
388 | + [$this->entityIdParser, "parse"], |
|
389 | + array_keys($value['latestRevisionIds']) |
|
391 | 390 | ); |
392 | 391 | |
393 | - if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) { |
|
392 | + if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) { |
|
394 | 393 | return null; |
395 | 394 | } |
396 | 395 | |
397 | 396 | return array_reduce( |
398 | 397 | $dependedEntityIds, |
399 | - static function ( DependencyMetadata $metadata, EntityId $entityId ) { |
|
400 | - return DependencyMetadata::merge( [ |
|
398 | + static function(DependencyMetadata $metadata, EntityId $entityId) { |
|
399 | + return DependencyMetadata::merge([ |
|
401 | 400 | $metadata, |
402 | - DependencyMetadata::ofEntityId( $entityId ) |
|
403 | - ] ); |
|
401 | + DependencyMetadata::ofEntityId($entityId) |
|
402 | + ]); |
|
404 | 403 | }, |
405 | 404 | $futureTimeDependencyMetadata |
406 | 405 | ); |
@@ -420,13 +419,13 @@ discard block |
||
420 | 419 | array $resultSerialization, |
421 | 420 | CachingMetadata $cachingMetadata |
422 | 421 | ) { |
423 | - $result = $this->checkResultDeserializer->deserialize( $resultSerialization ); |
|
424 | - if ( $this->isPossiblyStaleResult( $result ) ) { |
|
422 | + $result = $this->checkResultDeserializer->deserialize($resultSerialization); |
|
423 | + if ($this->isPossiblyStaleResult($result)) { |
|
425 | 424 | $result->withMetadata( |
426 | - Metadata::merge( [ |
|
425 | + Metadata::merge([ |
|
427 | 426 | $result->getMetadata(), |
428 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
429 | - ] ) |
|
427 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
428 | + ]) |
|
430 | 429 | ); |
431 | 430 | } |
432 | 431 | return $result; |
@@ -436,8 +435,8 @@ discard block |
||
436 | 435 | * @param CheckResult $result |
437 | 436 | * @return bool |
438 | 437 | */ |
439 | - private function isPossiblyStaleResult( CheckResult $result ) { |
|
440 | - if ( $result instanceof NullResult ) { |
|
438 | + private function isPossiblyStaleResult(CheckResult $result) { |
|
439 | + if ($result instanceof NullResult) { |
|
441 | 440 | return false; |
442 | 441 | } |
443 | 442 | |
@@ -452,14 +451,14 @@ discard block |
||
452 | 451 | * @return int[]|null array from entity ID serializations to revision ID, |
453 | 452 | * or null to indicate that not all revision IDs could be loaded |
454 | 453 | */ |
455 | - private function getLatestRevisionIds( array $entityIds ) { |
|
456 | - if ( $entityIds === [] ) { |
|
454 | + private function getLatestRevisionIds(array $entityIds) { |
|
455 | + if ($entityIds === []) { |
|
457 | 456 | $this->loggingHelper->logEmptyDependencyMetadata(); |
458 | 457 | return []; |
459 | 458 | } |
460 | - if ( count( $entityIds ) > $this->maxRevisionIds ) { |
|
459 | + if (count($entityIds) > $this->maxRevisionIds) { |
|
461 | 460 | // one of those entities will probably be edited soon, so might as well skip caching |
462 | - $this->loggingHelper->logHugeDependencyMetadata( $entityIds, $this->maxRevisionIds ); |
|
461 | + $this->loggingHelper->logHugeDependencyMetadata($entityIds, $this->maxRevisionIds); |
|
463 | 462 | return null; |
464 | 463 | } |
465 | 464 | |
@@ -467,7 +466,7 @@ discard block |
||
467 | 466 | $entityIds, |
468 | 467 | LookupConstants::LATEST_FROM_REPLICA |
469 | 468 | ); |
470 | - if ( $this->hasFalseElements( $latestRevisionIds ) ) { |
|
469 | + if ($this->hasFalseElements($latestRevisionIds)) { |
|
471 | 470 | return null; |
472 | 471 | } |
473 | 472 | return $latestRevisionIds; |
@@ -477,8 +476,8 @@ discard block |
||
477 | 476 | * @param array $array |
478 | 477 | * @return bool |
479 | 478 | */ |
480 | - private function hasFalseElements( array $array ) { |
|
481 | - return in_array( false, $array, true ); |
|
479 | + private function hasFalseElements(array $array) { |
|
480 | + return in_array(false, $array, true); |
|
482 | 481 | } |
483 | 482 | |
484 | 483 | /** |
@@ -486,7 +485,7 @@ discard block |
||
486 | 485 | * |
487 | 486 | * @param callable $microtime |
488 | 487 | */ |
489 | - public function setMicrotimeFunction( callable $microtime ) { |
|
488 | + public function setMicrotimeFunction(callable $microtime) { |
|
490 | 489 | $this->microtime = $microtime; |
491 | 490 | } |
492 | 491 |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | Config $config, |
135 | 135 | IBufferingStatsdDataFactory $dataFactory |
136 | 136 | ) { |
137 | - parent::__construct( 'ConstraintReport' ); |
|
137 | + parent::__construct('ConstraintReport'); |
|
138 | 138 | |
139 | 139 | $this->entityLookup = $entityLookup; |
140 | 140 | $this->entityTitleLookup = $entityTitleLookup; |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | $language = $this->getLanguage(); |
144 | 144 | |
145 | 145 | $formatterOptions = new FormatterOptions(); |
146 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
146 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
147 | 147 | $this->dataValueFormatter = $valueFormatterFactory->getValueFormatter( |
148 | 148 | SnakFormatter::FORMAT_HTML, |
149 | 149 | $formatterOptions |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @return string |
204 | 204 | */ |
205 | 205 | public function getDescription() { |
206 | - return $this->msg( 'wbqc-constraintreport' )->escaped(); |
|
206 | + return $this->msg('wbqc-constraintreport')->escaped(); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -215,43 +215,43 @@ discard block |
||
215 | 215 | * @throws EntityIdParsingException |
216 | 216 | * @throws UnexpectedValueException |
217 | 217 | */ |
218 | - public function execute( $subPage ) { |
|
218 | + public function execute($subPage) { |
|
219 | 219 | $out = $this->getOutput(); |
220 | 220 | |
221 | - $postRequest = $this->getContext()->getRequest()->getVal( 'entityid' ); |
|
222 | - if ( $postRequest ) { |
|
223 | - $out->redirect( $this->getPageTitle( strtoupper( $postRequest ) )->getLocalURL() ); |
|
221 | + $postRequest = $this->getContext()->getRequest()->getVal('entityid'); |
|
222 | + if ($postRequest) { |
|
223 | + $out->redirect($this->getPageTitle(strtoupper($postRequest))->getLocalURL()); |
|
224 | 224 | return; |
225 | 225 | } |
226 | 226 | |
227 | 227 | $out->enableOOUI(); |
228 | - $out->addModules( $this->getModules() ); |
|
228 | + $out->addModules($this->getModules()); |
|
229 | 229 | |
230 | 230 | $this->setHeaders(); |
231 | 231 | |
232 | - $out->addHTML( $this->getExplanationText() ); |
|
232 | + $out->addHTML($this->getExplanationText()); |
|
233 | 233 | $this->buildEntityIdForm(); |
234 | 234 | |
235 | - if ( !$subPage ) { |
|
235 | + if (!$subPage) { |
|
236 | 236 | return; |
237 | 237 | } |
238 | 238 | |
239 | - if ( !is_string( $subPage ) ) { |
|
240 | - throw new InvalidArgumentException( '$subPage must be string.' ); |
|
239 | + if (!is_string($subPage)) { |
|
240 | + throw new InvalidArgumentException('$subPage must be string.'); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | try { |
244 | - $entityId = $this->entityIdParser->parse( $subPage ); |
|
245 | - } catch ( EntityIdParsingException $e ) { |
|
244 | + $entityId = $this->entityIdParser->parse($subPage); |
|
245 | + } catch (EntityIdParsingException $e) { |
|
246 | 246 | $out->addHTML( |
247 | - $this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true ) |
|
247 | + $this->buildNotice('wbqc-constraintreport-invalid-entity-id', true) |
|
248 | 248 | ); |
249 | 249 | return; |
250 | 250 | } |
251 | 251 | |
252 | - if ( !$this->entityLookup->hasEntity( $entityId ) ) { |
|
252 | + if (!$this->entityLookup->hasEntity($entityId)) { |
|
253 | 253 | $out->addHTML( |
254 | - $this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true ) |
|
254 | + $this->buildNotice('wbqc-constraintreport-not-existent-entity', true) |
|
255 | 255 | ); |
256 | 256 | return; |
257 | 257 | } |
@@ -259,18 +259,18 @@ discard block |
||
259 | 259 | $this->dataFactory->increment( |
260 | 260 | 'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck' |
261 | 261 | ); |
262 | - $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId ); |
|
262 | + $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId); |
|
263 | 263 | |
264 | - if ( $results !== [] ) { |
|
264 | + if ($results !== []) { |
|
265 | 265 | $out->addHTML( |
266 | - $this->buildResultHeader( $entityId ) |
|
267 | - . $this->buildSummary( $results ) |
|
268 | - . $this->buildResultTable( $entityId, $results ) |
|
266 | + $this->buildResultHeader($entityId) |
|
267 | + . $this->buildSummary($results) |
|
268 | + . $this->buildResultTable($entityId, $results) |
|
269 | 269 | ); |
270 | 270 | } else { |
271 | 271 | $out->addHTML( |
272 | - $this->buildResultHeader( $entityId ) |
|
273 | - . $this->buildNotice( 'wbqc-constraintreport-empty-result' ) |
|
272 | + $this->buildResultHeader($entityId) |
|
273 | + . $this->buildNotice('wbqc-constraintreport-empty-result') |
|
274 | 274 | ); |
275 | 275 | } |
276 | 276 | } |
@@ -286,15 +286,15 @@ discard block |
||
286 | 286 | 'name' => 'entityid', |
287 | 287 | 'label-message' => 'wbqc-constraintreport-form-entityid-label', |
288 | 288 | 'cssclass' => 'wbqc-constraintreport-form-entity-id', |
289 | - 'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->escaped() |
|
289 | + 'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->escaped() |
|
290 | 290 | ] |
291 | 291 | ]; |
292 | - $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form' ); |
|
293 | - $htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->escaped() ); |
|
294 | - $htmlForm->setSubmitCallback( static function () { |
|
292 | + $htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form'); |
|
293 | + $htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->escaped()); |
|
294 | + $htmlForm->setSubmitCallback(static function() { |
|
295 | 295 | return false; |
296 | 296 | } ); |
297 | - $htmlForm->setMethod( 'post' ); |
|
297 | + $htmlForm->setMethod('post'); |
|
298 | 298 | $htmlForm->show(); |
299 | 299 | } |
300 | 300 | |
@@ -308,16 +308,16 @@ discard block |
||
308 | 308 | * |
309 | 309 | * @return string HTML |
310 | 310 | */ |
311 | - private function buildNotice( $messageKey, $error = false ) { |
|
312 | - if ( !is_string( $messageKey ) ) { |
|
313 | - throw new InvalidArgumentException( '$message must be string.' ); |
|
311 | + private function buildNotice($messageKey, $error = false) { |
|
312 | + if (!is_string($messageKey)) { |
|
313 | + throw new InvalidArgumentException('$message must be string.'); |
|
314 | 314 | } |
315 | - if ( !is_bool( $error ) ) { |
|
316 | - throw new InvalidArgumentException( '$error must be bool.' ); |
|
315 | + if (!is_bool($error)) { |
|
316 | + throw new InvalidArgumentException('$error must be bool.'); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | $cssClasses = 'wbqc-constraintreport-notice'; |
320 | - if ( $error ) { |
|
320 | + if ($error) { |
|
321 | 321 | $cssClasses .= ' wbqc-constraintreport-notice-error'; |
322 | 322 | } |
323 | 323 | |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | [ |
327 | 327 | 'class' => $cssClasses |
328 | 328 | ], |
329 | - $this->msg( $messageKey )->escaped() |
|
329 | + $this->msg($messageKey)->escaped() |
|
330 | 330 | ); |
331 | 331 | } |
332 | 332 | |
@@ -336,16 +336,16 @@ discard block |
||
336 | 336 | private function getExplanationText() { |
337 | 337 | return Html::rawElement( |
338 | 338 | 'div', |
339 | - [ 'class' => 'wbqc-explanation' ], |
|
339 | + ['class' => 'wbqc-explanation'], |
|
340 | 340 | Html::rawElement( |
341 | 341 | 'p', |
342 | 342 | [], |
343 | - $this->msg( 'wbqc-constraintreport-explanation-part-one' )->escaped() |
|
343 | + $this->msg('wbqc-constraintreport-explanation-part-one')->escaped() |
|
344 | 344 | ) |
345 | 345 | . Html::rawElement( |
346 | 346 | 'p', |
347 | 347 | [], |
348 | - $this->msg( 'wbqc-constraintreport-explanation-part-two' )->escaped() |
|
348 | + $this->msg('wbqc-constraintreport-explanation-part-two')->escaped() |
|
349 | 349 | ) |
350 | 350 | ); |
351 | 351 | } |
@@ -357,72 +357,72 @@ discard block |
||
357 | 357 | * @return string HTML |
358 | 358 | * @suppress SecurityCheck-DoubleEscaped |
359 | 359 | */ |
360 | - private function buildResultTable( EntityId $entityId, array $results ) { |
|
360 | + private function buildResultTable(EntityId $entityId, array $results) { |
|
361 | 361 | // Set table headers |
362 | 362 | $table = new HtmlTableBuilder( |
363 | 363 | [ |
364 | 364 | new HtmlTableHeaderBuilder( |
365 | - $this->msg( 'wbqc-constraintreport-result-table-header-status' )->escaped(), |
|
365 | + $this->msg('wbqc-constraintreport-result-table-header-status')->escaped(), |
|
366 | 366 | true |
367 | 367 | ), |
368 | 368 | new HtmlTableHeaderBuilder( |
369 | - $this->msg( 'wbqc-constraintreport-result-table-header-property' )->escaped(), |
|
369 | + $this->msg('wbqc-constraintreport-result-table-header-property')->escaped(), |
|
370 | 370 | true |
371 | 371 | ), |
372 | 372 | new HtmlTableHeaderBuilder( |
373 | - $this->msg( 'wbqc-constraintreport-result-table-header-message' )->escaped(), |
|
373 | + $this->msg('wbqc-constraintreport-result-table-header-message')->escaped(), |
|
374 | 374 | true |
375 | 375 | ), |
376 | 376 | new HtmlTableHeaderBuilder( |
377 | - $this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->escaped(), |
|
377 | + $this->msg('wbqc-constraintreport-result-table-header-constraint')->escaped(), |
|
378 | 378 | true |
379 | 379 | ) |
380 | 380 | ] |
381 | 381 | ); |
382 | 382 | |
383 | - foreach ( $results as $result ) { |
|
384 | - $table = $this->appendToResultTable( $table, $entityId, $result ); |
|
383 | + foreach ($results as $result) { |
|
384 | + $table = $this->appendToResultTable($table, $entityId, $result); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | return $table->toHtml(); |
388 | 388 | } |
389 | 389 | |
390 | - private function appendToResultTable( HtmlTableBuilder $table, EntityId $entityId, CheckResult $result ) { |
|
390 | + private function appendToResultTable(HtmlTableBuilder $table, EntityId $entityId, CheckResult $result) { |
|
391 | 391 | $message = $result->getMessage(); |
392 | - if ( $message === null ) { |
|
392 | + if ($message === null) { |
|
393 | 393 | // no row for this result |
394 | 394 | return $table; |
395 | 395 | } |
396 | 396 | |
397 | 397 | // Status column |
398 | - $statusColumn = $this->formatStatus( $result->getStatus() ); |
|
398 | + $statusColumn = $this->formatStatus($result->getStatus()); |
|
399 | 399 | |
400 | 400 | // Property column |
401 | - $propertyId = new PropertyId( $result->getContextCursor()->getSnakPropertyId() ); |
|
401 | + $propertyId = new PropertyId($result->getContextCursor()->getSnakPropertyId()); |
|
402 | 402 | $propertyColumn = $this->getClaimLink( |
403 | 403 | $entityId, |
404 | 404 | $propertyId, |
405 | - $this->entityIdLabelFormatter->formatEntityId( $propertyId ) |
|
405 | + $this->entityIdLabelFormatter->formatEntityId($propertyId) |
|
406 | 406 | ); |
407 | 407 | |
408 | 408 | // Message column |
409 | - $messageColumn = $this->violationMessageRenderer->render( $message ); |
|
409 | + $messageColumn = $this->violationMessageRenderer->render($message); |
|
410 | 410 | |
411 | 411 | // Constraint column |
412 | 412 | $constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId(); |
413 | 413 | try { |
414 | - $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) ); |
|
415 | - } catch ( InvalidArgumentException $e ) { |
|
416 | - $constraintTypeLabel = htmlspecialchars( $constraintTypeItemId ); |
|
414 | + $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId)); |
|
415 | + } catch (InvalidArgumentException $e) { |
|
416 | + $constraintTypeLabel = htmlspecialchars($constraintTypeItemId); |
|
417 | 417 | } |
418 | 418 | $constraintLink = $this->getClaimLink( |
419 | 419 | $propertyId, |
420 | - new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ), |
|
420 | + new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')), |
|
421 | 421 | $constraintTypeLabel |
422 | 422 | ); |
423 | 423 | $constraintColumn = $this->buildExpandableElement( |
424 | 424 | $constraintLink, |
425 | - $this->constraintParameterRenderer->formatParameters( $result->getParameters() ), |
|
425 | + $this->constraintParameterRenderer->formatParameters($result->getParameters()), |
|
426 | 426 | '[...]' |
427 | 427 | ); |
428 | 428 | |
@@ -462,15 +462,15 @@ discard block |
||
462 | 462 | * |
463 | 463 | * @return string HTML |
464 | 464 | */ |
465 | - protected function buildResultHeader( EntityId $entityId ) { |
|
466 | - $entityLink = sprintf( '%s (%s)', |
|
467 | - $this->entityIdLinkFormatter->formatEntityId( $entityId ), |
|
468 | - htmlspecialchars( $entityId->getSerialization() ) ); |
|
465 | + protected function buildResultHeader(EntityId $entityId) { |
|
466 | + $entityLink = sprintf('%s (%s)', |
|
467 | + $this->entityIdLinkFormatter->formatEntityId($entityId), |
|
468 | + htmlspecialchars($entityId->getSerialization())); |
|
469 | 469 | |
470 | 470 | return Html::rawElement( |
471 | 471 | 'h3', |
472 | 472 | [], |
473 | - sprintf( '%s %s', $this->msg( 'wbqc-constraintreport-result-headline' )->escaped(), $entityLink ) |
|
473 | + sprintf('%s %s', $this->msg('wbqc-constraintreport-result-headline')->escaped(), $entityLink) |
|
474 | 474 | ); |
475 | 475 | } |
476 | 476 | |
@@ -481,24 +481,24 @@ discard block |
||
481 | 481 | * |
482 | 482 | * @return string HTML |
483 | 483 | */ |
484 | - protected function buildSummary( array $results ) { |
|
484 | + protected function buildSummary(array $results) { |
|
485 | 485 | $statuses = []; |
486 | - foreach ( $results as $result ) { |
|
487 | - $status = strtolower( $result->getStatus() ); |
|
488 | - $statuses[$status] = isset( $statuses[$status] ) ? $statuses[$status] + 1 : 1; |
|
486 | + foreach ($results as $result) { |
|
487 | + $status = strtolower($result->getStatus()); |
|
488 | + $statuses[$status] = isset($statuses[$status]) ? $statuses[$status] + 1 : 1; |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | $statusElements = []; |
492 | - foreach ( $statuses as $status => $count ) { |
|
493 | - if ( $count > 0 ) { |
|
492 | + foreach ($statuses as $status => $count) { |
|
493 | + if ($count > 0) { |
|
494 | 494 | $statusElements[] = |
495 | - $this->formatStatus( $status ) |
|
495 | + $this->formatStatus($status) |
|
496 | 496 | . ': ' |
497 | 497 | . $count; |
498 | 498 | } |
499 | 499 | } |
500 | 500 | |
501 | - return Html::rawElement( 'p', [], implode( ', ', $statusElements ) ); |
|
501 | + return Html::rawElement('p', [], implode(', ', $statusElements)); |
|
502 | 502 | } |
503 | 503 | |
504 | 504 | /** |
@@ -513,15 +513,15 @@ discard block |
||
513 | 513 | * |
514 | 514 | * @return string HTML |
515 | 515 | */ |
516 | - protected function buildExpandableElement( $content, $expandableContent, $indicator ) { |
|
517 | - if ( !is_string( $content ) ) { |
|
518 | - throw new InvalidArgumentException( '$content has to be string.' ); |
|
516 | + protected function buildExpandableElement($content, $expandableContent, $indicator) { |
|
517 | + if (!is_string($content)) { |
|
518 | + throw new InvalidArgumentException('$content has to be string.'); |
|
519 | 519 | } |
520 | - if ( $expandableContent && ( !is_string( $expandableContent ) ) ) { |
|
521 | - throw new InvalidArgumentException( '$tooltipContent, if provided, has to be string.' ); |
|
520 | + if ($expandableContent && (!is_string($expandableContent))) { |
|
521 | + throw new InvalidArgumentException('$tooltipContent, if provided, has to be string.'); |
|
522 | 522 | } |
523 | 523 | |
524 | - if ( empty( $expandableContent ) ) { |
|
524 | + if (empty($expandableContent)) { |
|
525 | 525 | return $content; |
526 | 526 | } |
527 | 527 | |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | $expandableContent |
542 | 542 | ); |
543 | 543 | |
544 | - return sprintf( '%s %s %s', $content, $tooltipIndicator, $wrappedExpandableContent ); |
|
544 | + return sprintf('%s %s %s', $content, $tooltipIndicator, $wrappedExpandableContent); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
@@ -553,8 +553,8 @@ discard block |
||
553 | 553 | * |
554 | 554 | * @return string HTML |
555 | 555 | */ |
556 | - private function formatStatus( $status ) { |
|
557 | - $messageName = "wbqc-constraintreport-status-" . strtolower( $status ); |
|
556 | + private function formatStatus($status) { |
|
557 | + $messageName = "wbqc-constraintreport-status-".strtolower($status); |
|
558 | 558 | $statusIcons = [ |
559 | 559 | CheckResult::STATUS_SUGGESTION => [ |
560 | 560 | 'icon' => 'suggestion-constraint-violation', |
@@ -571,25 +571,25 @@ discard block |
||
571 | 571 | ], |
572 | 572 | ]; |
573 | 573 | |
574 | - if ( array_key_exists( $status, $statusIcons ) ) { |
|
575 | - $iconWidget = new IconWidget( $statusIcons[$status] ); |
|
576 | - $iconHtml = $iconWidget->toString() . ' '; |
|
574 | + if (array_key_exists($status, $statusIcons)) { |
|
575 | + $iconWidget = new IconWidget($statusIcons[$status]); |
|
576 | + $iconHtml = $iconWidget->toString().' '; |
|
577 | 577 | } else { |
578 | 578 | $iconHtml = ''; |
579 | 579 | } |
580 | 580 | |
581 | - $labelWidget = new LabelWidget( [ |
|
582 | - 'label' => $this->msg( $messageName )->text(), |
|
583 | - ] ); |
|
581 | + $labelWidget = new LabelWidget([ |
|
582 | + 'label' => $this->msg($messageName)->text(), |
|
583 | + ]); |
|
584 | 584 | $labelHtml = $labelWidget->toString(); |
585 | 585 | |
586 | 586 | $formattedStatus = |
587 | 587 | Html::rawElement( |
588 | 588 | 'span', |
589 | 589 | [ |
590 | - 'class' => 'wbqc-status wbqc-status-' . $status |
|
590 | + 'class' => 'wbqc-status wbqc-status-'.$status |
|
591 | 591 | ], |
592 | - $iconHtml . $labelHtml |
|
592 | + $iconHtml.$labelHtml |
|
593 | 593 | ); |
594 | 594 | |
595 | 595 | return $formattedStatus; |
@@ -605,26 +605,26 @@ discard block |
||
605 | 605 | * |
606 | 606 | * @return string HTML |
607 | 607 | */ |
608 | - protected function formatDataValues( $dataValues, $separator = ', ' ) { |
|
609 | - if ( $dataValues instanceof DataValue ) { |
|
610 | - $dataValues = [ $dataValues ]; |
|
611 | - } elseif ( !is_array( $dataValues ) ) { |
|
612 | - throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' ); |
|
608 | + protected function formatDataValues($dataValues, $separator = ', ') { |
|
609 | + if ($dataValues instanceof DataValue) { |
|
610 | + $dataValues = [$dataValues]; |
|
611 | + } elseif (!is_array($dataValues)) { |
|
612 | + throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.'); |
|
613 | 613 | } |
614 | 614 | |
615 | 615 | $formattedDataValues = []; |
616 | - foreach ( $dataValues as $dataValue ) { |
|
617 | - if ( !( $dataValue instanceof DataValue ) ) { |
|
618 | - throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' ); |
|
616 | + foreach ($dataValues as $dataValue) { |
|
617 | + if (!($dataValue instanceof DataValue)) { |
|
618 | + throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.'); |
|
619 | 619 | } |
620 | - if ( $dataValue instanceof EntityIdValue ) { |
|
621 | - $formattedDataValues[ ] = $this->entityIdLabelFormatter->formatEntityId( $dataValue->getEntityId() ); |
|
620 | + if ($dataValue instanceof EntityIdValue) { |
|
621 | + $formattedDataValues[] = $this->entityIdLabelFormatter->formatEntityId($dataValue->getEntityId()); |
|
622 | 622 | } else { |
623 | - $formattedDataValues[ ] = $this->dataValueFormatter->format( $dataValue ); |
|
623 | + $formattedDataValues[] = $this->dataValueFormatter->format($dataValue); |
|
624 | 624 | } |
625 | 625 | } |
626 | 626 | |
627 | - return implode( $separator, $formattedDataValues ); |
|
627 | + return implode($separator, $formattedDataValues); |
|
628 | 628 | } |
629 | 629 | |
630 | 630 | /** |
@@ -636,11 +636,11 @@ discard block |
||
636 | 636 | * |
637 | 637 | * @return string HTML |
638 | 638 | */ |
639 | - private function getClaimLink( EntityId $entityId, PropertyId $propertyId, $text ) { |
|
639 | + private function getClaimLink(EntityId $entityId, PropertyId $propertyId, $text) { |
|
640 | 640 | return Html::rawElement( |
641 | 641 | 'a', |
642 | 642 | [ |
643 | - 'href' => $this->getClaimUrl( $entityId, $propertyId ), |
|
643 | + 'href' => $this->getClaimUrl($entityId, $propertyId), |
|
644 | 644 | 'target' => '_blank' |
645 | 645 | ], |
646 | 646 | $text |
@@ -655,9 +655,9 @@ discard block |
||
655 | 655 | * |
656 | 656 | * @return string |
657 | 657 | */ |
658 | - private function getClaimUrl( EntityId $entityId, PropertyId $propertyId ) { |
|
659 | - $title = $this->entityTitleLookup->getTitleForId( $entityId ); |
|
660 | - $entityUrl = sprintf( '%s#%s', $title->getLocalURL(), $propertyId->getSerialization() ); |
|
658 | + private function getClaimUrl(EntityId $entityId, PropertyId $propertyId) { |
|
659 | + $title = $this->entityTitleLookup->getTitleForId($entityId); |
|
660 | + $entityUrl = sprintf('%s#%s', $title->getLocalURL(), $propertyId->getSerialization()); |
|
661 | 661 | |
662 | 662 | return $entityUrl; |
663 | 663 | } |
@@ -199,73 +199,73 @@ discard block |
||
199 | 199 | $this->defaultUserAgent = $defaultUserAgent; |
200 | 200 | $this->requestFactory = $requestFactory; |
201 | 201 | $this->entityPrefixes = []; |
202 | - foreach ( $rdfVocabulary->entityNamespaceNames as $namespaceName ) { |
|
203 | - $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI( $namespaceName ); |
|
202 | + foreach ($rdfVocabulary->entityNamespaceNames as $namespaceName) { |
|
203 | + $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI($namespaceName); |
|
204 | 204 | } |
205 | 205 | |
206 | - $this->endpoint = $config->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
207 | - $this->maxQueryTimeMillis = $config->get( 'WBQualityConstraintsSparqlMaxMillis' ); |
|
208 | - $this->instanceOfId = $config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
209 | - $this->subclassOfId = $config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
210 | - $this->cacheMapSize = $config->get( 'WBQualityConstraintsFormatCacheMapSize' ); |
|
206 | + $this->endpoint = $config->get('WBQualityConstraintsSparqlEndpoint'); |
|
207 | + $this->maxQueryTimeMillis = $config->get('WBQualityConstraintsSparqlMaxMillis'); |
|
208 | + $this->instanceOfId = $config->get('WBQualityConstraintsInstanceOfId'); |
|
209 | + $this->subclassOfId = $config->get('WBQualityConstraintsSubclassOfId'); |
|
210 | + $this->cacheMapSize = $config->get('WBQualityConstraintsFormatCacheMapSize'); |
|
211 | 211 | $this->timeoutExceptionClasses = $config->get( |
212 | 212 | 'WBQualityConstraintsSparqlTimeoutExceptionClasses' |
213 | 213 | ); |
214 | 214 | $this->sparqlHasWikibaseSupport = $config->get( |
215 | 215 | 'WBQualityConstraintsSparqlHasWikibaseSupport' |
216 | 216 | ); |
217 | - $this->sparqlThrottlingFallbackDuration = (int)$config->get( |
|
217 | + $this->sparqlThrottlingFallbackDuration = (int) $config->get( |
|
218 | 218 | 'WBQualityConstraintsSparqlThrottlingFallbackDuration' |
219 | 219 | ); |
220 | 220 | |
221 | - $this->prefixes = $this->getQueryPrefixes( $rdfVocabulary ); |
|
221 | + $this->prefixes = $this->getQueryPrefixes($rdfVocabulary); |
|
222 | 222 | } |
223 | 223 | |
224 | - private function getQueryPrefixes( RdfVocabulary $rdfVocabulary ) { |
|
224 | + private function getQueryPrefixes(RdfVocabulary $rdfVocabulary) { |
|
225 | 225 | // TODO: it would probably be smarter that RdfVocubulary exposed these prefixes somehow |
226 | 226 | $prefixes = ''; |
227 | - foreach ( $rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName ) { |
|
227 | + foreach ($rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName) { |
|
228 | 228 | $prefixes .= <<<END |
229 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
229 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
230 | 230 | END; |
231 | 231 | } |
232 | 232 | $prefixes .= <<<END |
233 | -PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}> |
|
234 | -PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}>\n |
|
233 | +PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}> |
|
234 | +PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}>\n |
|
235 | 235 | END; |
236 | 236 | |
237 | - foreach ( $rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces ) { |
|
237 | + foreach ($rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces) { |
|
238 | 238 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_DIRECT_CLAIM]; |
239 | 239 | $prefixes .= <<<END |
240 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
240 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
241 | 241 | END; |
242 | 242 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM]; |
243 | 243 | $prefixes .= <<<END |
244 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
244 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
245 | 245 | END; |
246 | 246 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM_STATEMENT]; |
247 | 247 | $prefixes .= <<<END |
248 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
248 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
249 | 249 | END; |
250 | 250 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER]; |
251 | 251 | $prefixes .= <<<END |
252 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
252 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
253 | 253 | END; |
254 | 254 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER_VALUE]; |
255 | 255 | $prefixes .= <<<END |
256 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
256 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
257 | 257 | END; |
258 | 258 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE]; |
259 | 259 | $prefixes .= <<<END |
260 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
260 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
261 | 261 | END; |
262 | 262 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE_VALUE]; |
263 | 263 | $prefixes .= <<<END |
264 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
264 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
265 | 265 | END; |
266 | 266 | } |
267 | 267 | $prefixes .= <<<END |
268 | -PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ONTOLOGY )}>\n |
|
268 | +PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ONTOLOGY)}>\n |
|
269 | 269 | END; |
270 | 270 | return $prefixes; |
271 | 271 | } |
@@ -277,21 +277,20 @@ discard block |
||
277 | 277 | * @return CachedBool |
278 | 278 | * @throws SparqlHelperException if the query times out or some other error occurs |
279 | 279 | */ |
280 | - public function hasType( $id, array $classes ) { |
|
280 | + public function hasType($id, array $classes) { |
|
281 | 281 | // TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually |
282 | 282 | $gearingHint = $this->sparqlHasWikibaseSupport ? |
283 | - ' hint:Prior hint:gearing "forward".' : |
|
284 | - ''; |
|
283 | + ' hint:Prior hint:gearing "forward".' : ''; |
|
285 | 284 | |
286 | 285 | $metadatas = []; |
287 | 286 | |
288 | - foreach ( array_chunk( $classes, 20 ) as $classesChunk ) { |
|
289 | - $classesValues = implode( ' ', array_map( |
|
290 | - static function ( $class ) { |
|
291 | - return 'wd:' . $class; |
|
287 | + foreach (array_chunk($classes, 20) as $classesChunk) { |
|
288 | + $classesValues = implode(' ', array_map( |
|
289 | + static function($class) { |
|
290 | + return 'wd:'.$class; |
|
292 | 291 | }, |
293 | 292 | $classesChunk |
294 | - ) ); |
|
293 | + )); |
|
295 | 294 | |
296 | 295 | $query = <<<EOF |
297 | 296 | ASK { |
@@ -301,19 +300,19 @@ discard block |
||
301 | 300 | } |
302 | 301 | EOF; |
303 | 302 | |
304 | - $result = $this->runQuery( $query ); |
|
303 | + $result = $this->runQuery($query); |
|
305 | 304 | $metadatas[] = $result->getMetadata(); |
306 | - if ( $result->getArray()['boolean'] ) { |
|
305 | + if ($result->getArray()['boolean']) { |
|
307 | 306 | return new CachedBool( |
308 | 307 | true, |
309 | - Metadata::merge( $metadatas ) |
|
308 | + Metadata::merge($metadatas) |
|
310 | 309 | ); |
311 | 310 | } |
312 | 311 | } |
313 | 312 | |
314 | 313 | return new CachedBool( |
315 | 314 | false, |
316 | - Metadata::merge( $metadatas ) |
|
315 | + Metadata::merge($metadatas) |
|
317 | 316 | ); |
318 | 317 | } |
319 | 318 | |
@@ -329,10 +328,10 @@ discard block |
||
329 | 328 | $ignoreDeprecatedStatements |
330 | 329 | ) { |
331 | 330 | $pid = $statement->getPropertyId()->serialize(); |
332 | - $guid = str_replace( '$', '-', $statement->getGuid() ); |
|
331 | + $guid = str_replace('$', '-', $statement->getGuid()); |
|
333 | 332 | |
334 | 333 | $deprecatedFilter = ''; |
335 | - if ( $ignoreDeprecatedStatements ) { |
|
334 | + if ($ignoreDeprecatedStatements) { |
|
336 | 335 | $deprecatedFilter = 'MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }'; |
337 | 336 | } |
338 | 337 | |
@@ -351,9 +350,9 @@ discard block |
||
351 | 350 | LIMIT 10 |
352 | 351 | EOF; |
353 | 352 | |
354 | - $result = $this->runQuery( $query ); |
|
353 | + $result = $this->runQuery($query); |
|
355 | 354 | |
356 | - return $this->getOtherEntities( $result ); |
|
355 | + return $this->getOtherEntities($result); |
|
357 | 356 | } |
358 | 357 | |
359 | 358 | /** |
@@ -378,16 +377,15 @@ discard block |
||
378 | 377 | $dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty( |
379 | 378 | $snak->getPropertyId() |
380 | 379 | ); |
381 | - list( $value, $isFullValue ) = $this->getRdfLiteral( $dataType, $dataValue ); |
|
382 | - if ( $isFullValue ) { |
|
380 | + list($value, $isFullValue) = $this->getRdfLiteral($dataType, $dataValue); |
|
381 | + if ($isFullValue) { |
|
383 | 382 | $prefix .= 'v'; |
384 | 383 | } |
385 | 384 | $path = $type === Context::TYPE_QUALIFIER ? |
386 | - "$prefix:$pid" : |
|
387 | - "prov:wasDerivedFrom/$prefix:$pid"; |
|
385 | + "$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid"; |
|
388 | 386 | |
389 | 387 | $deprecatedFilter = ''; |
390 | - if ( $ignoreDeprecatedStatements ) { |
|
388 | + if ($ignoreDeprecatedStatements) { |
|
391 | 389 | $deprecatedFilter = <<< EOF |
392 | 390 | MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. } |
393 | 391 | EOF; |
@@ -407,9 +405,9 @@ discard block |
||
407 | 405 | LIMIT 10 |
408 | 406 | EOF; |
409 | 407 | |
410 | - $result = $this->runQuery( $query ); |
|
408 | + $result = $this->runQuery($query); |
|
411 | 409 | |
412 | - return $this->getOtherEntities( $result ); |
|
410 | + return $this->getOtherEntities($result); |
|
413 | 411 | } |
414 | 412 | |
415 | 413 | /** |
@@ -419,8 +417,8 @@ discard block |
||
419 | 417 | * |
420 | 418 | * @return string |
421 | 419 | */ |
422 | - private function stringLiteral( $text ) { |
|
423 | - return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"'; |
|
420 | + private function stringLiteral($text) { |
|
421 | + return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"'; |
|
424 | 422 | } |
425 | 423 | |
426 | 424 | /** |
@@ -430,18 +428,18 @@ discard block |
||
430 | 428 | * |
431 | 429 | * @return CachedEntityIds |
432 | 430 | */ |
433 | - private function getOtherEntities( CachedQueryResults $results ) { |
|
434 | - return new CachedEntityIds( array_map( |
|
435 | - function ( $resultBindings ) { |
|
431 | + private function getOtherEntities(CachedQueryResults $results) { |
|
432 | + return new CachedEntityIds(array_map( |
|
433 | + function($resultBindings) { |
|
436 | 434 | $entityIRI = $resultBindings['otherEntity']['value']; |
437 | - foreach ( $this->entityPrefixes as $entityPrefix ) { |
|
438 | - $entityPrefixLength = strlen( $entityPrefix ); |
|
439 | - if ( substr( $entityIRI, 0, $entityPrefixLength ) === $entityPrefix ) { |
|
435 | + foreach ($this->entityPrefixes as $entityPrefix) { |
|
436 | + $entityPrefixLength = strlen($entityPrefix); |
|
437 | + if (substr($entityIRI, 0, $entityPrefixLength) === $entityPrefix) { |
|
440 | 438 | try { |
441 | 439 | return $this->entityIdParser->parse( |
442 | - substr( $entityIRI, $entityPrefixLength ) |
|
440 | + substr($entityIRI, $entityPrefixLength) |
|
443 | 441 | ); |
444 | - } catch ( EntityIdParsingException $e ) { |
|
442 | + } catch (EntityIdParsingException $e) { |
|
445 | 443 | // fall through |
446 | 444 | } |
447 | 445 | } |
@@ -452,7 +450,7 @@ discard block |
||
452 | 450 | return null; |
453 | 451 | }, |
454 | 452 | $results->getArray()['results']['bindings'] |
455 | - ), $results->getMetadata() ); |
|
453 | + ), $results->getMetadata()); |
|
456 | 454 | } |
457 | 455 | |
458 | 456 | // phpcs:disable Generic.Metrics.CyclomaticComplexity,Squiz.WhiteSpace.FunctionSpacing |
@@ -465,50 +463,50 @@ discard block |
||
465 | 463 | * @return array the literal or IRI as a string in SPARQL syntax, |
466 | 464 | * and a boolean indicating whether it refers to a full value node or not |
467 | 465 | */ |
468 | - private function getRdfLiteral( $dataType, DataValue $dataValue ) { |
|
469 | - switch ( $dataType ) { |
|
466 | + private function getRdfLiteral($dataType, DataValue $dataValue) { |
|
467 | + switch ($dataType) { |
|
470 | 468 | case 'string': |
471 | 469 | case 'external-id': |
472 | - return [ $this->stringLiteral( $dataValue->getValue() ), false ]; |
|
470 | + return [$this->stringLiteral($dataValue->getValue()), false]; |
|
473 | 471 | case 'commonsMedia': |
474 | - $url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() ); |
|
475 | - return [ '<' . $url . '>', false ]; |
|
472 | + $url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue()); |
|
473 | + return ['<'.$url.'>', false]; |
|
476 | 474 | case 'geo-shape': |
477 | - $url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() ); |
|
478 | - return [ '<' . $url . '>', false ]; |
|
475 | + $url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue()); |
|
476 | + return ['<'.$url.'>', false]; |
|
479 | 477 | case 'tabular-data': |
480 | - $url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() ); |
|
481 | - return [ '<' . $url . '>', false ]; |
|
478 | + $url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue()); |
|
479 | + return ['<'.$url.'>', false]; |
|
482 | 480 | case 'url': |
483 | 481 | $url = $dataValue->getValue(); |
484 | - if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) { |
|
482 | + if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) { |
|
485 | 483 | // not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF) |
486 | 484 | // such an URL should never reach us, so just throw |
487 | - throw new InvalidArgumentException( 'invalid URL: ' . $url ); |
|
485 | + throw new InvalidArgumentException('invalid URL: '.$url); |
|
488 | 486 | } |
489 | - return [ '<' . $url . '>', false ]; |
|
487 | + return ['<'.$url.'>', false]; |
|
490 | 488 | case 'wikibase-item': |
491 | 489 | case 'wikibase-property': |
492 | 490 | /** @var EntityIdValue $dataValue */ |
493 | 491 | '@phan-var EntityIdValue $dataValue'; |
494 | - return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ]; |
|
492 | + return ['wd:'.$dataValue->getEntityId()->getSerialization(), false]; |
|
495 | 493 | case 'monolingualtext': |
496 | 494 | /** @var MonolingualTextValue $dataValue */ |
497 | 495 | '@phan-var MonolingualTextValue $dataValue'; |
498 | 496 | $lang = $dataValue->getLanguageCode(); |
499 | - if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) { |
|
497 | + if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) { |
|
500 | 498 | // not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG) |
501 | 499 | // such a language tag should never reach us, so just throw |
502 | - throw new InvalidArgumentException( 'invalid language tag: ' . $lang ); |
|
500 | + throw new InvalidArgumentException('invalid language tag: '.$lang); |
|
503 | 501 | } |
504 | - return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ]; |
|
502 | + return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false]; |
|
505 | 503 | case 'globe-coordinate': |
506 | 504 | case 'quantity': |
507 | 505 | case 'time': |
508 | 506 | // @phan-suppress-next-line PhanUndeclaredMethod |
509 | - return [ 'wdv:' . $dataValue->getHash(), true ]; |
|
507 | + return ['wdv:'.$dataValue->getHash(), true]; |
|
510 | 508 | default: |
511 | - throw new InvalidArgumentException( 'unknown data type: ' . $dataType ); |
|
509 | + throw new InvalidArgumentException('unknown data type: '.$dataType); |
|
512 | 510 | } |
513 | 511 | } |
514 | 512 | // phpcs:enable |
@@ -521,43 +519,43 @@ discard block |
||
521 | 519 | * @throws SparqlHelperException if the query times out or some other error occurs |
522 | 520 | * @throws ConstraintParameterException if the $regex is invalid |
523 | 521 | */ |
524 | - public function matchesRegularExpression( $text, $regex ) { |
|
522 | + public function matchesRegularExpression($text, $regex) { |
|
525 | 523 | // caching wrapper around matchesRegularExpressionWithSparql |
526 | 524 | |
527 | - $textHash = hash( 'sha256', $text ); |
|
525 | + $textHash = hash('sha256', $text); |
|
528 | 526 | $cacheKey = $this->cache->makeKey( |
529 | 527 | 'WikibaseQualityConstraints', // extension |
530 | 528 | 'regex', // action |
531 | 529 | 'WDQS-Java', // regex flavor |
532 | - hash( 'sha256', $regex ) |
|
530 | + hash('sha256', $regex) |
|
533 | 531 | ); |
534 | 532 | |
535 | 533 | $cacheMapArray = $this->cache->getWithSetCallback( |
536 | 534 | $cacheKey, |
537 | 535 | WANObjectCache::TTL_DAY, |
538 | - function ( $cacheMapArray ) use ( $text, $regex, $textHash ) { |
|
536 | + function($cacheMapArray) use ($text, $regex, $textHash) { |
|
539 | 537 | // Initialize the cache map if not set |
540 | - if ( $cacheMapArray === false ) { |
|
538 | + if ($cacheMapArray === false) { |
|
541 | 539 | $key = 'wikibase.quality.constraints.regex.cache.refresh.init'; |
542 | - $this->dataFactory->increment( $key ); |
|
540 | + $this->dataFactory->increment($key); |
|
543 | 541 | return []; |
544 | 542 | } |
545 | 543 | |
546 | 544 | $key = 'wikibase.quality.constraints.regex.cache.refresh'; |
547 | - $this->dataFactory->increment( $key ); |
|
548 | - $cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $this->cacheMapSize ); |
|
549 | - if ( $cacheMap->has( $textHash ) ) { |
|
545 | + $this->dataFactory->increment($key); |
|
546 | + $cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $this->cacheMapSize); |
|
547 | + if ($cacheMap->has($textHash)) { |
|
550 | 548 | $key = 'wikibase.quality.constraints.regex.cache.refresh.hit'; |
551 | - $this->dataFactory->increment( $key ); |
|
552 | - $cacheMap->get( $textHash ); // ping cache |
|
549 | + $this->dataFactory->increment($key); |
|
550 | + $cacheMap->get($textHash); // ping cache |
|
553 | 551 | } else { |
554 | 552 | $key = 'wikibase.quality.constraints.regex.cache.refresh.miss'; |
555 | - $this->dataFactory->increment( $key ); |
|
553 | + $this->dataFactory->increment($key); |
|
556 | 554 | try { |
557 | - $matches = $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
558 | - } catch ( ConstraintParameterException $e ) { |
|
559 | - $matches = $this->serializeConstraintParameterException( $e ); |
|
560 | - } catch ( SparqlHelperException $e ) { |
|
555 | + $matches = $this->matchesRegularExpressionWithSparql($text, $regex); |
|
556 | + } catch (ConstraintParameterException $e) { |
|
557 | + $matches = $this->serializeConstraintParameterException($e); |
|
558 | + } catch (SparqlHelperException $e) { |
|
561 | 559 | // don’t cache this |
562 | 560 | return $cacheMap->toArray(); |
563 | 561 | } |
@@ -581,42 +579,42 @@ discard block |
||
581 | 579 | ] |
582 | 580 | ); |
583 | 581 | |
584 | - if ( isset( $cacheMapArray[$textHash] ) ) { |
|
582 | + if (isset($cacheMapArray[$textHash])) { |
|
585 | 583 | $key = 'wikibase.quality.constraints.regex.cache.hit'; |
586 | - $this->dataFactory->increment( $key ); |
|
584 | + $this->dataFactory->increment($key); |
|
587 | 585 | $matches = $cacheMapArray[$textHash]; |
588 | - if ( is_bool( $matches ) ) { |
|
586 | + if (is_bool($matches)) { |
|
589 | 587 | return $matches; |
590 | - } elseif ( is_array( $matches ) && |
|
591 | - $matches['type'] == ConstraintParameterException::class ) { |
|
592 | - throw $this->deserializeConstraintParameterException( $matches ); |
|
588 | + } elseif (is_array($matches) && |
|
589 | + $matches['type'] == ConstraintParameterException::class) { |
|
590 | + throw $this->deserializeConstraintParameterException($matches); |
|
593 | 591 | } else { |
594 | 592 | throw new MWException( |
595 | - 'Value of unknown type in object cache (' . |
|
596 | - 'cache key: ' . $cacheKey . ', ' . |
|
597 | - 'cache map key: ' . $textHash . ', ' . |
|
598 | - 'value type: ' . gettype( $matches ) . ')' |
|
593 | + 'Value of unknown type in object cache ('. |
|
594 | + 'cache key: '.$cacheKey.', '. |
|
595 | + 'cache map key: '.$textHash.', '. |
|
596 | + 'value type: '.gettype($matches).')' |
|
599 | 597 | ); |
600 | 598 | } |
601 | 599 | } else { |
602 | 600 | $key = 'wikibase.quality.constraints.regex.cache.miss'; |
603 | - $this->dataFactory->increment( $key ); |
|
604 | - return $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
601 | + $this->dataFactory->increment($key); |
|
602 | + return $this->matchesRegularExpressionWithSparql($text, $regex); |
|
605 | 603 | } |
606 | 604 | } |
607 | 605 | |
608 | - private function serializeConstraintParameterException( ConstraintParameterException $cpe ) { |
|
606 | + private function serializeConstraintParameterException(ConstraintParameterException $cpe) { |
|
609 | 607 | return [ |
610 | 608 | 'type' => ConstraintParameterException::class, |
611 | - 'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ), |
|
609 | + 'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()), |
|
612 | 610 | ]; |
613 | 611 | } |
614 | 612 | |
615 | - private function deserializeConstraintParameterException( array $serialization ) { |
|
613 | + private function deserializeConstraintParameterException(array $serialization) { |
|
616 | 614 | $message = $this->violationMessageDeserializer->deserialize( |
617 | 615 | $serialization['violationMessage'] |
618 | 616 | ); |
619 | - return new ConstraintParameterException( $message ); |
|
617 | + return new ConstraintParameterException($message); |
|
620 | 618 | } |
621 | 619 | |
622 | 620 | /** |
@@ -630,25 +628,25 @@ discard block |
||
630 | 628 | * @throws SparqlHelperException if the query times out or some other error occurs |
631 | 629 | * @throws ConstraintParameterException if the $regex is invalid |
632 | 630 | */ |
633 | - public function matchesRegularExpressionWithSparql( $text, $regex ) { |
|
634 | - $textStringLiteral = $this->stringLiteral( $text ); |
|
635 | - $regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' ); |
|
631 | + public function matchesRegularExpressionWithSparql($text, $regex) { |
|
632 | + $textStringLiteral = $this->stringLiteral($text); |
|
633 | + $regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$'); |
|
636 | 634 | |
637 | 635 | $query = <<<EOF |
638 | 636 | SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {} |
639 | 637 | EOF; |
640 | 638 | |
641 | - $result = $this->runQuery( $query, false ); |
|
639 | + $result = $this->runQuery($query, false); |
|
642 | 640 | |
643 | 641 | $vars = $result->getArray()['results']['bindings'][0]; |
644 | - if ( array_key_exists( 'matches', $vars ) ) { |
|
642 | + if (array_key_exists('matches', $vars)) { |
|
645 | 643 | // true or false ⇒ regex okay, text matches or not |
646 | 644 | return $vars['matches']['value'] === 'true'; |
647 | 645 | } else { |
648 | 646 | // empty result: regex broken |
649 | 647 | throw new ConstraintParameterException( |
650 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
651 | - ->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
648 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
649 | + ->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE) |
|
652 | 650 | ); |
653 | 651 | } |
654 | 652 | } |
@@ -660,14 +658,14 @@ discard block |
||
660 | 658 | * |
661 | 659 | * @return boolean |
662 | 660 | */ |
663 | - public function isTimeout( $responseContent ) { |
|
664 | - $timeoutRegex = implode( '|', array_map( |
|
665 | - static function ( $fqn ) { |
|
666 | - return preg_quote( $fqn, '/' ); |
|
661 | + public function isTimeout($responseContent) { |
|
662 | + $timeoutRegex = implode('|', array_map( |
|
663 | + static function($fqn) { |
|
664 | + return preg_quote($fqn, '/'); |
|
667 | 665 | }, |
668 | 666 | $this->timeoutExceptionClasses |
669 | - ) ); |
|
670 | - return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent ); |
|
667 | + )); |
|
668 | + return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent); |
|
671 | 669 | } |
672 | 670 | |
673 | 671 | /** |
@@ -679,17 +677,17 @@ discard block |
||
679 | 677 | * @return int|boolean the max-age (in seconds) |
680 | 678 | * or a plain boolean if no max-age can be determined |
681 | 679 | */ |
682 | - public function getCacheMaxAge( $responseHeaders ) { |
|
680 | + public function getCacheMaxAge($responseHeaders) { |
|
683 | 681 | if ( |
684 | - array_key_exists( 'x-cache-status', $responseHeaders ) && |
|
685 | - preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] ) |
|
682 | + array_key_exists('x-cache-status', $responseHeaders) && |
|
683 | + preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0]) |
|
686 | 684 | ) { |
687 | 685 | $maxage = []; |
688 | 686 | if ( |
689 | - array_key_exists( 'cache-control', $responseHeaders ) && |
|
690 | - preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage ) |
|
687 | + array_key_exists('cache-control', $responseHeaders) && |
|
688 | + preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage) |
|
691 | 689 | ) { |
692 | - return intval( $maxage[1] ); |
|
690 | + return intval($maxage[1]); |
|
693 | 691 | } else { |
694 | 692 | return true; |
695 | 693 | } |
@@ -710,34 +708,34 @@ discard block |
||
710 | 708 | * or SparlHelper::EMPTY_RETRY_AFTER if there is an empty Retry-After |
711 | 709 | * or SparlHelper::INVALID_RETRY_AFTER if there is something wrong with the format |
712 | 710 | */ |
713 | - public function getThrottling( MWHttpRequest $request ) { |
|
714 | - $retryAfterValue = $request->getResponseHeader( 'Retry-After' ); |
|
715 | - if ( $retryAfterValue === null ) { |
|
711 | + public function getThrottling(MWHttpRequest $request) { |
|
712 | + $retryAfterValue = $request->getResponseHeader('Retry-After'); |
|
713 | + if ($retryAfterValue === null) { |
|
716 | 714 | return self::NO_RETRY_AFTER; |
717 | 715 | } |
718 | 716 | |
719 | - $trimmedRetryAfterValue = trim( $retryAfterValue ); |
|
720 | - if ( empty( $trimmedRetryAfterValue ) ) { |
|
717 | + $trimmedRetryAfterValue = trim($retryAfterValue); |
|
718 | + if (empty($trimmedRetryAfterValue)) { |
|
721 | 719 | return self::EMPTY_RETRY_AFTER; |
722 | 720 | } |
723 | 721 | |
724 | - if ( is_numeric( $trimmedRetryAfterValue ) ) { |
|
725 | - $delaySeconds = (int)$trimmedRetryAfterValue; |
|
726 | - if ( $delaySeconds >= 0 ) { |
|
727 | - return $this->getTimestampInFuture( new DateInterval( 'PT' . $delaySeconds . 'S' ) ); |
|
722 | + if (is_numeric($trimmedRetryAfterValue)) { |
|
723 | + $delaySeconds = (int) $trimmedRetryAfterValue; |
|
724 | + if ($delaySeconds >= 0) { |
|
725 | + return $this->getTimestampInFuture(new DateInterval('PT'.$delaySeconds.'S')); |
|
728 | 726 | } |
729 | 727 | } else { |
730 | - $return = strtotime( $trimmedRetryAfterValue ); |
|
731 | - if ( !empty( $return ) ) { |
|
732 | - return new ConvertibleTimestamp( $return ); |
|
728 | + $return = strtotime($trimmedRetryAfterValue); |
|
729 | + if (!empty($return)) { |
|
730 | + return new ConvertibleTimestamp($return); |
|
733 | 731 | } |
734 | 732 | } |
735 | 733 | return self::INVALID_RETRY_AFTER; |
736 | 734 | } |
737 | 735 | |
738 | - private function getTimestampInFuture( DateInterval $delta ) { |
|
736 | + private function getTimestampInFuture(DateInterval $delta) { |
|
739 | 737 | $now = new ConvertibleTimestamp(); |
740 | - return new ConvertibleTimestamp( $now->timestamp->add( $delta ) ); |
|
738 | + return new ConvertibleTimestamp($now->timestamp->add($delta)); |
|
741 | 739 | } |
742 | 740 | |
743 | 741 | /** |
@@ -751,65 +749,64 @@ discard block |
||
751 | 749 | * |
752 | 750 | * @throws SparqlHelperException if the query times out or some other error occurs |
753 | 751 | */ |
754 | - public function runQuery( $query, $needsPrefixes = true ) { |
|
752 | + public function runQuery($query, $needsPrefixes = true) { |
|
755 | 753 | |
756 | - if ( $this->throttlingLock->isLocked( self::EXPIRY_LOCK_ID ) ) { |
|
757 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
754 | + if ($this->throttlingLock->isLocked(self::EXPIRY_LOCK_ID)) { |
|
755 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
758 | 756 | throw new TooManySparqlRequestsException(); |
759 | 757 | } |
760 | 758 | |
761 | - if ( $this->sparqlHasWikibaseSupport ) { |
|
759 | + if ($this->sparqlHasWikibaseSupport) { |
|
762 | 760 | $needsPrefixes = false; |
763 | 761 | } |
764 | 762 | |
765 | - if ( $needsPrefixes ) { |
|
766 | - $query = $this->prefixes . $query; |
|
763 | + if ($needsPrefixes) { |
|
764 | + $query = $this->prefixes.$query; |
|
767 | 765 | } |
768 | - $query = "#wbqc\n" . $query; |
|
766 | + $query = "#wbqc\n".$query; |
|
769 | 767 | |
770 | - $url = $this->endpoint . '?' . http_build_query( |
|
768 | + $url = $this->endpoint.'?'.http_build_query( |
|
771 | 769 | [ |
772 | 770 | 'query' => $query, |
773 | 771 | 'format' => 'json', |
774 | 772 | 'maxQueryTimeMillis' => $this->maxQueryTimeMillis, |
775 | 773 | ], |
776 | - null, ini_get( 'arg_separator.output' ), |
|
774 | + null, ini_get('arg_separator.output'), |
|
777 | 775 | // encode spaces with %20, not + |
778 | 776 | PHP_QUERY_RFC3986 |
779 | 777 | ); |
780 | 778 | |
781 | 779 | $options = [ |
782 | 780 | 'method' => 'GET', |
783 | - 'timeout' => (int)round( ( $this->maxQueryTimeMillis + 1000 ) / 1000 ), |
|
781 | + 'timeout' => (int) round(($this->maxQueryTimeMillis + 1000) / 1000), |
|
784 | 782 | 'connectTimeout' => 'default', |
785 | 783 | 'userAgent' => $this->defaultUserAgent, |
786 | 784 | ]; |
787 | - $request = $this->requestFactory->create( $url, $options, __METHOD__ ); |
|
788 | - $startTime = microtime( true ); |
|
785 | + $request = $this->requestFactory->create($url, $options, __METHOD__); |
|
786 | + $startTime = microtime(true); |
|
789 | 787 | $requestStatus = $request->execute(); |
790 | - $endTime = microtime( true ); |
|
788 | + $endTime = microtime(true); |
|
791 | 789 | $this->dataFactory->timing( |
792 | 790 | 'wikibase.quality.constraints.sparql.timing', |
793 | - ( $endTime - $startTime ) * 1000 |
|
791 | + ($endTime - $startTime) * 1000 |
|
794 | 792 | ); |
795 | 793 | |
796 | - $this->guardAgainstTooManyRequestsError( $request ); |
|
794 | + $this->guardAgainstTooManyRequestsError($request); |
|
797 | 795 | |
798 | - $maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() ); |
|
799 | - if ( $maxAge ) { |
|
800 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' ); |
|
796 | + $maxAge = $this->getCacheMaxAge($request->getResponseHeaders()); |
|
797 | + if ($maxAge) { |
|
798 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.cached'); |
|
801 | 799 | } |
802 | 800 | |
803 | - if ( $requestStatus->isOK() ) { |
|
801 | + if ($requestStatus->isOK()) { |
|
804 | 802 | $json = $request->getContent(); |
805 | - $jsonStatus = FormatJson::parse( $json, FormatJson::FORCE_ASSOC ); |
|
806 | - if ( $jsonStatus->isOK() ) { |
|
803 | + $jsonStatus = FormatJson::parse($json, FormatJson::FORCE_ASSOC); |
|
804 | + if ($jsonStatus->isOK()) { |
|
807 | 805 | return new CachedQueryResults( |
808 | 806 | $jsonStatus->getValue(), |
809 | 807 | Metadata::ofCachingMetadata( |
810 | 808 | $maxAge ? |
811 | - CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) : |
|
812 | - CachingMetadata::fresh() |
|
809 | + CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh() |
|
813 | 810 | ) |
814 | 811 | ); |
815 | 812 | } else { |
@@ -826,9 +823,9 @@ discard block |
||
826 | 823 | // fall through to general error handling |
827 | 824 | } |
828 | 825 | |
829 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' ); |
|
826 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.error'); |
|
830 | 827 | |
831 | - if ( $this->isTimeout( $request->getContent() ) ) { |
|
828 | + if ($this->isTimeout($request->getContent())) { |
|
832 | 829 | $this->dataFactory->increment( |
833 | 830 | 'wikibase.quality.constraints.sparql.error.timeout' |
834 | 831 | ); |
@@ -843,29 +840,29 @@ discard block |
||
843 | 840 | * @param MWHttpRequest $request |
844 | 841 | * @throws TooManySparqlRequestsException |
845 | 842 | */ |
846 | - private function guardAgainstTooManyRequestsError( MWHttpRequest $request ): void { |
|
847 | - if ( $request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS ) { |
|
843 | + private function guardAgainstTooManyRequestsError(MWHttpRequest $request): void { |
|
844 | + if ($request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS) { |
|
848 | 845 | return; |
849 | 846 | } |
850 | 847 | |
851 | 848 | $fallbackBlockDuration = $this->sparqlThrottlingFallbackDuration; |
852 | 849 | |
853 | - if ( $fallbackBlockDuration < 0 ) { |
|
854 | - throw new InvalidArgumentException( 'Fallback duration must be positive int but is: ' . |
|
855 | - $fallbackBlockDuration ); |
|
850 | + if ($fallbackBlockDuration < 0) { |
|
851 | + throw new InvalidArgumentException('Fallback duration must be positive int but is: '. |
|
852 | + $fallbackBlockDuration); |
|
856 | 853 | } |
857 | 854 | |
858 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
859 | - $throttlingUntil = $this->getThrottling( $request ); |
|
860 | - if ( !( $throttlingUntil instanceof ConvertibleTimestamp ) ) { |
|
861 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid( $request ); |
|
855 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
856 | + $throttlingUntil = $this->getThrottling($request); |
|
857 | + if (!($throttlingUntil instanceof ConvertibleTimestamp)) { |
|
858 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid($request); |
|
862 | 859 | $this->throttlingLock->lock( |
863 | 860 | self::EXPIRY_LOCK_ID, |
864 | - $this->getTimestampInFuture( new DateInterval( 'PT' . $fallbackBlockDuration . 'S' ) ) |
|
861 | + $this->getTimestampInFuture(new DateInterval('PT'.$fallbackBlockDuration.'S')) |
|
865 | 862 | ); |
866 | 863 | } else { |
867 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent( $throttlingUntil, $request ); |
|
868 | - $this->throttlingLock->lock( self::EXPIRY_LOCK_ID, $throttlingUntil ); |
|
864 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent($throttlingUntil, $request); |
|
865 | + $this->throttlingLock->lock(self::EXPIRY_LOCK_ID, $throttlingUntil); |
|
869 | 866 | } |
870 | 867 | throw new TooManySparqlRequestsException(); |
871 | 868 | } |
@@ -20,13 +20,13 @@ |
||
20 | 20 | * @param PropertyId $propertyId |
21 | 21 | * @return int |
22 | 22 | */ |
23 | - public function getPropertyCount( array $snaks, PropertyId $propertyId ) { |
|
24 | - return count( array_filter( |
|
23 | + public function getPropertyCount(array $snaks, PropertyId $propertyId) { |
|
24 | + return count(array_filter( |
|
25 | 25 | $snaks, |
26 | - static function ( Snak $snak ) use ( $propertyId ) { |
|
27 | - return $snak->getPropertyId()->equals( $propertyId ); |
|
26 | + static function(Snak $snak) use ($propertyId) { |
|
27 | + return $snak->getPropertyId()->equals($propertyId); |
|
28 | 28 | } |
29 | - ) ); |
|
29 | + )); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | } |
@@ -80,24 +80,24 @@ discard block |
||
80 | 80 | * @return bool |
81 | 81 | * @throws OverflowException if $entitiesChecked exceeds the configured limit |
82 | 82 | */ |
83 | - private function isSubclassOf( EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0 ) { |
|
84 | - $maxEntities = $this->config->get( 'WBQualityConstraintsTypeCheckMaxEntities' ); |
|
83 | + private function isSubclassOf(EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0) { |
|
84 | + $maxEntities = $this->config->get('WBQualityConstraintsTypeCheckMaxEntities'); |
|
85 | 85 | if ( ++$entitiesChecked > $maxEntities ) { |
86 | - throw new OverflowException( 'Too many entities to check' ); |
|
86 | + throw new OverflowException('Too many entities to check'); |
|
87 | 87 | } |
88 | 88 | |
89 | - $item = $this->entityLookup->getEntity( $comparativeClass ); |
|
90 | - if ( !( $item instanceof StatementListProvider ) ) { |
|
89 | + $item = $this->entityLookup->getEntity($comparativeClass); |
|
90 | + if (!($item instanceof StatementListProvider)) { |
|
91 | 91 | return false; // lookup failed, probably because item doesn't exist |
92 | 92 | } |
93 | 93 | |
94 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
94 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
95 | 95 | /** @var Statement $statement */ |
96 | - foreach ( $item->getStatements()->getByPropertyId( new PropertyId( $subclassId ) ) as $statement ) { |
|
96 | + foreach ($item->getStatements()->getByPropertyId(new PropertyId($subclassId)) as $statement) { |
|
97 | 97 | $mainSnak = $statement->getMainSnak(); |
98 | 98 | |
99 | - if ( !$this->hasCorrectType( $mainSnak ) || |
|
100 | - $statement->getRank() === Statement::RANK_DEPRECATED ) { |
|
99 | + if (!$this->hasCorrectType($mainSnak) || |
|
100 | + $statement->getRank() === Statement::RANK_DEPRECATED) { |
|
101 | 101 | continue; |
102 | 102 | } |
103 | 103 | /** @var PropertyValueSnak $mainSnak */ |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | '@phan-var EntityIdValue $dataValue'; |
108 | 108 | $comparativeClass = $dataValue->getEntityId(); |
109 | 109 | |
110 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
110 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
111 | 111 | return true; |
112 | 112 | } |
113 | 113 | |
114 | - if ( $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ) ) { |
|
114 | + if ($this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked)) { |
|
115 | 115 | return true; |
116 | 116 | } |
117 | 117 | } |
@@ -132,48 +132,48 @@ discard block |
||
132 | 132 | * @return CachedBool |
133 | 133 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
134 | 134 | */ |
135 | - public function isSubclassOfWithSparqlFallback( EntityId $comparativeClass, array $classesToCheck ) { |
|
135 | + public function isSubclassOfWithSparqlFallback(EntityId $comparativeClass, array $classesToCheck) { |
|
136 | 136 | try { |
137 | 137 | $entitiesChecked = 0; |
138 | - $start1 = microtime( true ); |
|
139 | - $isSubclass = $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ); |
|
140 | - $end1 = microtime( true ); |
|
138 | + $start1 = microtime(true); |
|
139 | + $isSubclass = $this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked); |
|
140 | + $end1 = microtime(true); |
|
141 | 141 | $this->dataFactory->timing( |
142 | 142 | 'wikibase.quality.constraints.type.php.success.timing', |
143 | - ( $end1 - $start1 ) * 1000 |
|
143 | + ($end1 - $start1) * 1000 |
|
144 | 144 | ); |
145 | 145 | $this->dataFactory->timing( // not really a timing, but works like one (we want percentiles etc.) |
146 | 146 | 'wikibase.quality.constraints.type.php.success.entities', |
147 | 147 | $entitiesChecked |
148 | 148 | ); |
149 | 149 | |
150 | - return new CachedBool( $isSubclass, Metadata::blank() ); |
|
151 | - } catch ( OverflowException $e ) { |
|
152 | - $end1 = microtime( true ); |
|
150 | + return new CachedBool($isSubclass, Metadata::blank()); |
|
151 | + } catch (OverflowException $e) { |
|
152 | + $end1 = microtime(true); |
|
153 | 153 | $this->dataFactory->timing( |
154 | 154 | 'wikibase.quality.constraints.type.php.overflow.timing', |
155 | - ( $end1 - $start1 ) * 1000 |
|
155 | + ($end1 - $start1) * 1000 |
|
156 | 156 | ); |
157 | 157 | |
158 | - if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) { |
|
158 | + if (!($this->sparqlHelper instanceof DummySparqlHelper)) { |
|
159 | 159 | $this->dataFactory->increment( |
160 | 160 | 'wikibase.quality.constraints.sparql.typeFallback' |
161 | 161 | ); |
162 | 162 | |
163 | - $start2 = microtime( true ); |
|
163 | + $start2 = microtime(true); |
|
164 | 164 | $hasType = $this->sparqlHelper->hasType( |
165 | 165 | $comparativeClass->getSerialization(), |
166 | 166 | $classesToCheck |
167 | 167 | ); |
168 | - $end2 = microtime( true ); |
|
168 | + $end2 = microtime(true); |
|
169 | 169 | $this->dataFactory->timing( |
170 | 170 | 'wikibase.quality.constraints.type.sparql.success.timing', |
171 | - ( $end2 - $start2 ) * 1000 |
|
171 | + ($end2 - $start2) * 1000 |
|
172 | 172 | ); |
173 | 173 | |
174 | 174 | return $hasType; |
175 | 175 | } else { |
176 | - return new CachedBool( false, Metadata::blank() ); |
|
176 | + return new CachedBool(false, Metadata::blank()); |
|
177 | 177 | } |
178 | 178 | } |
179 | 179 | } |
@@ -191,14 +191,14 @@ discard block |
||
191 | 191 | * @return CachedBool |
192 | 192 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
193 | 193 | */ |
194 | - public function hasClassInRelation( StatementList $statements, array $relationIds, array $classesToCheck ) { |
|
194 | + public function hasClassInRelation(StatementList $statements, array $relationIds, array $classesToCheck) { |
|
195 | 195 | $metadatas = []; |
196 | 196 | |
197 | - foreach ( $this->getStatementsByPropertyIds( $statements, $relationIds ) as $statement ) { |
|
197 | + foreach ($this->getStatementsByPropertyIds($statements, $relationIds) as $statement) { |
|
198 | 198 | $mainSnak = $statement->getMainSnak(); |
199 | 199 | |
200 | - if ( !$this->hasCorrectType( $mainSnak ) || |
|
201 | - $statement->getRank() === Statement::RANK_DEPRECATED ) { |
|
200 | + if (!$this->hasCorrectType($mainSnak) || |
|
201 | + $statement->getRank() === Statement::RANK_DEPRECATED) { |
|
202 | 202 | continue; |
203 | 203 | } |
204 | 204 | /** @var PropertyValueSnak $mainSnak */ |
@@ -208,24 +208,24 @@ discard block |
||
208 | 208 | '@phan-var EntityIdValue $dataValue'; |
209 | 209 | $comparativeClass = $dataValue->getEntityId(); |
210 | 210 | |
211 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
211 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
212 | 212 | // discard $metadatas, we know this is fresh |
213 | - return new CachedBool( true, Metadata::blank() ); |
|
213 | + return new CachedBool(true, Metadata::blank()); |
|
214 | 214 | } |
215 | 215 | |
216 | - $result = $this->isSubclassOfWithSparqlFallback( $comparativeClass, $classesToCheck ); |
|
216 | + $result = $this->isSubclassOfWithSparqlFallback($comparativeClass, $classesToCheck); |
|
217 | 217 | $metadatas[] = $result->getMetadata(); |
218 | - if ( $result->getBool() ) { |
|
218 | + if ($result->getBool()) { |
|
219 | 219 | return new CachedBool( |
220 | 220 | true, |
221 | - Metadata::merge( $metadatas ) |
|
221 | + Metadata::merge($metadatas) |
|
222 | 222 | ); |
223 | 223 | } |
224 | 224 | } |
225 | 225 | |
226 | 226 | return new CachedBool( |
227 | 227 | false, |
228 | - Metadata::merge( $metadatas ) |
|
228 | + Metadata::merge($metadatas) |
|
229 | 229 | ); |
230 | 230 | } |
231 | 231 | |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | * @return bool |
235 | 235 | * @phan-assert PropertyValueSnak $mainSnak |
236 | 236 | */ |
237 | - private function hasCorrectType( Snak $mainSnak ) { |
|
237 | + private function hasCorrectType(Snak $mainSnak) { |
|
238 | 238 | return $mainSnak instanceof PropertyValueSnak |
239 | 239 | && $mainSnak->getDataValue()->getType() === 'wikibase-entityid'; |
240 | 240 | } |
@@ -251,12 +251,12 @@ discard block |
||
251 | 251 | ) { |
252 | 252 | $statementArrays = []; |
253 | 253 | |
254 | - foreach ( $propertyIdSerializations as $propertyIdSerialization ) { |
|
255 | - $propertyId = new PropertyId( $propertyIdSerialization ); |
|
256 | - $statementArrays[] = $statements->getByPropertyId( $propertyId )->toArray(); |
|
254 | + foreach ($propertyIdSerializations as $propertyIdSerialization) { |
|
255 | + $propertyId = new PropertyId($propertyIdSerialization); |
|
256 | + $statementArrays[] = $statements->getByPropertyId($propertyId)->toArray(); |
|
257 | 257 | } |
258 | 258 | |
259 | - return call_user_func_array( 'array_merge', $statementArrays ); |
|
259 | + return call_user_func_array('array_merge', $statementArrays); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -268,10 +268,10 @@ discard block |
||
268 | 268 | * |
269 | 269 | * @return ViolationMessage |
270 | 270 | */ |
271 | - public function getViolationMessage( PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation ) { |
|
271 | + public function getViolationMessage(PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation) { |
|
272 | 272 | $classes = array_map( |
273 | - static function ( $itemIdSerialization ) { |
|
274 | - return new ItemId( $itemIdSerialization ); |
|
273 | + static function($itemIdSerialization) { |
|
274 | + return new ItemId($itemIdSerialization); |
|
275 | 275 | }, |
276 | 276 | $classes |
277 | 277 | ); |
@@ -283,10 +283,10 @@ discard block |
||
283 | 283 | // wbqc-violation-message-valueType-instance |
284 | 284 | // wbqc-violation-message-valueType-subclass |
285 | 285 | // wbqc-violation-message-valueType-instanceOrSubclass |
286 | - return ( new ViolationMessage( 'wbqc-violation-message-' . $checker . '-' . $relation ) ) |
|
287 | - ->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ) |
|
288 | - ->withEntityId( $entityId, Role::SUBJECT ) |
|
289 | - ->withEntityIdList( $classes, Role::OBJECT ); |
|
286 | + return (new ViolationMessage('wbqc-violation-message-'.$checker.'-'.$relation)) |
|
287 | + ->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY) |
|
288 | + ->withEntityId($entityId, Role::SUBJECT) |
|
289 | + ->withEntityIdList($classes, Role::OBJECT); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | } |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | callable $defaultResultsPerEntity = null |
144 | 144 | ) { |
145 | 145 | $checkResults = []; |
146 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
146 | + $entity = $this->entityLookup->getEntity($entityId); |
|
147 | 147 | |
148 | - if ( $entity instanceof StatementListProvidingEntity ) { |
|
149 | - $startTime = microtime( true ); |
|
148 | + if ($entity instanceof StatementListProvidingEntity) { |
|
149 | + $startTime = microtime(true); |
|
150 | 150 | |
151 | 151 | $checkResults = $this->checkEveryStatement( |
152 | 152 | $entity, |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | $defaultResultsPerContext |
155 | 155 | ); |
156 | 156 | |
157 | - $endTime = microtime( true ); |
|
157 | + $endTime = microtime(true); |
|
158 | 158 | |
159 | - if ( $constraintIds === null ) { // only log full constraint checks |
|
159 | + if ($constraintIds === null) { // only log full constraint checks |
|
160 | 160 | $this->loggingHelper->logConstraintCheckOnEntity( |
161 | 161 | $entityId, |
162 | 162 | $checkResults, |
@@ -166,11 +166,11 @@ discard block |
||
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
169 | - if ( $defaultResultsPerEntity !== null ) { |
|
170 | - $checkResults = array_merge( $defaultResultsPerEntity( $entityId ), $checkResults ); |
|
169 | + if ($defaultResultsPerEntity !== null) { |
|
170 | + $checkResults = array_merge($defaultResultsPerEntity($entityId), $checkResults); |
|
171 | 171 | } |
172 | 172 | |
173 | - return $this->sortResult( $checkResults ); |
|
173 | + return $this->sortResult($checkResults); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -192,19 +192,19 @@ discard block |
||
192 | 192 | callable $defaultResults = null |
193 | 193 | ) { |
194 | 194 | |
195 | - $parsedGuid = $this->statementGuidParser->parse( $guid ); |
|
195 | + $parsedGuid = $this->statementGuidParser->parse($guid); |
|
196 | 196 | $entityId = $parsedGuid->getEntityId(); |
197 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
198 | - if ( $entity instanceof StatementListProvidingEntity ) { |
|
199 | - $statement = $entity->getStatements()->getFirstStatementWithGuid( $guid ); |
|
200 | - if ( $statement ) { |
|
197 | + $entity = $this->entityLookup->getEntity($entityId); |
|
198 | + if ($entity instanceof StatementListProvidingEntity) { |
|
199 | + $statement = $entity->getStatements()->getFirstStatementWithGuid($guid); |
|
200 | + if ($statement) { |
|
201 | 201 | $result = $this->checkStatement( |
202 | 202 | $entity, |
203 | 203 | $statement, |
204 | 204 | $constraintIds, |
205 | 205 | $defaultResults |
206 | 206 | ); |
207 | - $output = $this->sortResult( $result ); |
|
207 | + $output = $this->sortResult($result); |
|
208 | 208 | return $output; |
209 | 209 | } |
210 | 210 | } |
@@ -212,8 +212,8 @@ discard block |
||
212 | 212 | return []; |
213 | 213 | } |
214 | 214 | |
215 | - private function getAllowedContextTypes( Constraint $constraint ) { |
|
216 | - if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
215 | + private function getAllowedContextTypes(Constraint $constraint) { |
|
216 | + if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
217 | 217 | return [ |
218 | 218 | Context::TYPE_STATEMENT, |
219 | 219 | Context::TYPE_QUALIFIER, |
@@ -221,12 +221,12 @@ discard block |
||
221 | 221 | ]; |
222 | 222 | } |
223 | 223 | |
224 | - return array_keys( array_filter( |
|
224 | + return array_keys(array_filter( |
|
225 | 225 | $this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedContextTypes(), |
226 | - static function ( $resultStatus ) { |
|
226 | + static function($resultStatus) { |
|
227 | 227 | return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE; |
228 | 228 | } |
229 | - ) ); |
|
229 | + )); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -237,32 +237,32 @@ discard block |
||
237 | 237 | * |
238 | 238 | * @return ConstraintParameterException[] |
239 | 239 | */ |
240 | - private function checkCommonConstraintParameters( Constraint $constraint ) { |
|
240 | + private function checkCommonConstraintParameters(Constraint $constraint) { |
|
241 | 241 | $constraintParameters = $constraint->getConstraintParameters(); |
242 | 242 | try { |
243 | - $this->constraintParameterParser->checkError( $constraintParameters ); |
|
244 | - } catch ( ConstraintParameterException $e ) { |
|
245 | - return [ $e ]; |
|
243 | + $this->constraintParameterParser->checkError($constraintParameters); |
|
244 | + } catch (ConstraintParameterException $e) { |
|
245 | + return [$e]; |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | $problems = []; |
249 | 249 | try { |
250 | - $this->constraintParameterParser->parseExceptionParameter( $constraintParameters ); |
|
251 | - } catch ( ConstraintParameterException $e ) { |
|
250 | + $this->constraintParameterParser->parseExceptionParameter($constraintParameters); |
|
251 | + } catch (ConstraintParameterException $e) { |
|
252 | 252 | $problems[] = $e; |
253 | 253 | } |
254 | 254 | try { |
255 | - $this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters ); |
|
256 | - } catch ( ConstraintParameterException $e ) { |
|
255 | + $this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters); |
|
256 | + } catch (ConstraintParameterException $e) { |
|
257 | 257 | $problems[] = $e; |
258 | 258 | } |
259 | 259 | try { |
260 | 260 | $this->constraintParameterParser->parseConstraintScopeParameter( |
261 | 261 | $constraintParameters, |
262 | 262 | $constraint->getConstraintTypeItemId(), |
263 | - $this->getAllowedContextTypes( $constraint ) |
|
263 | + $this->getAllowedContextTypes($constraint) |
|
264 | 264 | ); |
265 | - } catch ( ConstraintParameterException $e ) { |
|
265 | + } catch (ConstraintParameterException $e) { |
|
266 | 266 | $problems[] = $e; |
267 | 267 | } |
268 | 268 | return $problems; |
@@ -275,16 +275,16 @@ discard block |
||
275 | 275 | * @return ConstraintParameterException[][] first level indexed by constraint ID, |
276 | 276 | * second level like checkConstraintParametersOnConstraintId (but without possibility of null) |
277 | 277 | */ |
278 | - public function checkConstraintParametersOnPropertyId( PropertyId $propertyId ) { |
|
279 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
278 | + public function checkConstraintParametersOnPropertyId(PropertyId $propertyId) { |
|
279 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
280 | 280 | $result = []; |
281 | 281 | |
282 | - foreach ( $constraints as $constraint ) { |
|
283 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
282 | + foreach ($constraints as $constraint) { |
|
283 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
284 | 284 | |
285 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
285 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
286 | 286 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
287 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
287 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | $result[$constraint->getConstraintId()] = $problems; |
@@ -301,18 +301,18 @@ discard block |
||
301 | 301 | * @return ConstraintParameterException[]|null list of constraint parameter exceptions |
302 | 302 | * (empty means all parameters okay), or null if constraint is not found |
303 | 303 | */ |
304 | - public function checkConstraintParametersOnConstraintId( $constraintId ) { |
|
305 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
304 | + public function checkConstraintParametersOnConstraintId($constraintId) { |
|
305 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
306 | 306 | '@phan-var PropertyId $propertyId'; |
307 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
307 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
308 | 308 | |
309 | - foreach ( $constraints as $constraint ) { |
|
310 | - if ( $constraint->getConstraintId() === $constraintId ) { |
|
311 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
309 | + foreach ($constraints as $constraint) { |
|
310 | + if ($constraint->getConstraintId() === $constraintId) { |
|
311 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
312 | 312 | |
313 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
313 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
314 | 314 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
315 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
315 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | return $problems; |
@@ -337,14 +337,14 @@ discard block |
||
337 | 337 | $result = []; |
338 | 338 | |
339 | 339 | /** @var Statement $statement */ |
340 | - foreach ( $entity->getStatements() as $statement ) { |
|
341 | - $result = array_merge( $result, |
|
340 | + foreach ($entity->getStatements() as $statement) { |
|
341 | + $result = array_merge($result, |
|
342 | 342 | $this->checkStatement( |
343 | 343 | $entity, |
344 | 344 | $statement, |
345 | 345 | $constraintIds, |
346 | 346 | $defaultResultsPerContext |
347 | - ) ); |
|
347 | + )); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | return $result; |
@@ -366,32 +366,32 @@ discard block |
||
366 | 366 | ) { |
367 | 367 | $result = []; |
368 | 368 | |
369 | - $result = array_merge( $result, |
|
369 | + $result = array_merge($result, |
|
370 | 370 | $this->checkConstraintsForMainSnak( |
371 | 371 | $entity, |
372 | 372 | $statement, |
373 | 373 | $constraintIds, |
374 | 374 | $defaultResultsPerContext |
375 | - ) ); |
|
375 | + )); |
|
376 | 376 | |
377 | - if ( $this->checkQualifiers ) { |
|
378 | - $result = array_merge( $result, |
|
377 | + if ($this->checkQualifiers) { |
|
378 | + $result = array_merge($result, |
|
379 | 379 | $this->checkConstraintsForQualifiers( |
380 | 380 | $entity, |
381 | 381 | $statement, |
382 | 382 | $constraintIds, |
383 | 383 | $defaultResultsPerContext |
384 | - ) ); |
|
384 | + )); |
|
385 | 385 | } |
386 | 386 | |
387 | - if ( $this->checkReferences ) { |
|
388 | - $result = array_merge( $result, |
|
387 | + if ($this->checkReferences) { |
|
388 | + $result = array_merge($result, |
|
389 | 389 | $this->checkConstraintsForReferences( |
390 | 390 | $entity, |
391 | 391 | $statement, |
392 | 392 | $constraintIds, |
393 | 393 | $defaultResultsPerContext |
394 | - ) ); |
|
394 | + )); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | return $result; |
@@ -406,12 +406,12 @@ discard block |
||
406 | 406 | * @param string[]|null $constraintIds |
407 | 407 | * @return Constraint[] |
408 | 408 | */ |
409 | - private function getConstraintsToUse( PropertyId $propertyId, array $constraintIds = null ) { |
|
410 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
411 | - if ( $constraintIds !== null ) { |
|
409 | + private function getConstraintsToUse(PropertyId $propertyId, array $constraintIds = null) { |
|
410 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
411 | + if ($constraintIds !== null) { |
|
412 | 412 | $constraintsToUse = []; |
413 | - foreach ( $constraints as $constraint ) { |
|
414 | - if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) { |
|
413 | + foreach ($constraints as $constraint) { |
|
414 | + if (in_array($constraint->getConstraintId(), $constraintIds)) { |
|
415 | 415 | $constraintsToUse[] = $constraint; |
416 | 416 | } |
417 | 417 | } |
@@ -435,18 +435,18 @@ discard block |
||
435 | 435 | array $constraintIds = null, |
436 | 436 | callable $defaultResults = null |
437 | 437 | ) { |
438 | - $context = new MainSnakContext( $entity, $statement ); |
|
438 | + $context = new MainSnakContext($entity, $statement); |
|
439 | 439 | $constraints = $this->getConstraintsToUse( |
440 | 440 | $statement->getPropertyId(), |
441 | 441 | $constraintIds |
442 | 442 | ); |
443 | - $result = $defaultResults !== null ? $defaultResults( $context ) : []; |
|
443 | + $result = $defaultResults !== null ? $defaultResults($context) : []; |
|
444 | 444 | |
445 | - foreach ( $constraints as $constraint ) { |
|
445 | + foreach ($constraints as $constraint) { |
|
446 | 446 | $parameters = $constraint->getConstraintParameters(); |
447 | 447 | try { |
448 | - $exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters ); |
|
449 | - } catch ( ConstraintParameterException $e ) { |
|
448 | + $exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters); |
|
449 | + } catch (ConstraintParameterException $e) { |
|
450 | 450 | $result[] = new CheckResult( |
451 | 451 | $context, |
452 | 452 | $constraint, |
@@ -456,13 +456,13 @@ discard block |
||
456 | 456 | continue; |
457 | 457 | } |
458 | 458 | |
459 | - if ( in_array( $entity->getId(), $exceptions ) ) { |
|
460 | - $message = new ViolationMessage( 'wbqc-violation-message-exception' ); |
|
461 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message ); |
|
459 | + if (in_array($entity->getId(), $exceptions)) { |
|
460 | + $message = new ViolationMessage('wbqc-violation-message-exception'); |
|
461 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message); |
|
462 | 462 | continue; |
463 | 463 | } |
464 | 464 | |
465 | - $result[] = $this->getCheckResultFor( $context, $constraint ); |
|
465 | + $result[] = $this->getCheckResultFor($context, $constraint); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | return $result; |
@@ -484,24 +484,24 @@ discard block |
||
484 | 484 | ) { |
485 | 485 | $result = []; |
486 | 486 | |
487 | - if ( in_array( |
|
487 | + if (in_array( |
|
488 | 488 | $statement->getPropertyId()->getSerialization(), |
489 | 489 | $this->propertiesWithViolatingQualifiers |
490 | - ) ) { |
|
490 | + )) { |
|
491 | 491 | return $result; |
492 | 492 | } |
493 | 493 | |
494 | - foreach ( $statement->getQualifiers() as $qualifier ) { |
|
495 | - $qualifierContext = new QualifierContext( $entity, $statement, $qualifier ); |
|
496 | - if ( $defaultResultsPerContext !== null ) { |
|
497 | - $result = array_merge( $result, $defaultResultsPerContext( $qualifierContext ) ); |
|
494 | + foreach ($statement->getQualifiers() as $qualifier) { |
|
495 | + $qualifierContext = new QualifierContext($entity, $statement, $qualifier); |
|
496 | + if ($defaultResultsPerContext !== null) { |
|
497 | + $result = array_merge($result, $defaultResultsPerContext($qualifierContext)); |
|
498 | 498 | } |
499 | 499 | $qualifierConstraints = $this->getConstraintsToUse( |
500 | 500 | $qualifierContext->getSnak()->getPropertyId(), |
501 | 501 | $constraintIds |
502 | 502 | ); |
503 | - foreach ( $qualifierConstraints as $qualifierConstraint ) { |
|
504 | - $result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint ); |
|
503 | + foreach ($qualifierConstraints as $qualifierConstraint) { |
|
504 | + $result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint); |
|
505 | 505 | } |
506 | 506 | } |
507 | 507 | |
@@ -525,19 +525,19 @@ discard block |
||
525 | 525 | $result = []; |
526 | 526 | |
527 | 527 | /** @var Reference $reference */ |
528 | - foreach ( $statement->getReferences() as $reference ) { |
|
529 | - foreach ( $reference->getSnaks() as $snak ) { |
|
528 | + foreach ($statement->getReferences() as $reference) { |
|
529 | + foreach ($reference->getSnaks() as $snak) { |
|
530 | 530 | $referenceContext = new ReferenceContext( |
531 | 531 | $entity, $statement, $reference, $snak |
532 | 532 | ); |
533 | - if ( $defaultResultsPerContext !== null ) { |
|
534 | - $result = array_merge( $result, $defaultResultsPerContext( $referenceContext ) ); |
|
533 | + if ($defaultResultsPerContext !== null) { |
|
534 | + $result = array_merge($result, $defaultResultsPerContext($referenceContext)); |
|
535 | 535 | } |
536 | 536 | $referenceConstraints = $this->getConstraintsToUse( |
537 | 537 | $referenceContext->getSnak()->getPropertyId(), |
538 | 538 | $constraintIds |
539 | 539 | ); |
540 | - foreach ( $referenceConstraints as $referenceConstraint ) { |
|
540 | + foreach ($referenceConstraints as $referenceConstraint) { |
|
541 | 541 | $result[] = $this->getCheckResultFor( |
542 | 542 | $referenceContext, |
543 | 543 | $referenceConstraint |
@@ -556,20 +556,20 @@ discard block |
||
556 | 556 | * @throws InvalidArgumentException |
557 | 557 | * @return CheckResult |
558 | 558 | */ |
559 | - private function getCheckResultFor( Context $context, Constraint $constraint ) { |
|
560 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
559 | + private function getCheckResultFor(Context $context, Constraint $constraint) { |
|
560 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
561 | 561 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
562 | - $result = $this->handleScope( $checker, $context, $constraint ); |
|
562 | + $result = $this->handleScope($checker, $context, $constraint); |
|
563 | 563 | |
564 | - if ( $result !== null ) { |
|
565 | - $this->addMetadata( $context, $result ); |
|
564 | + if ($result !== null) { |
|
565 | + $this->addMetadata($context, $result); |
|
566 | 566 | return $result; |
567 | 567 | } |
568 | 568 | |
569 | - $startTime = microtime( true ); |
|
569 | + $startTime = microtime(true); |
|
570 | 570 | try { |
571 | - $result = $checker->checkConstraint( $context, $constraint ); |
|
572 | - } catch ( ConstraintParameterException $e ) { |
|
571 | + $result = $checker->checkConstraint($context, $constraint); |
|
572 | + } catch (ConstraintParameterException $e) { |
|
573 | 573 | $result = new CheckResult( |
574 | 574 | $context, |
575 | 575 | $constraint, |
@@ -577,28 +577,28 @@ discard block |
||
577 | 577 | CheckResult::STATUS_BAD_PARAMETERS, |
578 | 578 | $e->getViolationMessage() |
579 | 579 | ); |
580 | - } catch ( SparqlHelperException $e ) { |
|
581 | - $message = new ViolationMessage( 'wbqc-violation-message-sparql-error' ); |
|
582 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, $message ); |
|
580 | + } catch (SparqlHelperException $e) { |
|
581 | + $message = new ViolationMessage('wbqc-violation-message-sparql-error'); |
|
582 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, $message); |
|
583 | 583 | } |
584 | - $endTime = microtime( true ); |
|
584 | + $endTime = microtime(true); |
|
585 | 585 | |
586 | - $this->addMetadata( $context, $result ); |
|
586 | + $this->addMetadata($context, $result); |
|
587 | 587 | |
588 | - $this->downgradeResultStatus( $context, $result ); |
|
588 | + $this->downgradeResultStatus($context, $result); |
|
589 | 589 | |
590 | 590 | $this->loggingHelper->logConstraintCheck( |
591 | 591 | $context, |
592 | 592 | $constraint, |
593 | 593 | $result, |
594 | - get_class( $checker ), |
|
594 | + get_class($checker), |
|
595 | 595 | $endTime - $startTime, |
596 | 596 | __METHOD__ |
597 | 597 | ); |
598 | 598 | |
599 | 599 | return $result; |
600 | 600 | } else { |
601 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
601 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
602 | 602 | } |
603 | 603 | } |
604 | 604 | |
@@ -612,61 +612,61 @@ discard block |
||
612 | 612 | $constraint->getConstraintParameters(), |
613 | 613 | $constraint->getConstraintTypeItemId() |
614 | 614 | ); |
615 | - } catch ( ConstraintParameterException $e ) { |
|
616 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
615 | + } catch (ConstraintParameterException $e) { |
|
616 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
617 | 617 | } |
618 | - if ( $checkedContextTypes === null ) { |
|
618 | + if ($checkedContextTypes === null) { |
|
619 | 619 | $checkedContextTypes = $checker->getDefaultContextTypes(); |
620 | 620 | } |
621 | - if ( !in_array( $context->getType(), $checkedContextTypes ) ) { |
|
622 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null ); |
|
621 | + if (!in_array($context->getType(), $checkedContextTypes)) { |
|
622 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null); |
|
623 | 623 | } |
624 | - if ( $checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO ) { |
|
625 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
624 | + if ($checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO) { |
|
625 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
626 | 626 | } |
627 | 627 | return null; |
628 | 628 | } |
629 | 629 | |
630 | - private function addMetadata( Context $context, CheckResult $result ) { |
|
631 | - $result->withMetadata( Metadata::merge( [ |
|
630 | + private function addMetadata(Context $context, CheckResult $result) { |
|
631 | + $result->withMetadata(Metadata::merge([ |
|
632 | 632 | $result->getMetadata(), |
633 | - Metadata::ofDependencyMetadata( DependencyMetadata::merge( [ |
|
634 | - DependencyMetadata::ofEntityId( $context->getEntity()->getId() ), |
|
635 | - DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ), |
|
636 | - ] ) ), |
|
637 | - ] ) ); |
|
633 | + Metadata::ofDependencyMetadata(DependencyMetadata::merge([ |
|
634 | + DependencyMetadata::ofEntityId($context->getEntity()->getId()), |
|
635 | + DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()), |
|
636 | + ])), |
|
637 | + ])); |
|
638 | 638 | } |
639 | 639 | |
640 | - private function downgradeResultStatus( Context $context, CheckResult &$result ) { |
|
640 | + private function downgradeResultStatus(Context $context, CheckResult &$result) { |
|
641 | 641 | $constraint = $result->getConstraint(); |
642 | 642 | try { |
643 | 643 | $constraintStatus = $this->constraintParameterParser |
644 | - ->parseConstraintStatusParameter( $constraint->getConstraintParameters() ); |
|
645 | - } catch ( ConstraintParameterException $e ) { |
|
646 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
644 | + ->parseConstraintStatusParameter($constraint->getConstraintParameters()); |
|
645 | + } catch (ConstraintParameterException $e) { |
|
646 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
647 | 647 | $constraintStatus = null; |
648 | 648 | } |
649 | - if ( $constraintStatus === null ) { |
|
649 | + if ($constraintStatus === null) { |
|
650 | 650 | // downgrade violation to warning |
651 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
652 | - $result->setStatus( CheckResult::STATUS_WARNING ); |
|
651 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
652 | + $result->setStatus(CheckResult::STATUS_WARNING); |
|
653 | 653 | } |
654 | - } elseif ( $constraintStatus === 'suggestion' ) { |
|
654 | + } elseif ($constraintStatus === 'suggestion') { |
|
655 | 655 | // downgrade violation to suggestion |
656 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
657 | - $result->setStatus( CheckResult::STATUS_SUGGESTION ); |
|
656 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
657 | + $result->setStatus(CheckResult::STATUS_SUGGESTION); |
|
658 | 658 | } |
659 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
659 | + $result->addParameter('constraint_status', $constraintStatus); |
|
660 | 660 | } else { |
661 | - if ( $constraintStatus !== 'mandatory' ) { |
|
661 | + if ($constraintStatus !== 'mandatory') { |
|
662 | 662 | // @codeCoverageIgnoreStart |
663 | 663 | throw new LogicException( |
664 | - "Unknown constraint status '$constraintStatus', " . |
|
664 | + "Unknown constraint status '$constraintStatus', ". |
|
665 | 665 | "only known statuses are 'mandatory' and 'suggestion'" |
666 | 666 | ); |
667 | 667 | // @codeCoverageIgnoreEnd |
668 | 668 | } |
669 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
669 | + $result->addParameter('constraint_status', $constraintStatus); |
|
670 | 670 | } |
671 | 671 | } |
672 | 672 | |
@@ -675,12 +675,12 @@ discard block |
||
675 | 675 | * |
676 | 676 | * @return CheckResult[] |
677 | 677 | */ |
678 | - private function sortResult( array $result ) { |
|
679 | - if ( count( $result ) < 2 ) { |
|
678 | + private function sortResult(array $result) { |
|
679 | + if (count($result) < 2) { |
|
680 | 680 | return $result; |
681 | 681 | } |
682 | 682 | |
683 | - $sortFunction = static function ( CheckResult $a, CheckResult $b ) { |
|
683 | + $sortFunction = static function(CheckResult $a, CheckResult $b) { |
|
684 | 684 | $orderNum = 0; |
685 | 685 | $order = [ |
686 | 686 | CheckResult::STATUS_BAD_PARAMETERS => $orderNum++, |
@@ -697,55 +697,55 @@ discard block |
||
697 | 697 | $statusA = $a->getStatus(); |
698 | 698 | $statusB = $b->getStatus(); |
699 | 699 | |
700 | - $orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ]; |
|
701 | - $orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ]; |
|
700 | + $orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other']; |
|
701 | + $orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other']; |
|
702 | 702 | |
703 | - if ( $orderA === $orderB ) { |
|
703 | + if ($orderA === $orderB) { |
|
704 | 704 | $cursorA = $a->getContextCursor(); |
705 | 705 | $cursorB = $b->getContextCursor(); |
706 | 706 | |
707 | - if ( $cursorA instanceof EntityContextCursor ) { |
|
707 | + if ($cursorA instanceof EntityContextCursor) { |
|
708 | 708 | return $cursorB instanceof EntityContextCursor ? 0 : -1; |
709 | 709 | } |
710 | - if ( $cursorB instanceof EntityContextCursor ) { |
|
710 | + if ($cursorB instanceof EntityContextCursor) { |
|
711 | 711 | return $cursorA instanceof EntityContextCursor ? 0 : 1; |
712 | 712 | } |
713 | 713 | |
714 | 714 | $pidA = $cursorA->getSnakPropertyId(); |
715 | 715 | $pidB = $cursorB->getSnakPropertyId(); |
716 | 716 | |
717 | - if ( $pidA === $pidB ) { |
|
717 | + if ($pidA === $pidB) { |
|
718 | 718 | $hashA = $cursorA->getSnakHash(); |
719 | 719 | $hashB = $cursorB->getSnakHash(); |
720 | 720 | |
721 | - if ( $hashA === $hashB ) { |
|
722 | - if ( $a instanceof NullResult ) { |
|
721 | + if ($hashA === $hashB) { |
|
722 | + if ($a instanceof NullResult) { |
|
723 | 723 | return $b instanceof NullResult ? 0 : -1; |
724 | 724 | } |
725 | - if ( $b instanceof NullResult ) { |
|
725 | + if ($b instanceof NullResult) { |
|
726 | 726 | return $a instanceof NullResult ? 0 : 1; |
727 | 727 | } |
728 | 728 | |
729 | 729 | $typeA = $a->getConstraint()->getConstraintTypeItemId(); |
730 | 730 | $typeB = $b->getConstraint()->getConstraintTypeItemId(); |
731 | 731 | |
732 | - if ( $typeA == $typeB ) { |
|
732 | + if ($typeA == $typeB) { |
|
733 | 733 | return 0; |
734 | 734 | } else { |
735 | - return ( $typeA > $typeB ) ? 1 : -1; |
|
735 | + return ($typeA > $typeB) ? 1 : -1; |
|
736 | 736 | } |
737 | 737 | } else { |
738 | - return ( $hashA > $hashB ) ? 1 : -1; |
|
738 | + return ($hashA > $hashB) ? 1 : -1; |
|
739 | 739 | } |
740 | 740 | } else { |
741 | - return ( $pidA > $pidB ) ? 1 : -1; |
|
741 | + return ($pidA > $pidB) ? 1 : -1; |
|
742 | 742 | } |
743 | 743 | } else { |
744 | - return ( $orderA > $orderB ) ? 1 : -1; |
|
744 | + return ($orderA > $orderB) ? 1 : -1; |
|
745 | 745 | } |
746 | 746 | }; |
747 | 747 | |
748 | - uasort( $result, $sortFunction ); |
|
748 | + uasort($result, $sortFunction); |
|
749 | 749 | |
750 | 750 | return $result; |
751 | 751 | } |