@@ -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\Checker; |
| 6 | 6 | |
@@ -64,18 +64,18 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
| 66 | 66 | */ |
| 67 | - public function checkConstraint( Context $context, Constraint $constraint ): CheckResult { |
|
| 68 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
| 69 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED ); |
|
| 67 | + public function checkConstraint(Context $context, Constraint $constraint): CheckResult { |
|
| 68 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
| 69 | + return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) { |
|
| 72 | + if (!($this->sparqlHelper instanceof DummySparqlHelper)) { |
|
| 73 | 73 | |
| 74 | 74 | $separators = $this->constraintParameterParser->parseSeparatorsParameter( |
| 75 | 75 | $constraint->getConstraintParameters() |
| 76 | 76 | ); |
| 77 | 77 | |
| 78 | - if ( $context->getType() === 'statement' ) { |
|
| 78 | + if ($context->getType() === 'statement') { |
|
| 79 | 79 | $statement = $context->getSnakStatement(); |
| 80 | 80 | '@phan-var Statement $statement'; |
| 81 | 81 | $result = $this->sparqlHelper->findEntitiesWithSameStatement( |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | ); |
| 85 | 85 | } else { |
| 86 | 86 | $snak = $context->getSnak(); |
| 87 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
| 87 | + if (!$snak instanceof PropertyValueSnak) { |
|
| 88 | 88 | // nothing to check |
| 89 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE ); |
|
| 89 | + return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE); |
|
| 90 | 90 | } |
| 91 | 91 | $result = $this->sparqlHelper->findEntitiesWithSameQualifierOrReference( |
| 92 | 92 | $context->getEntity()->getId(), |
@@ -99,31 +99,31 @@ discard block |
||
| 99 | 99 | $otherEntities = $result->getArray(); |
| 100 | 100 | $metadata = $result->getMetadata(); |
| 101 | 101 | |
| 102 | - if ( $otherEntities === [] ) { |
|
| 102 | + if ($otherEntities === []) { |
|
| 103 | 103 | $status = CheckResult::STATUS_COMPLIANCE; |
| 104 | 104 | $message = null; |
| 105 | 105 | } else { |
| 106 | 106 | $status = CheckResult::STATUS_VIOLATION; |
| 107 | - $message = ( new ViolationMessage( 'wbqc-violation-message-unique-value' ) ) |
|
| 108 | - ->withEntityIdList( $otherEntities, Role::SUBJECT ); |
|
| 107 | + $message = (new ViolationMessage('wbqc-violation-message-unique-value')) |
|
| 108 | + ->withEntityIdList($otherEntities, Role::SUBJECT); |
|
| 109 | 109 | } |
| 110 | 110 | } else { |
| 111 | 111 | $status = CheckResult::STATUS_TODO; |
| 112 | - $message = ( new ViolationMessage( 'wbqc-violation-message-not-yet-implemented' ) ) |
|
| 113 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ); |
|
| 112 | + $message = (new ViolationMessage('wbqc-violation-message-not-yet-implemented')) |
|
| 113 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM); |
|
| 114 | 114 | $metadata = Metadata::blank(); |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - return ( new CheckResult( $context, $constraint, $status, $message ) ) |
|
| 118 | - ->withMetadata( $metadata ); |
|
| 117 | + return (new CheckResult($context, $constraint, $status, $message)) |
|
| 118 | + ->withMetadata($metadata); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - public function checkConstraintParameters( Constraint $constraint ): array { |
|
| 121 | + public function checkConstraintParameters(Constraint $constraint): array { |
|
| 122 | 122 | $constraintParameters = $constraint->getConstraintParameters(); |
| 123 | 123 | $exceptions = []; |
| 124 | 124 | try { |
| 125 | - $this->constraintParameterParser->parseSeparatorsParameter( $constraintParameters ); |
|
| 126 | - } catch ( ConstraintParameterException $e ) { |
|
| 125 | + $this->constraintParameterParser->parseSeparatorsParameter($constraintParameters); |
|
| 126 | + } catch (ConstraintParameterException $e) { |
|
| 127 | 127 | $exceptions[] = $e; |
| 128 | 128 | } |
| 129 | 129 | return $exceptions; |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare( strict_types = 1 ); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Cache; |
| 6 | 6 | |
@@ -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\Helper; |
| 6 | 6 | |
@@ -148,74 +148,74 @@ discard block |
||
| 148 | 148 | $this->defaultUserAgent = $defaultUserAgent; |
| 149 | 149 | $this->requestFactory = $requestFactory; |
| 150 | 150 | $this->entityPrefixes = []; |
| 151 | - foreach ( $rdfVocabulary->entityNamespaceNames as $namespaceName ) { |
|
| 152 | - $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI( $namespaceName ); |
|
| 151 | + foreach ($rdfVocabulary->entityNamespaceNames as $namespaceName) { |
|
| 152 | + $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI($namespaceName); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - $this->primaryEndpoint = $config->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
| 156 | - $this->additionalEndpoints = $config->get( 'WBQualityConstraintsAdditionalSparqlEndpoints' ) ?: []; |
|
| 157 | - $this->maxQueryTimeMillis = $config->get( 'WBQualityConstraintsSparqlMaxMillis' ); |
|
| 158 | - $this->instanceOfId = $config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
| 159 | - $this->subclassOfId = $config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
| 160 | - $this->cacheMapSize = $config->get( 'WBQualityConstraintsFormatCacheMapSize' ); |
|
| 155 | + $this->primaryEndpoint = $config->get('WBQualityConstraintsSparqlEndpoint'); |
|
| 156 | + $this->additionalEndpoints = $config->get('WBQualityConstraintsAdditionalSparqlEndpoints') ?: []; |
|
| 157 | + $this->maxQueryTimeMillis = $config->get('WBQualityConstraintsSparqlMaxMillis'); |
|
| 158 | + $this->instanceOfId = $config->get('WBQualityConstraintsInstanceOfId'); |
|
| 159 | + $this->subclassOfId = $config->get('WBQualityConstraintsSubclassOfId'); |
|
| 160 | + $this->cacheMapSize = $config->get('WBQualityConstraintsFormatCacheMapSize'); |
|
| 161 | 161 | $this->timeoutExceptionClasses = $config->get( |
| 162 | 162 | 'WBQualityConstraintsSparqlTimeoutExceptionClasses' |
| 163 | 163 | ); |
| 164 | 164 | $this->sparqlHasWikibaseSupport = $config->get( |
| 165 | 165 | 'WBQualityConstraintsSparqlHasWikibaseSupport' |
| 166 | 166 | ); |
| 167 | - $this->sparqlThrottlingFallbackDuration = (int)$config->get( |
|
| 167 | + $this->sparqlThrottlingFallbackDuration = (int) $config->get( |
|
| 168 | 168 | 'WBQualityConstraintsSparqlThrottlingFallbackDuration' |
| 169 | 169 | ); |
| 170 | 170 | |
| 171 | - $this->prefixes = $this->getQueryPrefixes( $rdfVocabulary ); |
|
| 171 | + $this->prefixes = $this->getQueryPrefixes($rdfVocabulary); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - private function getQueryPrefixes( RdfVocabulary $rdfVocabulary ): string { |
|
| 174 | + private function getQueryPrefixes(RdfVocabulary $rdfVocabulary): string { |
|
| 175 | 175 | // TODO: it would probably be smarter that RdfVocabulary exposed these prefixes somehow |
| 176 | 176 | $prefixes = ''; |
| 177 | - foreach ( $rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName ) { |
|
| 177 | + foreach ($rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName) { |
|
| 178 | 178 | $prefixes .= <<<END |
| 179 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
| 179 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
| 180 | 180 | END; |
| 181 | 181 | } |
| 182 | 182 | $prefixes .= <<<END |
| 183 | -PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}> |
|
| 184 | -PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}>\n |
|
| 183 | +PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}> |
|
| 184 | +PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}>\n |
|
| 185 | 185 | END; |
| 186 | 186 | |
| 187 | - foreach ( $rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces ) { |
|
| 187 | + foreach ($rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces) { |
|
| 188 | 188 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_DIRECT_CLAIM]; |
| 189 | 189 | $prefixes .= <<<END |
| 190 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
| 190 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
| 191 | 191 | END; |
| 192 | 192 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM]; |
| 193 | 193 | $prefixes .= <<<END |
| 194 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
| 194 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
| 195 | 195 | END; |
| 196 | 196 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM_STATEMENT]; |
| 197 | 197 | $prefixes .= <<<END |
| 198 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
| 198 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
| 199 | 199 | END; |
| 200 | 200 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER]; |
| 201 | 201 | $prefixes .= <<<END |
| 202 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
| 202 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
| 203 | 203 | END; |
| 204 | 204 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER_VALUE]; |
| 205 | 205 | $prefixes .= <<<END |
| 206 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
| 206 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
| 207 | 207 | END; |
| 208 | 208 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE]; |
| 209 | 209 | $prefixes .= <<<END |
| 210 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
| 210 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
| 211 | 211 | END; |
| 212 | 212 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE_VALUE]; |
| 213 | 213 | $prefixes .= <<<END |
| 214 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
| 214 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
| 215 | 215 | END; |
| 216 | 216 | } |
| 217 | 217 | $prefixes .= <<<END |
| 218 | -PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ONTOLOGY )}>\n |
|
| 218 | +PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ONTOLOGY)}>\n |
|
| 219 | 219 | END; |
| 220 | 220 | return $prefixes; |
| 221 | 221 | } |
@@ -227,21 +227,20 @@ discard block |
||
| 227 | 227 | * @return CachedBool |
| 228 | 228 | * @throws SparqlHelperException if the query times out or some other error occurs |
| 229 | 229 | */ |
| 230 | - public function hasType( string $id, array $classes ): CachedBool { |
|
| 230 | + public function hasType(string $id, array $classes): CachedBool { |
|
| 231 | 231 | // TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually |
| 232 | 232 | $gearingHint = $this->sparqlHasWikibaseSupport ? |
| 233 | - ' hint:Prior hint:gearing "forward".' : |
|
| 234 | - ''; |
|
| 233 | + ' hint:Prior hint:gearing "forward".' : ''; |
|
| 235 | 234 | |
| 236 | 235 | $metadatas = []; |
| 237 | 236 | |
| 238 | - foreach ( array_chunk( $classes, 20 ) as $classesChunk ) { |
|
| 239 | - $classesValues = implode( ' ', array_map( |
|
| 240 | - static function ( $class ) { |
|
| 241 | - return 'wd:' . $class; |
|
| 237 | + foreach (array_chunk($classes, 20) as $classesChunk) { |
|
| 238 | + $classesValues = implode(' ', array_map( |
|
| 239 | + static function($class) { |
|
| 240 | + return 'wd:'.$class; |
|
| 242 | 241 | }, |
| 243 | 242 | $classesChunk |
| 244 | - ) ); |
|
| 243 | + )); |
|
| 245 | 244 | |
| 246 | 245 | $query = <<<EOF |
| 247 | 246 | ASK { |
@@ -251,19 +250,19 @@ discard block |
||
| 251 | 250 | } |
| 252 | 251 | EOF; |
| 253 | 252 | |
| 254 | - $result = $this->runQuery( $query, $this->primaryEndpoint ); |
|
| 253 | + $result = $this->runQuery($query, $this->primaryEndpoint); |
|
| 255 | 254 | $metadatas[] = $result->getMetadata(); |
| 256 | - if ( $result->getArray()['boolean'] ) { |
|
| 255 | + if ($result->getArray()['boolean']) { |
|
| 257 | 256 | return new CachedBool( |
| 258 | 257 | true, |
| 259 | - Metadata::merge( $metadatas ) |
|
| 258 | + Metadata::merge($metadatas) |
|
| 260 | 259 | ); |
| 261 | 260 | } |
| 262 | 261 | } |
| 263 | 262 | |
| 264 | 263 | return new CachedBool( |
| 265 | 264 | false, |
| 266 | - Metadata::merge( $metadatas ) |
|
| 265 | + Metadata::merge($metadatas) |
|
| 267 | 266 | ); |
| 268 | 267 | } |
| 269 | 268 | |
@@ -271,7 +270,7 @@ discard block |
||
| 271 | 270 | * Helper function used by findEntitiesWithSameStatement to filter |
| 272 | 271 | * out entities with different qualifiers or no qualifier value. |
| 273 | 272 | */ |
| 274 | - private function nestedSeparatorFilter( PropertyId $separator ): string { |
|
| 273 | + private function nestedSeparatorFilter(PropertyId $separator): string { |
|
| 275 | 274 | $filter = <<<EOF |
| 276 | 275 | MINUS { |
| 277 | 276 | ?statement pq:$separator ?qualifier. |
@@ -308,14 +307,14 @@ discard block |
||
| 308 | 307 | * @return CachedEntityIds |
| 309 | 308 | * @throws SparqlHelperException if the query times out or some other error occurs |
| 310 | 309 | */ |
| 311 | - public function findEntitiesWithSameStatement( Statement $statement, array $separators ): CachedEntityIds { |
|
| 310 | + public function findEntitiesWithSameStatement(Statement $statement, array $separators): CachedEntityIds { |
|
| 312 | 311 | $pid = $statement->getPropertyId()->getSerialization(); |
| 313 | 312 | $guid = $statement->getGuid(); |
| 314 | 313 | '@phan-var string $guid'; // statement must have a non-null GUID |
| 315 | - $guidForRdf = str_replace( '$', '-', $guid ); |
|
| 314 | + $guidForRdf = str_replace('$', '-', $guid); |
|
| 316 | 315 | |
| 317 | - $separatorFilters = array_map( [ $this, 'nestedSeparatorFilter' ], $separators ); |
|
| 318 | - $finalSeparatorFilter = implode( "\n", $separatorFilters ); |
|
| 316 | + $separatorFilters = array_map([$this, 'nestedSeparatorFilter'], $separators); |
|
| 317 | + $finalSeparatorFilter = implode("\n", $separatorFilters); |
|
| 319 | 318 | |
| 320 | 319 | $query = <<<EOF |
| 321 | 320 | SELECT DISTINCT ?otherEntity WHERE { |
@@ -333,12 +332,12 @@ discard block |
||
| 333 | 332 | LIMIT 10 |
| 334 | 333 | EOF; |
| 335 | 334 | |
| 336 | - $results = [ $this->runQuery( $query, $this->primaryEndpoint ) ]; |
|
| 337 | - foreach ( $this->additionalEndpoints as $endpoint ) { |
|
| 338 | - $results[] = $this->runQuery( $query, $endpoint ); |
|
| 335 | + $results = [$this->runQuery($query, $this->primaryEndpoint)]; |
|
| 336 | + foreach ($this->additionalEndpoints as $endpoint) { |
|
| 337 | + $results[] = $this->runQuery($query, $endpoint); |
|
| 339 | 338 | } |
| 340 | 339 | |
| 341 | - return $this->getOtherEntities( $results ); |
|
| 340 | + return $this->getOtherEntities($results); |
|
| 342 | 341 | } |
| 343 | 342 | |
| 344 | 343 | /** |
@@ -363,16 +362,15 @@ discard block |
||
| 363 | 362 | $dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty( |
| 364 | 363 | $snak->getPropertyId() |
| 365 | 364 | ); |
| 366 | - [ $value, $isFullValue ] = $this->getRdfLiteral( $dataType, $dataValue ); |
|
| 367 | - if ( $isFullValue ) { |
|
| 365 | + [$value, $isFullValue] = $this->getRdfLiteral($dataType, $dataValue); |
|
| 366 | + if ($isFullValue) { |
|
| 368 | 367 | $prefix .= 'v'; |
| 369 | 368 | } |
| 370 | 369 | $path = $type === Context::TYPE_QUALIFIER ? |
| 371 | - "$prefix:$pid" : |
|
| 372 | - "prov:wasDerivedFrom/$prefix:$pid"; |
|
| 370 | + "$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid"; |
|
| 373 | 371 | |
| 374 | 372 | $deprecatedFilter = ''; |
| 375 | - if ( $ignoreDeprecatedStatements ) { |
|
| 373 | + if ($ignoreDeprecatedStatements) { |
|
| 376 | 374 | $deprecatedFilter = <<< EOF |
| 377 | 375 | MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. } |
| 378 | 376 | EOF; |
@@ -392,19 +390,19 @@ discard block |
||
| 392 | 390 | LIMIT 10 |
| 393 | 391 | EOF; |
| 394 | 392 | |
| 395 | - $results = [ $this->runQuery( $query, $this->primaryEndpoint ) ]; |
|
| 396 | - foreach ( $this->additionalEndpoints as $endpoint ) { |
|
| 397 | - $results[] = $this->runQuery( $query, $endpoint ); |
|
| 393 | + $results = [$this->runQuery($query, $this->primaryEndpoint)]; |
|
| 394 | + foreach ($this->additionalEndpoints as $endpoint) { |
|
| 395 | + $results[] = $this->runQuery($query, $endpoint); |
|
| 398 | 396 | } |
| 399 | 397 | |
| 400 | - return $this->getOtherEntities( $results ); |
|
| 398 | + return $this->getOtherEntities($results); |
|
| 401 | 399 | } |
| 402 | 400 | |
| 403 | 401 | /** |
| 404 | 402 | * Return SPARQL code for a string literal with $text as content. |
| 405 | 403 | */ |
| 406 | - private function stringLiteral( string $text ): string { |
|
| 407 | - return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"'; |
|
| 404 | + private function stringLiteral(string $text): string { |
|
| 405 | + return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"'; |
|
| 408 | 406 | } |
| 409 | 407 | |
| 410 | 408 | /** |
@@ -414,26 +412,26 @@ discard block |
||
| 414 | 412 | * |
| 415 | 413 | * @return CachedEntityIds |
| 416 | 414 | */ |
| 417 | - private function getOtherEntities( array $results ): CachedEntityIds { |
|
| 415 | + private function getOtherEntities(array $results): CachedEntityIds { |
|
| 418 | 416 | $allResultBindings = []; |
| 419 | 417 | $metadatas = []; |
| 420 | 418 | |
| 421 | - foreach ( $results as $result ) { |
|
| 419 | + foreach ($results as $result) { |
|
| 422 | 420 | $metadatas[] = $result->getMetadata(); |
| 423 | - $allResultBindings = array_merge( $allResultBindings, $result->getArray()['results']['bindings'] ); |
|
| 421 | + $allResultBindings = array_merge($allResultBindings, $result->getArray()['results']['bindings']); |
|
| 424 | 422 | } |
| 425 | 423 | |
| 426 | 424 | $entityIds = array_map( |
| 427 | - function ( $resultBindings ) { |
|
| 425 | + function($resultBindings) { |
|
| 428 | 426 | $entityIRI = $resultBindings['otherEntity']['value']; |
| 429 | - foreach ( $this->entityPrefixes as $entityPrefix ) { |
|
| 430 | - $entityPrefixLength = strlen( $entityPrefix ); |
|
| 431 | - if ( substr( $entityIRI, 0, $entityPrefixLength ) === $entityPrefix ) { |
|
| 427 | + foreach ($this->entityPrefixes as $entityPrefix) { |
|
| 428 | + $entityPrefixLength = strlen($entityPrefix); |
|
| 429 | + if (substr($entityIRI, 0, $entityPrefixLength) === $entityPrefix) { |
|
| 432 | 430 | try { |
| 433 | 431 | return $this->entityIdParser->parse( |
| 434 | - substr( $entityIRI, $entityPrefixLength ) |
|
| 432 | + substr($entityIRI, $entityPrefixLength) |
|
| 435 | 433 | ); |
| 436 | - } catch ( EntityIdParsingException $e ) { |
|
| 434 | + } catch (EntityIdParsingException $e) { |
|
| 437 | 435 | // fall through |
| 438 | 436 | } |
| 439 | 437 | } |
@@ -447,8 +445,8 @@ discard block |
||
| 447 | 445 | ); |
| 448 | 446 | |
| 449 | 447 | return new CachedEntityIds( |
| 450 | - array_values( array_filter( array_unique( $entityIds ) ) ), |
|
| 451 | - Metadata::merge( $metadatas ) |
|
| 448 | + array_values(array_filter(array_unique($entityIds))), |
|
| 449 | + Metadata::merge($metadatas) |
|
| 452 | 450 | ); |
| 453 | 451 | } |
| 454 | 452 | |
@@ -459,50 +457,50 @@ discard block |
||
| 459 | 457 | * @return array the literal or IRI as a string in SPARQL syntax, |
| 460 | 458 | * and a boolean indicating whether it refers to a full value node or not |
| 461 | 459 | */ |
| 462 | - private function getRdfLiteral( string $dataType, DataValue $dataValue ): array { |
|
| 463 | - switch ( $dataType ) { |
|
| 460 | + private function getRdfLiteral(string $dataType, DataValue $dataValue): array { |
|
| 461 | + switch ($dataType) { |
|
| 464 | 462 | case 'string': |
| 465 | 463 | case 'external-id': |
| 466 | - return [ $this->stringLiteral( $dataValue->getValue() ), false ]; |
|
| 464 | + return [$this->stringLiteral($dataValue->getValue()), false]; |
|
| 467 | 465 | case 'commonsMedia': |
| 468 | - $url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() ); |
|
| 469 | - return [ '<' . $url . '>', false ]; |
|
| 466 | + $url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue()); |
|
| 467 | + return ['<'.$url.'>', false]; |
|
| 470 | 468 | case 'geo-shape': |
| 471 | - $url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() ); |
|
| 472 | - return [ '<' . $url . '>', false ]; |
|
| 469 | + $url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue()); |
|
| 470 | + return ['<'.$url.'>', false]; |
|
| 473 | 471 | case 'tabular-data': |
| 474 | - $url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() ); |
|
| 475 | - return [ '<' . $url . '>', false ]; |
|
| 472 | + $url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue()); |
|
| 473 | + return ['<'.$url.'>', false]; |
|
| 476 | 474 | case 'url': |
| 477 | 475 | $url = $dataValue->getValue(); |
| 478 | - if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) { |
|
| 476 | + if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) { |
|
| 479 | 477 | // not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF) |
| 480 | 478 | // such an URL should never reach us, so just throw |
| 481 | - throw new InvalidArgumentException( 'invalid URL: ' . $url ); |
|
| 479 | + throw new InvalidArgumentException('invalid URL: '.$url); |
|
| 482 | 480 | } |
| 483 | - return [ '<' . $url . '>', false ]; |
|
| 481 | + return ['<'.$url.'>', false]; |
|
| 484 | 482 | case 'wikibase-item': |
| 485 | 483 | case 'wikibase-property': |
| 486 | 484 | /** @var EntityIdValue $dataValue */ |
| 487 | 485 | '@phan-var EntityIdValue $dataValue'; |
| 488 | - return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ]; |
|
| 486 | + return ['wd:'.$dataValue->getEntityId()->getSerialization(), false]; |
|
| 489 | 487 | case 'monolingualtext': |
| 490 | 488 | /** @var MonolingualTextValue $dataValue */ |
| 491 | 489 | '@phan-var MonolingualTextValue $dataValue'; |
| 492 | 490 | $lang = $dataValue->getLanguageCode(); |
| 493 | - if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) { |
|
| 491 | + if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) { |
|
| 494 | 492 | // not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG) |
| 495 | 493 | // such a language tag should never reach us, so just throw |
| 496 | - throw new InvalidArgumentException( 'invalid language tag: ' . $lang ); |
|
| 494 | + throw new InvalidArgumentException('invalid language tag: '.$lang); |
|
| 497 | 495 | } |
| 498 | - return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ]; |
|
| 496 | + return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false]; |
|
| 499 | 497 | case 'globe-coordinate': |
| 500 | 498 | case 'quantity': |
| 501 | 499 | case 'time': |
| 502 | 500 | // @phan-suppress-next-line PhanUndeclaredMethod |
| 503 | - return [ 'wdv:' . $dataValue->getHash(), true ]; |
|
| 501 | + return ['wdv:'.$dataValue->getHash(), true]; |
|
| 504 | 502 | default: |
| 505 | - throw new InvalidArgumentException( 'unknown data type: ' . $dataType ); |
|
| 503 | + throw new InvalidArgumentException('unknown data type: '.$dataType); |
|
| 506 | 504 | } |
| 507 | 505 | } |
| 508 | 506 | // phpcs:enable |
@@ -511,43 +509,43 @@ discard block |
||
| 511 | 509 | * @throws SparqlHelperException if the query times out or some other error occurs |
| 512 | 510 | * @throws ConstraintParameterException if the $regex is invalid |
| 513 | 511 | */ |
| 514 | - public function matchesRegularExpression( string $text, string $regex ): bool { |
|
| 512 | + public function matchesRegularExpression(string $text, string $regex): bool { |
|
| 515 | 513 | // caching wrapper around matchesRegularExpressionWithSparql |
| 516 | 514 | |
| 517 | - $textHash = hash( 'sha256', $text ); |
|
| 515 | + $textHash = hash('sha256', $text); |
|
| 518 | 516 | $cacheKey = $this->cache->makeKey( |
| 519 | 517 | 'WikibaseQualityConstraints', // extension |
| 520 | 518 | 'regex', // action |
| 521 | 519 | 'WDQS-Java', // regex flavor |
| 522 | - hash( 'sha256', $regex ) |
|
| 520 | + hash('sha256', $regex) |
|
| 523 | 521 | ); |
| 524 | 522 | |
| 525 | 523 | $cacheMapArray = $this->cache->getWithSetCallback( |
| 526 | 524 | $cacheKey, |
| 527 | 525 | WANObjectCache::TTL_DAY, |
| 528 | - function ( $cacheMapArray ) use ( $text, $regex, $textHash ) { |
|
| 526 | + function($cacheMapArray) use ($text, $regex, $textHash) { |
|
| 529 | 527 | // Initialize the cache map if not set |
| 530 | - if ( $cacheMapArray === false ) { |
|
| 528 | + if ($cacheMapArray === false) { |
|
| 531 | 529 | $key = 'wikibase.quality.constraints.regex.cache.refresh.init'; |
| 532 | - $this->dataFactory->increment( $key ); |
|
| 530 | + $this->dataFactory->increment($key); |
|
| 533 | 531 | return []; |
| 534 | 532 | } |
| 535 | 533 | |
| 536 | 534 | $key = 'wikibase.quality.constraints.regex.cache.refresh'; |
| 537 | - $this->dataFactory->increment( $key ); |
|
| 538 | - $cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $this->cacheMapSize ); |
|
| 539 | - if ( $cacheMap->has( $textHash ) ) { |
|
| 535 | + $this->dataFactory->increment($key); |
|
| 536 | + $cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $this->cacheMapSize); |
|
| 537 | + if ($cacheMap->has($textHash)) { |
|
| 540 | 538 | $key = 'wikibase.quality.constraints.regex.cache.refresh.hit'; |
| 541 | - $this->dataFactory->increment( $key ); |
|
| 542 | - $cacheMap->get( $textHash ); // ping cache |
|
| 539 | + $this->dataFactory->increment($key); |
|
| 540 | + $cacheMap->get($textHash); // ping cache |
|
| 543 | 541 | } else { |
| 544 | 542 | $key = 'wikibase.quality.constraints.regex.cache.refresh.miss'; |
| 545 | - $this->dataFactory->increment( $key ); |
|
| 543 | + $this->dataFactory->increment($key); |
|
| 546 | 544 | try { |
| 547 | - $matches = $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
| 548 | - } catch ( ConstraintParameterException $e ) { |
|
| 549 | - $matches = $this->serializeConstraintParameterException( $e ); |
|
| 550 | - } catch ( SparqlHelperException $e ) { |
|
| 545 | + $matches = $this->matchesRegularExpressionWithSparql($text, $regex); |
|
| 546 | + } catch (ConstraintParameterException $e) { |
|
| 547 | + $matches = $this->serializeConstraintParameterException($e); |
|
| 548 | + } catch (SparqlHelperException $e) { |
|
| 551 | 549 | // don’t cache this |
| 552 | 550 | return $cacheMap->toArray(); |
| 553 | 551 | } |
@@ -571,42 +569,42 @@ discard block |
||
| 571 | 569 | ] |
| 572 | 570 | ); |
| 573 | 571 | |
| 574 | - if ( isset( $cacheMapArray[$textHash] ) ) { |
|
| 572 | + if (isset($cacheMapArray[$textHash])) { |
|
| 575 | 573 | $key = 'wikibase.quality.constraints.regex.cache.hit'; |
| 576 | - $this->dataFactory->increment( $key ); |
|
| 574 | + $this->dataFactory->increment($key); |
|
| 577 | 575 | $matches = $cacheMapArray[$textHash]; |
| 578 | - if ( is_bool( $matches ) ) { |
|
| 576 | + if (is_bool($matches)) { |
|
| 579 | 577 | return $matches; |
| 580 | - } elseif ( is_array( $matches ) && |
|
| 581 | - $matches['type'] == ConstraintParameterException::class ) { |
|
| 582 | - throw $this->deserializeConstraintParameterException( $matches ); |
|
| 578 | + } elseif (is_array($matches) && |
|
| 579 | + $matches['type'] == ConstraintParameterException::class) { |
|
| 580 | + throw $this->deserializeConstraintParameterException($matches); |
|
| 583 | 581 | } else { |
| 584 | 582 | throw new UnexpectedValueException( |
| 585 | - 'Value of unknown type in object cache (' . |
|
| 586 | - 'cache key: ' . $cacheKey . ', ' . |
|
| 587 | - 'cache map key: ' . $textHash . ', ' . |
|
| 588 | - 'value type: ' . get_debug_type( $matches ) . ')' |
|
| 583 | + 'Value of unknown type in object cache ('. |
|
| 584 | + 'cache key: '.$cacheKey.', '. |
|
| 585 | + 'cache map key: '.$textHash.', '. |
|
| 586 | + 'value type: '.get_debug_type($matches).')' |
|
| 589 | 587 | ); |
| 590 | 588 | } |
| 591 | 589 | } else { |
| 592 | 590 | $key = 'wikibase.quality.constraints.regex.cache.miss'; |
| 593 | - $this->dataFactory->increment( $key ); |
|
| 594 | - return $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
| 591 | + $this->dataFactory->increment($key); |
|
| 592 | + return $this->matchesRegularExpressionWithSparql($text, $regex); |
|
| 595 | 593 | } |
| 596 | 594 | } |
| 597 | 595 | |
| 598 | - private function serializeConstraintParameterException( ConstraintParameterException $cpe ): array { |
|
| 596 | + private function serializeConstraintParameterException(ConstraintParameterException $cpe): array { |
|
| 599 | 597 | return [ |
| 600 | 598 | 'type' => ConstraintParameterException::class, |
| 601 | - 'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ), |
|
| 599 | + 'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()), |
|
| 602 | 600 | ]; |
| 603 | 601 | } |
| 604 | 602 | |
| 605 | - private function deserializeConstraintParameterException( array $serialization ): ConstraintParameterException { |
|
| 603 | + private function deserializeConstraintParameterException(array $serialization): ConstraintParameterException { |
|
| 606 | 604 | $message = $this->violationMessageDeserializer->deserialize( |
| 607 | 605 | $serialization['violationMessage'] |
| 608 | 606 | ); |
| 609 | - return new ConstraintParameterException( $message ); |
|
| 607 | + return new ConstraintParameterException($message); |
|
| 610 | 608 | } |
| 611 | 609 | |
| 612 | 610 | /** |
@@ -616,25 +614,25 @@ discard block |
||
| 616 | 614 | * @throws SparqlHelperException if the query times out or some other error occurs |
| 617 | 615 | * @throws ConstraintParameterException if the $regex is invalid |
| 618 | 616 | */ |
| 619 | - public function matchesRegularExpressionWithSparql( string $text, string $regex ): bool { |
|
| 620 | - $textStringLiteral = $this->stringLiteral( $text ); |
|
| 621 | - $regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' ); |
|
| 617 | + public function matchesRegularExpressionWithSparql(string $text, string $regex): bool { |
|
| 618 | + $textStringLiteral = $this->stringLiteral($text); |
|
| 619 | + $regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$'); |
|
| 622 | 620 | |
| 623 | 621 | $query = <<<EOF |
| 624 | 622 | SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {} |
| 625 | 623 | EOF; |
| 626 | 624 | |
| 627 | - $result = $this->runQuery( $query, $this->primaryEndpoint, false ); |
|
| 625 | + $result = $this->runQuery($query, $this->primaryEndpoint, false); |
|
| 628 | 626 | |
| 629 | 627 | $vars = $result->getArray()['results']['bindings'][0]; |
| 630 | - if ( array_key_exists( 'matches', $vars ) ) { |
|
| 628 | + if (array_key_exists('matches', $vars)) { |
|
| 631 | 629 | // true or false ⇒ regex okay, text matches or not |
| 632 | 630 | return $vars['matches']['value'] === 'true'; |
| 633 | 631 | } else { |
| 634 | 632 | // empty result: regex broken |
| 635 | 633 | throw new ConstraintParameterException( |
| 636 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
| 637 | - ->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
| 634 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
| 635 | + ->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE) |
|
| 638 | 636 | ); |
| 639 | 637 | } |
| 640 | 638 | } |
@@ -642,14 +640,14 @@ discard block |
||
| 642 | 640 | /** |
| 643 | 641 | * Check whether the text content of an error response indicates a query timeout. |
| 644 | 642 | */ |
| 645 | - public function isTimeout( string $responseContent ): bool { |
|
| 646 | - $timeoutRegex = implode( '|', array_map( |
|
| 647 | - static function ( $fqn ) { |
|
| 648 | - return preg_quote( $fqn, '/' ); |
|
| 643 | + public function isTimeout(string $responseContent): bool { |
|
| 644 | + $timeoutRegex = implode('|', array_map( |
|
| 645 | + static function($fqn) { |
|
| 646 | + return preg_quote($fqn, '/'); |
|
| 649 | 647 | }, |
| 650 | 648 | $this->timeoutExceptionClasses |
| 651 | - ) ); |
|
| 652 | - return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent ); |
|
| 649 | + )); |
|
| 650 | + return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent); |
|
| 653 | 651 | } |
| 654 | 652 | |
| 655 | 653 | /** |
@@ -661,17 +659,17 @@ discard block |
||
| 661 | 659 | * @return int|boolean the max-age (in seconds) |
| 662 | 660 | * or a plain boolean if no max-age can be determined |
| 663 | 661 | */ |
| 664 | - public function getCacheMaxAge( array $responseHeaders ) { |
|
| 662 | + public function getCacheMaxAge(array $responseHeaders) { |
|
| 665 | 663 | if ( |
| 666 | - array_key_exists( 'x-cache-status', $responseHeaders ) && |
|
| 667 | - preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] ) |
|
| 664 | + array_key_exists('x-cache-status', $responseHeaders) && |
|
| 665 | + preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0]) |
|
| 668 | 666 | ) { |
| 669 | 667 | $maxage = []; |
| 670 | 668 | if ( |
| 671 | - array_key_exists( 'cache-control', $responseHeaders ) && |
|
| 672 | - preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage ) |
|
| 669 | + array_key_exists('cache-control', $responseHeaders) && |
|
| 670 | + preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage) |
|
| 673 | 671 | ) { |
| 674 | - return intval( $maxage[1] ); |
|
| 672 | + return intval($maxage[1]); |
|
| 675 | 673 | } else { |
| 676 | 674 | return true; |
| 677 | 675 | } |
@@ -692,34 +690,34 @@ discard block |
||
| 692 | 690 | * or SparlHelper::EMPTY_RETRY_AFTER if there is an empty Retry-After |
| 693 | 691 | * or SparlHelper::INVALID_RETRY_AFTER if there is something wrong with the format |
| 694 | 692 | */ |
| 695 | - public function getThrottling( MWHttpRequest $request ) { |
|
| 696 | - $retryAfterValue = $request->getResponseHeader( 'Retry-After' ); |
|
| 697 | - if ( $retryAfterValue === null ) { |
|
| 693 | + public function getThrottling(MWHttpRequest $request) { |
|
| 694 | + $retryAfterValue = $request->getResponseHeader('Retry-After'); |
|
| 695 | + if ($retryAfterValue === null) { |
|
| 698 | 696 | return self::NO_RETRY_AFTER; |
| 699 | 697 | } |
| 700 | 698 | |
| 701 | - $trimmedRetryAfterValue = trim( $retryAfterValue ); |
|
| 702 | - if ( $trimmedRetryAfterValue === '' ) { |
|
| 699 | + $trimmedRetryAfterValue = trim($retryAfterValue); |
|
| 700 | + if ($trimmedRetryAfterValue === '') { |
|
| 703 | 701 | return self::EMPTY_RETRY_AFTER; |
| 704 | 702 | } |
| 705 | 703 | |
| 706 | - if ( is_numeric( $trimmedRetryAfterValue ) ) { |
|
| 707 | - $delaySeconds = (int)$trimmedRetryAfterValue; |
|
| 708 | - if ( $delaySeconds >= 0 ) { |
|
| 709 | - return $this->getTimestampInFuture( new DateInterval( 'PT' . $delaySeconds . 'S' ) ); |
|
| 704 | + if (is_numeric($trimmedRetryAfterValue)) { |
|
| 705 | + $delaySeconds = (int) $trimmedRetryAfterValue; |
|
| 706 | + if ($delaySeconds >= 0) { |
|
| 707 | + return $this->getTimestampInFuture(new DateInterval('PT'.$delaySeconds.'S')); |
|
| 710 | 708 | } |
| 711 | 709 | } else { |
| 712 | - $return = strtotime( $trimmedRetryAfterValue ); |
|
| 713 | - if ( $return !== false ) { |
|
| 714 | - return new ConvertibleTimestamp( $return ); |
|
| 710 | + $return = strtotime($trimmedRetryAfterValue); |
|
| 711 | + if ($return !== false) { |
|
| 712 | + return new ConvertibleTimestamp($return); |
|
| 715 | 713 | } |
| 716 | 714 | } |
| 717 | 715 | return self::INVALID_RETRY_AFTER; |
| 718 | 716 | } |
| 719 | 717 | |
| 720 | - private function getTimestampInFuture( DateInterval $delta ) { |
|
| 718 | + private function getTimestampInFuture(DateInterval $delta) { |
|
| 721 | 719 | $now = new ConvertibleTimestamp(); |
| 722 | - return new ConvertibleTimestamp( $now->timestamp->add( $delta ) ); |
|
| 720 | + return new ConvertibleTimestamp($now->timestamp->add($delta)); |
|
| 723 | 721 | } |
| 724 | 722 | |
| 725 | 723 | /** |
@@ -734,64 +732,63 @@ discard block |
||
| 734 | 732 | * |
| 735 | 733 | * @throws SparqlHelperException if the query times out or some other error occurs |
| 736 | 734 | */ |
| 737 | - protected function runQuery( string $query, string $endpoint, bool $needsPrefixes = true ): CachedQueryResults { |
|
| 738 | - if ( $this->throttlingLock->isLocked( self::EXPIRY_LOCK_ID ) ) { |
|
| 739 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
| 735 | + protected function runQuery(string $query, string $endpoint, bool $needsPrefixes = true): CachedQueryResults { |
|
| 736 | + if ($this->throttlingLock->isLocked(self::EXPIRY_LOCK_ID)) { |
|
| 737 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
| 740 | 738 | throw new TooManySparqlRequestsException(); |
| 741 | 739 | } |
| 742 | 740 | |
| 743 | - if ( $this->sparqlHasWikibaseSupport ) { |
|
| 741 | + if ($this->sparqlHasWikibaseSupport) { |
|
| 744 | 742 | $needsPrefixes = false; |
| 745 | 743 | } |
| 746 | 744 | |
| 747 | - if ( $needsPrefixes ) { |
|
| 748 | - $query = $this->prefixes . $query; |
|
| 745 | + if ($needsPrefixes) { |
|
| 746 | + $query = $this->prefixes.$query; |
|
| 749 | 747 | } |
| 750 | - $query = "#wbqc\n" . $query; |
|
| 748 | + $query = "#wbqc\n".$query; |
|
| 751 | 749 | |
| 752 | - $url = $endpoint . '?' . http_build_query( |
|
| 750 | + $url = $endpoint.'?'.http_build_query( |
|
| 753 | 751 | [ |
| 754 | 752 | 'query' => $query, |
| 755 | 753 | 'format' => 'json', |
| 756 | 754 | 'maxQueryTimeMillis' => $this->maxQueryTimeMillis, |
| 757 | 755 | ], |
| 758 | - '', ini_get( 'arg_separator.output' ), |
|
| 756 | + '', ini_get('arg_separator.output'), |
|
| 759 | 757 | // encode spaces with %20, not + |
| 760 | 758 | PHP_QUERY_RFC3986 |
| 761 | 759 | ); |
| 762 | 760 | |
| 763 | 761 | $options = [ |
| 764 | 762 | 'method' => 'GET', |
| 765 | - 'timeout' => (int)round( ( $this->maxQueryTimeMillis + 1000 ) / 1000 ), |
|
| 763 | + 'timeout' => (int) round(($this->maxQueryTimeMillis + 1000) / 1000), |
|
| 766 | 764 | 'connectTimeout' => 'default', |
| 767 | 765 | 'userAgent' => $this->defaultUserAgent, |
| 768 | 766 | ]; |
| 769 | - $request = $this->requestFactory->create( $url, $options, __METHOD__ ); |
|
| 770 | - $startTime = microtime( true ); |
|
| 767 | + $request = $this->requestFactory->create($url, $options, __METHOD__); |
|
| 768 | + $startTime = microtime(true); |
|
| 771 | 769 | $requestStatus = $request->execute(); |
| 772 | - $endTime = microtime( true ); |
|
| 770 | + $endTime = microtime(true); |
|
| 773 | 771 | $this->dataFactory->timing( |
| 774 | 772 | 'wikibase.quality.constraints.sparql.timing', |
| 775 | - ( $endTime - $startTime ) * 1000 |
|
| 773 | + ($endTime - $startTime) * 1000 |
|
| 776 | 774 | ); |
| 777 | 775 | |
| 778 | - $this->guardAgainstTooManyRequestsError( $request ); |
|
| 776 | + $this->guardAgainstTooManyRequestsError($request); |
|
| 779 | 777 | |
| 780 | - $maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() ); |
|
| 781 | - if ( $maxAge ) { |
|
| 782 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' ); |
|
| 778 | + $maxAge = $this->getCacheMaxAge($request->getResponseHeaders()); |
|
| 779 | + if ($maxAge) { |
|
| 780 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.cached'); |
|
| 783 | 781 | } |
| 784 | 782 | |
| 785 | - if ( $requestStatus->isOK() ) { |
|
| 783 | + if ($requestStatus->isOK()) { |
|
| 786 | 784 | $json = $request->getContent(); |
| 787 | - $jsonStatus = FormatJson::parse( $json, FormatJson::FORCE_ASSOC ); |
|
| 788 | - if ( $jsonStatus->isOK() ) { |
|
| 785 | + $jsonStatus = FormatJson::parse($json, FormatJson::FORCE_ASSOC); |
|
| 786 | + if ($jsonStatus->isOK()) { |
|
| 789 | 787 | return new CachedQueryResults( |
| 790 | 788 | $jsonStatus->getValue(), |
| 791 | 789 | Metadata::ofCachingMetadata( |
| 792 | 790 | $maxAge ? |
| 793 | - CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) : |
|
| 794 | - CachingMetadata::fresh() |
|
| 791 | + CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh() |
|
| 795 | 792 | ) |
| 796 | 793 | ); |
| 797 | 794 | } else { |
@@ -808,9 +805,9 @@ discard block |
||
| 808 | 805 | // fall through to general error handling |
| 809 | 806 | } |
| 810 | 807 | |
| 811 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' ); |
|
| 808 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.error'); |
|
| 812 | 809 | |
| 813 | - if ( $this->isTimeout( $request->getContent() ) ) { |
|
| 810 | + if ($this->isTimeout($request->getContent())) { |
|
| 814 | 811 | $this->dataFactory->increment( |
| 815 | 812 | 'wikibase.quality.constraints.sparql.error.timeout' |
| 816 | 813 | ); |
@@ -825,29 +822,29 @@ discard block |
||
| 825 | 822 | * @param MWHttpRequest $request |
| 826 | 823 | * @throws TooManySparqlRequestsException |
| 827 | 824 | */ |
| 828 | - private function guardAgainstTooManyRequestsError( MWHttpRequest $request ): void { |
|
| 829 | - if ( $request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS ) { |
|
| 825 | + private function guardAgainstTooManyRequestsError(MWHttpRequest $request): void { |
|
| 826 | + if ($request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS) { |
|
| 830 | 827 | return; |
| 831 | 828 | } |
| 832 | 829 | |
| 833 | 830 | $fallbackBlockDuration = $this->sparqlThrottlingFallbackDuration; |
| 834 | 831 | |
| 835 | - if ( $fallbackBlockDuration < 0 ) { |
|
| 836 | - throw new InvalidArgumentException( 'Fallback duration must be positive int but is: ' . |
|
| 837 | - $fallbackBlockDuration ); |
|
| 832 | + if ($fallbackBlockDuration < 0) { |
|
| 833 | + throw new InvalidArgumentException('Fallback duration must be positive int but is: '. |
|
| 834 | + $fallbackBlockDuration); |
|
| 838 | 835 | } |
| 839 | 836 | |
| 840 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
| 841 | - $throttlingUntil = $this->getThrottling( $request ); |
|
| 842 | - if ( !( $throttlingUntil instanceof ConvertibleTimestamp ) ) { |
|
| 843 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid( $request ); |
|
| 837 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
| 838 | + $throttlingUntil = $this->getThrottling($request); |
|
| 839 | + if (!($throttlingUntil instanceof ConvertibleTimestamp)) { |
|
| 840 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid($request); |
|
| 844 | 841 | $this->throttlingLock->lock( |
| 845 | 842 | self::EXPIRY_LOCK_ID, |
| 846 | - $this->getTimestampInFuture( new DateInterval( 'PT' . $fallbackBlockDuration . 'S' ) ) |
|
| 843 | + $this->getTimestampInFuture(new DateInterval('PT'.$fallbackBlockDuration.'S')) |
|
| 847 | 844 | ); |
| 848 | 845 | } else { |
| 849 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent( $throttlingUntil, $request ); |
|
| 850 | - $this->throttlingLock->lock( self::EXPIRY_LOCK_ID, $throttlingUntil ); |
|
| 846 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent($throttlingUntil, $request); |
|
| 847 | + $this->throttlingLock->lock(self::EXPIRY_LOCK_ID, $throttlingUntil); |
|
| 851 | 848 | } |
| 852 | 849 | throw new TooManySparqlRequestsException(); |
| 853 | 850 | } |
@@ -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\Helper; |
| 6 | 6 | |
@@ -28,15 +28,15 @@ discard block |
||
| 28 | 28 | // no parent::__construct() call |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - public function hasType( string $id, array $classes ): CachedBool { |
|
| 32 | - throw new LogicException( 'methods of this class should never be called' ); |
|
| 31 | + public function hasType(string $id, array $classes): CachedBool { |
|
| 32 | + throw new LogicException('methods of this class should never be called'); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function findEntitiesWithSameStatement( |
| 36 | 36 | Statement $statement, |
| 37 | 37 | array $separators |
| 38 | 38 | ): CachedEntityIds { |
| 39 | - throw new LogicException( 'methods of this class should never be called' ); |
|
| 39 | + throw new LogicException('methods of this class should never be called'); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | public function findEntitiesWithSameQualifierOrReference( |
@@ -45,15 +45,15 @@ discard block |
||
| 45 | 45 | string $type, |
| 46 | 46 | bool $ignoreDeprecatedStatements |
| 47 | 47 | ): CachedEntityIds { |
| 48 | - throw new LogicException( 'methods of this class should never be called' ); |
|
| 48 | + throw new LogicException('methods of this class should never be called'); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - public function matchesRegularExpression( string $text, string $regex ): bool { |
|
| 52 | - throw new LogicException( 'methods of this class should never be called' ); |
|
| 51 | + public function matchesRegularExpression(string $text, string $regex): bool { |
|
| 52 | + throw new LogicException('methods of this class should never be called'); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - public function runQuery( string $query, string $endpoint, bool $needsPrefixes = true ): CachedQueryResults { |
|
| 56 | - throw new LogicException( 'methods of this class should never be called' ); |
|
| 55 | + public function runQuery(string $query, string $endpoint, bool $needsPrefixes = true): CachedQueryResults { |
|
| 56 | + throw new LogicException('methods of this class should never be called'); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | } |
@@ -15,12 +15,12 @@ |
||
| 15 | 15 | /** |
| 16 | 16 | * @param DatabaseUpdater $updater |
| 17 | 17 | */ |
| 18 | - public function onLoadExtensionSchemaUpdates( $updater ) { |
|
| 19 | - $dir = dirname( __DIR__ ) . '/sql/'; |
|
| 18 | + public function onLoadExtensionSchemaUpdates($updater) { |
|
| 19 | + $dir = dirname(__DIR__).'/sql/'; |
|
| 20 | 20 | |
| 21 | 21 | $updater->addExtensionTable( |
| 22 | 22 | 'wbqc_constraints', |
| 23 | - $dir . "/{$updater->getDB()->getType()}/tables-generated.sql" |
|
| 23 | + $dir."/{$updater->getDB()->getType()}/tables-generated.sql" |
|
| 24 | 24 | ); |
| 25 | 25 | } |
| 26 | 26 | |
@@ -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\Checker; |
| 6 | 6 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | private ConstraintParameterParser $constraintParameterParser; |
| 24 | 24 | |
| 25 | - public function __construct( ConstraintParameterParser $constraintParameterParser ) { |
|
| 25 | + public function __construct(ConstraintParameterParser $constraintParameterParser) { |
|
| 26 | 26 | $this->constraintParameterParser = $constraintParameterParser; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -64,9 +64,9 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | * @throws ConstraintParameterException |
| 66 | 66 | */ |
| 67 | - public function checkConstraint( Context $context, Constraint $constraint ): CheckResult { |
|
| 68 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
| 69 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED ); |
|
| 67 | + public function checkConstraint(Context $context, Constraint $constraint): CheckResult { |
|
| 68 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
| 69 | + return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | $constraintParameters = $constraint->getConstraintParameters(); |
@@ -77,21 +77,21 @@ discard block |
||
| 77 | 77 | ); |
| 78 | 78 | |
| 79 | 79 | $status = CheckResult::STATUS_VIOLATION; |
| 80 | - $message = ( new ViolationMessage( 'wbqc-violation-message-label-lacking' ) ) |
|
| 81 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ) |
|
| 82 | - ->withLanguages( $languages ); |
|
| 80 | + $message = (new ViolationMessage('wbqc-violation-message-label-lacking')) |
|
| 81 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE) |
|
| 82 | + ->withLanguages($languages); |
|
| 83 | 83 | |
| 84 | 84 | /** @var LabelsProvider $entity */ |
| 85 | 85 | $entity = $context->getEntity(); |
| 86 | 86 | '@phan-var LabelsProvider $entity'; |
| 87 | 87 | $labels = $entity->getLabels(); |
| 88 | 88 | |
| 89 | - if ( $labels->hasTermForLanguage( 'mul' ) ) { |
|
| 89 | + if ($labels->hasTermForLanguage('mul')) { |
|
| 90 | 90 | $message = null; |
| 91 | 91 | $status = CheckResult::STATUS_COMPLIANCE; |
| 92 | 92 | } else { |
| 93 | - foreach ( $languages as $language ) { |
|
| 94 | - if ( $labels->hasTermForLanguage( $language ) ) { |
|
| 93 | + foreach ($languages as $language) { |
|
| 94 | + if ($labels->hasTermForLanguage($language)) { |
|
| 95 | 95 | $message = null; |
| 96 | 96 | $status = CheckResult::STATUS_COMPLIANCE; |
| 97 | 97 | break; |
@@ -99,10 +99,10 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - return new CheckResult( $context, $constraint, $status, $message ); |
|
| 102 | + return new CheckResult($context, $constraint, $status, $message); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - public function checkConstraintParameters( Constraint $constraint ): array { |
|
| 105 | + public function checkConstraintParameters(Constraint $constraint): array { |
|
| 106 | 106 | $constraintParameters = $constraint->getConstraintParameters(); |
| 107 | 107 | $exceptions = []; |
| 108 | 108 | try { |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | $constraintParameters, |
| 111 | 111 | $constraint->getConstraintTypeItemId() |
| 112 | 112 | ); |
| 113 | - } catch ( ConstraintParameterException $e ) { |
|
| 113 | + } catch (ConstraintParameterException $e) { |
|
| 114 | 114 | $exceptions[] = $e; |
| 115 | 115 | } |
| 116 | 116 | return $exceptions; |
@@ -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\Html; |
| 6 | 6 | |
@@ -33,8 +33,8 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @throws InvalidArgumentException |
| 35 | 35 | */ |
| 36 | - public function __construct( $content, bool $isSortable = false ) { |
|
| 37 | - Assert::parameterType( [ 'string', HtmlArmor::class ], $content, '$content' ); |
|
| 36 | + public function __construct($content, bool $isSortable = false) { |
|
| 37 | + Assert::parameterType(['string', HtmlArmor::class], $content, '$content'); |
|
| 38 | 38 | |
| 39 | 39 | $this->content = $content; |
| 40 | 40 | $this->isSortable = $isSortable; |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @return string HTML |
| 45 | 45 | */ |
| 46 | 46 | public function getContent(): string { |
| 47 | - return HtmlArmor::getHtml( $this->content ); |
|
| 47 | + return HtmlArmor::getHtml($this->content); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | public function getIsSortable(): bool { |
@@ -57,13 +57,13 @@ discard block |
||
| 57 | 57 | * @return string HTML |
| 58 | 58 | */ |
| 59 | 59 | public function toHtml(): string { |
| 60 | - $attributes = [ 'role' => 'columnheader button' ]; |
|
| 60 | + $attributes = ['role' => 'columnheader button']; |
|
| 61 | 61 | |
| 62 | - if ( !$this->isSortable ) { |
|
| 62 | + if (!$this->isSortable) { |
|
| 63 | 63 | $attributes['class'] = 'unsortable'; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - return Html::rawElement( 'th', $attributes, $this->getContent() ); |
|
| 66 | + return Html::rawElement('th', $attributes, $this->getContent()); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | } |
@@ -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 | |
@@ -21,26 +21,26 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class ViolationMessageSerializer implements Serializer { |
| 23 | 23 | |
| 24 | - private function abbreviateViolationMessageKey( string $fullMessageKey ): string { |
|
| 25 | - return substr( $fullMessageKey, strlen( ViolationMessage::MESSAGE_KEY_PREFIX ) ); |
|
| 24 | + private function abbreviateViolationMessageKey(string $fullMessageKey): string { |
|
| 25 | + return substr($fullMessageKey, strlen(ViolationMessage::MESSAGE_KEY_PREFIX)); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * @param ViolationMessage $object |
| 30 | 30 | * @return array |
| 31 | 31 | */ |
| 32 | - public function serialize( $object ): array { |
|
| 32 | + public function serialize($object): array { |
|
| 33 | 33 | /** @var ViolationMessage $object */ |
| 34 | - Assert::parameterType( ViolationMessage::class, $object, '$object' ); |
|
| 34 | + Assert::parameterType(ViolationMessage::class, $object, '$object'); |
|
| 35 | 35 | |
| 36 | 36 | $arguments = $object->getArguments(); |
| 37 | 37 | $serializedArguments = []; |
| 38 | - foreach ( $arguments as $argument ) { |
|
| 39 | - $serializedArguments[] = $this->serializeArgument( $argument ); |
|
| 38 | + foreach ($arguments as $argument) { |
|
| 39 | + $serializedArguments[] = $this->serializeArgument($argument); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | return [ |
| 43 | - 'k' => $this->abbreviateViolationMessageKey( $object->getMessageKey() ), |
|
| 43 | + 'k' => $this->abbreviateViolationMessageKey($object->getMessageKey()), |
|
| 44 | 44 | 'a' => $serializedArguments, |
| 45 | 45 | ]; |
| 46 | 46 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * @param array $argument element of ViolationMessage::getArguments() |
| 50 | 50 | * @return array [ 't' => ViolationMessage::TYPE_*, 'v' => serialized value, 'r' => $role ] |
| 51 | 51 | */ |
| 52 | - private function serializeArgument( array $argument ): array { |
|
| 52 | + private function serializeArgument(array $argument): array { |
|
| 53 | 53 | $methods = [ |
| 54 | 54 | ViolationMessage::TYPE_ENTITY_ID => 'serializeEntityId', |
| 55 | 55 | ViolationMessage::TYPE_ENTITY_ID_LIST => 'serializeEntityIdList', |
@@ -71,12 +71,12 @@ discard block |
||
| 71 | 71 | $value = $argument['value']; |
| 72 | 72 | $role = $argument['role']; |
| 73 | 73 | |
| 74 | - if ( array_key_exists( $type, $methods ) ) { |
|
| 74 | + if (array_key_exists($type, $methods)) { |
|
| 75 | 75 | $method = $methods[$type]; |
| 76 | - $serializedValue = $this->$method( $value ); |
|
| 76 | + $serializedValue = $this->$method($value); |
|
| 77 | 77 | } else { |
| 78 | 78 | throw new InvalidArgumentException( |
| 79 | - 'Unknown ViolationMessage argument type ' . $type . '!' |
|
| 79 | + 'Unknown ViolationMessage argument type '.$type.'!' |
|
| 80 | 80 | ); |
| 81 | 81 | } |
| 82 | 82 | |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | * @param string $string any value that shall simply be serialized to itself |
| 94 | 94 | * @return string that same value, unchanged |
| 95 | 95 | */ |
| 96 | - private function serializeStringByIdentity( string $string ): string { |
|
| 96 | + private function serializeStringByIdentity(string $string): string { |
|
| 97 | 97 | return $string; |
| 98 | 98 | } |
| 99 | 99 | |
@@ -101,8 +101,8 @@ discard block |
||
| 101 | 101 | * @param string[] $strings |
| 102 | 102 | * @return string[] |
| 103 | 103 | */ |
| 104 | - private function serializeStringListByIdentity( array $strings ): array { |
|
| 105 | - Assert::parameterElementType( 'string', $strings, '$strings' ); |
|
| 104 | + private function serializeStringListByIdentity(array $strings): array { |
|
| 105 | + Assert::parameterElementType('string', $strings, '$strings'); |
|
| 106 | 106 | return $strings; |
| 107 | 107 | } |
| 108 | 108 | |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @param EntityId $entityId |
| 111 | 111 | * @return string entity ID serialization |
| 112 | 112 | */ |
| 113 | - private function serializeEntityId( EntityId $entityId ): string { |
|
| 113 | + private function serializeEntityId(EntityId $entityId): string { |
|
| 114 | 114 | return $entityId->getSerialization(); |
| 115 | 115 | } |
| 116 | 116 | |
@@ -118,8 +118,8 @@ discard block |
||
| 118 | 118 | * @param EntityId[] $entityIdList |
| 119 | 119 | * @return string[] entity ID serializations |
| 120 | 120 | */ |
| 121 | - private function serializeEntityIdList( array $entityIdList ): array { |
|
| 122 | - return array_map( [ $this, 'serializeEntityId' ], $entityIdList ); |
|
| 121 | + private function serializeEntityIdList(array $entityIdList): array { |
|
| 122 | + return array_map([$this, 'serializeEntityId'], $entityIdList); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -127,10 +127,10 @@ discard block |
||
| 127 | 127 | * @return string entity ID serialization, '::somevalue', or '::novalue' |
| 128 | 128 | * (according to EntityId::PATTERN, entity ID serializations can never begin with two colons) |
| 129 | 129 | */ |
| 130 | - private function serializeItemIdSnakValue( ItemIdSnakValue $value ): string { |
|
| 131 | - switch ( true ) { |
|
| 130 | + private function serializeItemIdSnakValue(ItemIdSnakValue $value): string { |
|
| 131 | + switch (true) { |
|
| 132 | 132 | case $value->isValue(): |
| 133 | - return $this->serializeEntityId( $value->getItemId() ); |
|
| 133 | + return $this->serializeEntityId($value->getItemId()); |
|
| 134 | 134 | case $value->isSomeValue(): |
| 135 | 135 | return '::somevalue'; |
| 136 | 136 | case $value->isNoValue(): |
@@ -148,15 +148,15 @@ discard block |
||
| 148 | 148 | * @param ItemIdSnakValue[] $valueList |
| 149 | 149 | * @return string[] array of entity ID serializations, '::somevalue's or '::novalue's |
| 150 | 150 | */ |
| 151 | - private function serializeItemIdSnakValueList( array $valueList ): array { |
|
| 152 | - return array_map( [ $this, 'serializeItemIdSnakValue' ], $valueList ); |
|
| 151 | + private function serializeItemIdSnakValueList(array $valueList): array { |
|
| 152 | + return array_map([$this, 'serializeItemIdSnakValue'], $valueList); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
| 156 | 156 | * @param DataValue $dataValue |
| 157 | 157 | * @return array the data value in array form |
| 158 | 158 | */ |
| 159 | - private function serializeDataValue( DataValue $dataValue ): array { |
|
| 159 | + private function serializeDataValue(DataValue $dataValue): array { |
|
| 160 | 160 | return $dataValue->toArray(); |
| 161 | 161 | } |
| 162 | 162 | |
@@ -164,8 +164,8 @@ discard block |
||
| 164 | 164 | * @param string $contextType one of the Context::TYPE_* constants |
| 165 | 165 | * @return string the abbreviated context type |
| 166 | 166 | */ |
| 167 | - private function serializeContextType( string $contextType ): string { |
|
| 168 | - switch ( $contextType ) { |
|
| 167 | + private function serializeContextType(string $contextType): string { |
|
| 168 | + switch ($contextType) { |
|
| 169 | 169 | case Context::TYPE_STATEMENT: |
| 170 | 170 | return 's'; |
| 171 | 171 | case Context::TYPE_QUALIFIER: |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | default: |
| 176 | 176 | // @codeCoverageIgnoreStart |
| 177 | 177 | throw new LogicException( |
| 178 | - 'Unknown context type ' . $contextType |
|
| 178 | + 'Unknown context type '.$contextType |
|
| 179 | 179 | ); |
| 180 | 180 | // @codeCoverageIgnoreEnd |
| 181 | 181 | } |
@@ -185,15 +185,15 @@ discard block |
||
| 185 | 185 | * @param string[] $contextTypeList Context::TYPE_* constants |
| 186 | 186 | * @return string[] abbreviated context types |
| 187 | 187 | */ |
| 188 | - private function serializeContextTypeList( array $contextTypeList ): array { |
|
| 189 | - return array_map( [ $this, 'serializeContextType' ], $contextTypeList ); |
|
| 188 | + private function serializeContextTypeList(array $contextTypeList): array { |
|
| 189 | + return array_map([$this, 'serializeContextType'], $contextTypeList); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** |
| 193 | 193 | * @param MultilingualTextValue $text |
| 194 | 194 | * @return mixed {@see MultilingualTextValue::getArrayValue} |
| 195 | 195 | */ |
| 196 | - private function serializeMultilingualText( MultilingualTextValue $text ) { |
|
| 196 | + private function serializeMultilingualText(MultilingualTextValue $text) { |
|
| 197 | 197 | return $text->getArrayValue(); |
| 198 | 198 | } |
| 199 | 199 | |
@@ -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\Cache; |
| 6 | 6 | |
@@ -31,8 +31,8 @@ discard block |
||
| 31 | 31 | * @param int $maxAge The maximum age of the cached value (in seconds). |
| 32 | 32 | * @return self Indication that a value is possibly outdated by up to this many seconds. |
| 33 | 33 | */ |
| 34 | - public static function ofMaximumAgeInSeconds( int $maxAge ): self { |
|
| 35 | - Assert::parameter( $maxAge > 0, '$maxAge', '$maxage > 0' ); |
|
| 34 | + public static function ofMaximumAgeInSeconds(int $maxAge): self { |
|
| 35 | + Assert::parameter($maxAge > 0, '$maxAge', '$maxage > 0'); |
|
| 36 | 36 | $ret = new self; |
| 37 | 37 | $ret->maxAge = $maxAge; |
| 38 | 38 | return $ret; |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | * @param array|null $array As returned by toArray. |
| 44 | 44 | * @return self |
| 45 | 45 | */ |
| 46 | - public static function ofArray( array $array = null ): self { |
|
| 46 | + public static function ofArray(array $array = null): self { |
|
| 47 | 47 | $ret = new self; |
| 48 | - if ( $array !== null ) { |
|
| 48 | + if ($array !== null) { |
|
| 49 | 49 | $ret->maxAge = $array['maximumAgeInSeconds']; |
| 50 | 50 | } |
| 51 | 51 | return $ret; |
@@ -55,11 +55,11 @@ discard block |
||
| 55 | 55 | * @param self[] $metadatas |
| 56 | 56 | * @return self |
| 57 | 57 | */ |
| 58 | - public static function merge( array $metadatas ): self { |
|
| 59 | - Assert::parameterElementType( self::class, $metadatas, '$metadatas' ); |
|
| 58 | + public static function merge(array $metadatas): self { |
|
| 59 | + Assert::parameterElementType(self::class, $metadatas, '$metadatas'); |
|
| 60 | 60 | $ret = new self; |
| 61 | - foreach ( $metadatas as $metadata ) { |
|
| 62 | - $ret->maxAge = max( $ret->maxAge, $metadata->maxAge ); |
|
| 61 | + foreach ($metadatas as $metadata) { |
|
| 62 | + $ret->maxAge = max($ret->maxAge, $metadata->maxAge); |
|
| 63 | 63 | } |
| 64 | 64 | return $ret; |
| 65 | 65 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * For a fresh value, returns 0. |
| 78 | 78 | */ |
| 79 | 79 | public function getMaximumAgeInSeconds(): int { |
| 80 | - if ( is_int( $this->maxAge ) ) { |
|
| 80 | + if (is_int($this->maxAge)) { |
|
| 81 | 81 | return $this->maxAge; |
| 82 | 82 | } else { |
| 83 | 83 | return 0; |
@@ -92,8 +92,7 @@ discard block |
||
| 92 | 92 | return $this->isCached() ? |
| 93 | 93 | [ |
| 94 | 94 | 'maximumAgeInSeconds' => $this->maxAge, |
| 95 | - ] : |
|
| 96 | - null; |
|
| 95 | + ] : null; |
|
| 97 | 96 | } |
| 98 | 97 | |
| 99 | 98 | } |