@@ -6,11 +6,11 @@ |
||
| 6 | 6 | use Wikibase\Repo\WikibaseRepo; |
| 7 | 7 | |
| 8 | 8 | return [ |
| 9 | - WikibaseServices::ENTITY_LOOKUP => function( MediaWikiServices $services ) { |
|
| 9 | + WikibaseServices::ENTITY_LOOKUP => function(MediaWikiServices $services) { |
|
| 10 | 10 | return WikibaseRepo::getDefaultInstance()->getEntityLookup(); |
| 11 | 11 | }, |
| 12 | 12 | |
| 13 | - WikibaseServices::PROPERTY_DATA_TYPE_LOOKUP => function( MediaWikiServices $services ) { |
|
| 13 | + WikibaseServices::PROPERTY_DATA_TYPE_LOOKUP => function(MediaWikiServices $services) { |
|
| 14 | 14 | return WikibaseRepo::getDefaultInstance()->getPropertyDataTypeLookup(); |
| 15 | 15 | }, |
| 16 | 16 | ]; |
@@ -74,17 +74,17 @@ discard block |
||
| 74 | 74 | * |
| 75 | 75 | * @return self |
| 76 | 76 | */ |
| 77 | - public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) { |
|
| 77 | + public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') { |
|
| 78 | 78 | $repo = WikibaseRepo::getDefaultInstance(); |
| 79 | - $helperFactory = $repo->getApiHelperFactory( RequestContext::getMain() ); |
|
| 79 | + $helperFactory = $repo->getApiHelperFactory(RequestContext::getMain()); |
|
| 80 | 80 | $language = $repo->getUserLanguage(); |
| 81 | 81 | |
| 82 | 82 | $entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory(); |
| 83 | - $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $language ); |
|
| 83 | + $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($language); |
|
| 84 | 84 | $formatterOptions = new FormatterOptions(); |
| 85 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
| 85 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
| 86 | 86 | $valueFormatterFactory = $repo->getValueFormatterFactory(); |
| 87 | - $dataValueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
| 87 | + $dataValueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions); |
|
| 88 | 88 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
| 89 | 89 | $violationMessageRenderer = new MultilingualTextViolationMessageRenderer( |
| 90 | 90 | $entityIdHtmlLinkFormatter, |
@@ -124,9 +124,9 @@ discard block |
||
| 124 | 124 | StatementGuidParser $statementGuidParser, |
| 125 | 125 | IBufferingStatsdDataFactory $dataFactory |
| 126 | 126 | ) { |
| 127 | - parent::__construct( $main, $name, $prefix ); |
|
| 127 | + parent::__construct($main, $name, $prefix); |
|
| 128 | 128 | |
| 129 | - $this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
| 129 | + $this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this); |
|
| 130 | 130 | $this->delegatingConstraintChecker = $delegatingConstraintChecker; |
| 131 | 131 | $this->violationMessageRenderer = $violationMessageRenderer; |
| 132 | 132 | $this->statementGuidParser = $statementGuidParser; |
@@ -141,39 +141,39 @@ discard block |
||
| 141 | 141 | $params = $this->extractRequestParams(); |
| 142 | 142 | $result = $this->getResult(); |
| 143 | 143 | |
| 144 | - $propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] ); |
|
| 145 | - $constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] ); |
|
| 144 | + $propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]); |
|
| 145 | + $constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]); |
|
| 146 | 146 | |
| 147 | - $this->checkPropertyIds( $propertyIds, $result ); |
|
| 148 | - $this->checkConstraintIds( $constraintIds, $result ); |
|
| 147 | + $this->checkPropertyIds($propertyIds, $result); |
|
| 148 | + $this->checkConstraintIds($constraintIds, $result); |
|
| 149 | 149 | |
| 150 | - $result->addValue( null, 'success', 1 ); |
|
| 150 | + $result->addValue(null, 'success', 1); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
| 154 | 154 | * @param array|null $propertyIdSerializations |
| 155 | 155 | * @return PropertyId[] |
| 156 | 156 | */ |
| 157 | - private function parsePropertyIds( $propertyIdSerializations ) { |
|
| 158 | - if ( $propertyIdSerializations === null ) { |
|
| 157 | + private function parsePropertyIds($propertyIdSerializations) { |
|
| 158 | + if ($propertyIdSerializations === null) { |
|
| 159 | 159 | return []; |
| 160 | - } elseif ( empty( $propertyIdSerializations ) ) { |
|
| 160 | + } elseif (empty($propertyIdSerializations)) { |
|
| 161 | 161 | $this->apiErrorReporter->dieError( |
| 162 | - 'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.', |
|
| 162 | + 'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.', |
|
| 163 | 163 | 'no-data' |
| 164 | 164 | ); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | return array_map( |
| 168 | - function( $propertyIdSerialization ) { |
|
| 168 | + function($propertyIdSerialization) { |
|
| 169 | 169 | try { |
| 170 | - return new PropertyId( $propertyIdSerialization ); |
|
| 171 | - } catch ( InvalidArgumentException $e ) { |
|
| 170 | + return new PropertyId($propertyIdSerialization); |
|
| 171 | + } catch (InvalidArgumentException $e) { |
|
| 172 | 172 | $this->apiErrorReporter->dieError( |
| 173 | 173 | "Invalid id: $propertyIdSerialization", |
| 174 | 174 | 'invalid-property-id', |
| 175 | 175 | 0, // default argument |
| 176 | - [ self::PARAM_PROPERTY_ID => $propertyIdSerialization ] |
|
| 176 | + [self::PARAM_PROPERTY_ID => $propertyIdSerialization] |
|
| 177 | 177 | ); |
| 178 | 178 | } |
| 179 | 179 | }, |
@@ -185,35 +185,35 @@ discard block |
||
| 185 | 185 | * @param array|null $constraintIds |
| 186 | 186 | * @return string[] |
| 187 | 187 | */ |
| 188 | - private function parseConstraintIds( $constraintIds ) { |
|
| 189 | - if ( $constraintIds === null ) { |
|
| 188 | + private function parseConstraintIds($constraintIds) { |
|
| 189 | + if ($constraintIds === null) { |
|
| 190 | 190 | return []; |
| 191 | - } elseif ( empty( $constraintIds ) ) { |
|
| 191 | + } elseif (empty($constraintIds)) { |
|
| 192 | 192 | $this->apiErrorReporter->dieError( |
| 193 | - 'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.', |
|
| 193 | + 'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.', |
|
| 194 | 194 | 'no-data' |
| 195 | 195 | ); |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | return array_map( |
| 199 | - function( $constraintId ) { |
|
| 199 | + function($constraintId) { |
|
| 200 | 200 | try { |
| 201 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
| 202 | - if ( !$propertyId instanceof PropertyId ) { |
|
| 201 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
| 202 | + if (!$propertyId instanceof PropertyId) { |
|
| 203 | 203 | $this->apiErrorReporter->dieError( |
| 204 | 204 | "Invalid property ID: {$propertyId->getSerialization()}", |
| 205 | 205 | 'invalid-property-id', |
| 206 | 206 | 0, // default argument |
| 207 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
| 207 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
| 208 | 208 | ); |
| 209 | 209 | } |
| 210 | 210 | return $constraintId; |
| 211 | - } catch ( StatementGuidParsingException $e ) { |
|
| 211 | + } catch (StatementGuidParsingException $e) { |
|
| 212 | 212 | $this->apiErrorReporter->dieError( |
| 213 | 213 | "Invalid statement GUID: $constraintId", |
| 214 | 214 | 'invalid-guid', |
| 215 | 215 | 0, // default argument |
| 216 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
| 216 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
| 217 | 217 | ); |
| 218 | 218 | } |
| 219 | 219 | }, |
@@ -225,12 +225,12 @@ discard block |
||
| 225 | 225 | * @param PropertyId[] $propertyIds |
| 226 | 226 | * @param ApiResult $result |
| 227 | 227 | */ |
| 228 | - private function checkPropertyIds( array $propertyIds, ApiResult $result ) { |
|
| 229 | - foreach ( $propertyIds as $propertyId ) { |
|
| 230 | - $result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' ); |
|
| 231 | - $allConstraintExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnPropertyId( $propertyId ); |
|
| 232 | - foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) { |
|
| 233 | - $this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result ); |
|
| 228 | + private function checkPropertyIds(array $propertyIds, ApiResult $result) { |
|
| 229 | + foreach ($propertyIds as $propertyId) { |
|
| 230 | + $result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc'); |
|
| 231 | + $allConstraintExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnPropertyId($propertyId); |
|
| 232 | + foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) { |
|
| 233 | + $this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result); |
|
| 234 | 234 | } |
| 235 | 235 | } |
| 236 | 236 | } |
@@ -239,14 +239,14 @@ discard block |
||
| 239 | 239 | * @param string[] $constraintIds |
| 240 | 240 | * @param ApiResult $result |
| 241 | 241 | */ |
| 242 | - private function checkConstraintIds( array $constraintIds, ApiResult $result ) { |
|
| 243 | - foreach ( $constraintIds as $constraintId ) { |
|
| 244 | - if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) { |
|
| 242 | + private function checkConstraintIds(array $constraintIds, ApiResult $result) { |
|
| 243 | + foreach ($constraintIds as $constraintId) { |
|
| 244 | + if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) { |
|
| 245 | 245 | // already checked as part of checkPropertyIds() |
| 246 | 246 | continue; |
| 247 | 247 | } |
| 248 | - $constraintParameterExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnConstraintId( $constraintId ); |
|
| 249 | - $this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result ); |
|
| 248 | + $constraintParameterExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnConstraintId($constraintId); |
|
| 249 | + $this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result); |
|
| 250 | 250 | } |
| 251 | 251 | } |
| 252 | 252 | |
@@ -254,17 +254,17 @@ discard block |
||
| 254 | 254 | * @param PropertyId $propertyId |
| 255 | 255 | * @return string[] |
| 256 | 256 | */ |
| 257 | - private function getResultPathForPropertyId( PropertyId $propertyId ) { |
|
| 258 | - return [ $this->getModuleName(), $propertyId->getSerialization() ]; |
|
| 257 | + private function getResultPathForPropertyId(PropertyId $propertyId) { |
|
| 258 | + return [$this->getModuleName(), $propertyId->getSerialization()]; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
| 262 | 262 | * @param string $constraintId |
| 263 | 263 | * @return string[] |
| 264 | 264 | */ |
| 265 | - private function getResultPathForConstraintId( $constraintId ) { |
|
| 266 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
| 267 | - return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] ); |
|
| 265 | + private function getResultPathForConstraintId($constraintId) { |
|
| 266 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
| 267 | + return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -274,9 +274,9 @@ discard block |
||
| 274 | 274 | * @param ConstraintParameterException[]|null $constraintParameterExceptions |
| 275 | 275 | * @param ApiResult $result |
| 276 | 276 | */ |
| 277 | - private function addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, ApiResult $result ) { |
|
| 278 | - $path = $this->getResultPathForConstraintId( $constraintId ); |
|
| 279 | - if ( $constraintParameterExceptions === null ) { |
|
| 277 | + private function addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, ApiResult $result) { |
|
| 278 | + $path = $this->getResultPathForConstraintId($constraintId); |
|
| 279 | + if ($constraintParameterExceptions === null) { |
|
| 280 | 280 | $result->addValue( |
| 281 | 281 | $path, |
| 282 | 282 | self::KEY_STATUS, |
@@ -286,12 +286,12 @@ discard block |
||
| 286 | 286 | $result->addValue( |
| 287 | 287 | $path, |
| 288 | 288 | self::KEY_STATUS, |
| 289 | - empty( $constraintParameterExceptions ) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
| 289 | + empty($constraintParameterExceptions) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
| 290 | 290 | ); |
| 291 | 291 | $result->addValue( |
| 292 | 292 | $path, |
| 293 | 293 | self::KEY_PROBLEMS, |
| 294 | - array_map( [ $this, 'formatConstraintParameterException' ], $constraintParameterExceptions ) |
|
| 294 | + array_map([$this, 'formatConstraintParameterException'], $constraintParameterExceptions) |
|
| 295 | 295 | ); |
| 296 | 296 | } |
| 297 | 297 | } |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | * @param ConstraintParameterException $e |
| 303 | 303 | * @return string[] |
| 304 | 304 | */ |
| 305 | - private function formatConstraintParameterException( ConstraintParameterException $e ) { |
|
| 305 | + private function formatConstraintParameterException(ConstraintParameterException $e) { |
|
| 306 | 306 | return [ |
| 307 | 307 | self::KEY_MESSAGE_HTML => $this->violationMessageRenderer->render( |
| 308 | 308 | $e->getViolationMessage() |
@@ -39,13 +39,13 @@ discard block |
||
| 39 | 39 | EntityIdLookup $entityIdLookup, |
| 40 | 40 | RdfVocabulary $rdfVocabulary |
| 41 | 41 | ) { |
| 42 | - parent::__construct( $page, $context ); |
|
| 42 | + parent::__construct($page, $context); |
|
| 43 | 43 | $this->resultsSource = $resultsSource; |
| 44 | 44 | $this->entityIdLookup = $entityIdLookup; |
| 45 | 45 | $this->rdfVocabulary = $rdfVocabulary; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public static function newFromGlobalState( Page $page, IContextSource $context = null ) { |
|
| 48 | + public static function newFromGlobalState(Page $page, IContextSource $context = null) { |
|
| 49 | 49 | $repo = WikibaseRepo::getDefaultInstance(); |
| 50 | 50 | |
| 51 | 51 | return new static( |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | * @param string $guid |
| 93 | 93 | * @return string |
| 94 | 94 | */ |
| 95 | - private function cleanupGuid( $guid ) { |
|
| 96 | - return preg_replace( '/[^\w-]/', '-', $guid ); |
|
| 95 | + private function cleanupGuid($guid) { |
|
| 96 | + return preg_replace('/[^\w-]/', '-', $guid); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
@@ -105,51 +105,51 @@ discard block |
||
| 105 | 105 | $response = $this->getRequest()->response(); |
| 106 | 106 | $this->getOutput()->disable(); |
| 107 | 107 | |
| 108 | - if ( !$this->resultsSource instanceof CachingResultsSource ) { |
|
| 108 | + if (!$this->resultsSource instanceof CachingResultsSource) { |
|
| 109 | 109 | // TODO: make configurable whether only cached results are returned |
| 110 | - $response->statusHeader( 501 ); // Not Implemented |
|
| 110 | + $response->statusHeader(501); // Not Implemented |
|
| 111 | 111 | return null; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - $entityId = $this->entityIdLookup->getEntityIdForTitle( $this->getTitle() ); |
|
| 115 | - if ( $entityId === null ) { |
|
| 116 | - $response->statusHeader( 404 ); // Not Found |
|
| 114 | + $entityId = $this->entityIdLookup->getEntityIdForTitle($this->getTitle()); |
|
| 115 | + if ($entityId === null) { |
|
| 116 | + $response->statusHeader(404); // Not Found |
|
| 117 | 117 | return null; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - $results = $this->resultsSource->getStoredResults( $entityId ); |
|
| 121 | - if ( $results === null ) { |
|
| 122 | - $response->statusHeader( 204 ); // No Content |
|
| 120 | + $results = $this->resultsSource->getStoredResults($entityId); |
|
| 121 | + if ($results === null) { |
|
| 122 | + $response->statusHeader(204); // No Content |
|
| 123 | 123 | return null; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | $format = 'ttl'; // TODO: make format an option |
| 127 | 127 | |
| 128 | 128 | $writerFactory = new RdfWriterFactory(); |
| 129 | - $formatName = $writerFactory->getFormatName( $format ); |
|
| 130 | - $contentType = $writerFactory->getMimeTypes( $formatName )[0]; |
|
| 129 | + $formatName = $writerFactory->getFormatName($format); |
|
| 130 | + $contentType = $writerFactory->getMimeTypes($formatName)[0]; |
|
| 131 | 131 | |
| 132 | - $response->header( "Content-Type: $contentType; charset=UTF-8" ); |
|
| 132 | + $response->header("Content-Type: $contentType; charset=UTF-8"); |
|
| 133 | 133 | |
| 134 | - $writer = $writerFactory->getWriter( $formatName ); |
|
| 135 | - foreach ( [ RdfVocabulary::NS_STATEMENT, RdfVocabulary::NS_ONTOLOGY ] as $ns ) { |
|
| 136 | - $writer->prefix( $ns, $this->rdfVocabulary->getNamespaceURI( $ns ) ); |
|
| 134 | + $writer = $writerFactory->getWriter($formatName); |
|
| 135 | + foreach ([RdfVocabulary::NS_STATEMENT, RdfVocabulary::NS_ONTOLOGY] as $ns) { |
|
| 136 | + $writer->prefix($ns, $this->rdfVocabulary->getNamespaceURI($ns)); |
|
| 137 | 137 | } |
| 138 | 138 | $writer->start(); |
| 139 | 139 | |
| 140 | - foreach ( $results->getArray() as $checkResult ) { |
|
| 141 | - if ( $checkResult instanceof NullResult ) { |
|
| 140 | + foreach ($results->getArray() as $checkResult) { |
|
| 141 | + if ($checkResult instanceof NullResult) { |
|
| 142 | 142 | continue; |
| 143 | 143 | } |
| 144 | - if ( $checkResult->getStatus() === CheckResult::STATUS_BAD_PARAMETERS ) { |
|
| 144 | + if ($checkResult->getStatus() === CheckResult::STATUS_BAD_PARAMETERS) { |
|
| 145 | 145 | continue; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - $writer->about( RdfVocabulary::NS_STATEMENT, |
|
| 149 | - $this->cleanupGuid( $checkResult->getContextCursor()->getStatementGuid() ) ) |
|
| 150 | - ->say( RdfVocabulary::NS_ONTOLOGY, 'hasViolationForConstraint' ) |
|
| 151 | - ->is( RdfVocabulary::NS_STATEMENT, |
|
| 152 | - $this->cleanupGuid( $checkResult->getConstraint()->getConstraintId() ) ); |
|
| 148 | + $writer->about(RdfVocabulary::NS_STATEMENT, |
|
| 149 | + $this->cleanupGuid($checkResult->getContextCursor()->getStatementGuid())) |
|
| 150 | + ->say(RdfVocabulary::NS_ONTOLOGY, 'hasViolationForConstraint') |
|
| 151 | + ->is(RdfVocabulary::NS_STATEMENT, |
|
| 152 | + $this->cleanupGuid($checkResult->getConstraint()->getConstraintId())); |
|
| 153 | 153 | } |
| 154 | 154 | $writer->finish(); |
| 155 | 155 | echo $writer->drain(); |
@@ -79,19 +79,19 @@ discard block |
||
| 79 | 79 | * |
| 80 | 80 | * @return self |
| 81 | 81 | */ |
| 82 | - public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) { |
|
| 82 | + public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') { |
|
| 83 | 83 | $repo = WikibaseRepo::getDefaultInstance(); |
| 84 | 84 | |
| 85 | 85 | $language = $repo->getUserLanguage(); |
| 86 | 86 | $formatterOptions = new FormatterOptions(); |
| 87 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
| 87 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
| 88 | 88 | $valueFormatterFactory = $repo->getValueFormatterFactory(); |
| 89 | - $valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
| 89 | + $valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions); |
|
| 90 | 90 | |
| 91 | 91 | $entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory(); |
| 92 | - $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $language ); |
|
| 92 | + $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($language); |
|
| 93 | 93 | $entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory(); |
| 94 | - $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $language ); |
|
| 94 | + $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($language); |
|
| 95 | 95 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
| 96 | 96 | $dataFactory = MediaWikiServices::getInstance()->getStatsdDataFactory(); |
| 97 | 97 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | $prefix, |
| 114 | 114 | $repo->getEntityIdParser(), |
| 115 | 115 | $repo->getStatementGuidValidator(), |
| 116 | - $repo->getApiHelperFactory( RequestContext::getMain() ), |
|
| 116 | + $repo->getApiHelperFactory(RequestContext::getMain()), |
|
| 117 | 117 | $resultsSource, |
| 118 | 118 | $checkResultsRenderer, |
| 119 | 119 | $dataFactory |
@@ -142,11 +142,11 @@ discard block |
||
| 142 | 142 | CheckResultsRenderer $checkResultsRenderer, |
| 143 | 143 | IBufferingStatsdDataFactory $dataFactory |
| 144 | 144 | ) { |
| 145 | - parent::__construct( $main, $name, $prefix ); |
|
| 145 | + parent::__construct($main, $name, $prefix); |
|
| 146 | 146 | $this->entityIdParser = $entityIdParser; |
| 147 | 147 | $this->statementGuidValidator = $statementGuidValidator; |
| 148 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
| 149 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
| 148 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
| 149 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
| 150 | 150 | $this->resultsSource = $resultsSource; |
| 151 | 151 | $this->checkResultsRenderer = $checkResultsRenderer; |
| 152 | 152 | $this->dataFactory = $dataFactory; |
@@ -162,9 +162,9 @@ discard block |
||
| 162 | 162 | |
| 163 | 163 | $params = $this->extractRequestParams(); |
| 164 | 164 | |
| 165 | - $this->validateParameters( $params ); |
|
| 166 | - $entityIds = $this->parseEntityIds( $params ); |
|
| 167 | - $claimIds = $this->parseClaimIds( $params ); |
|
| 165 | + $this->validateParameters($params); |
|
| 166 | + $entityIds = $this->parseEntityIds($params); |
|
| 167 | + $claimIds = $this->parseClaimIds($params); |
|
| 168 | 168 | $constraintIDs = $params[self::PARAM_CONSTRAINT_ID]; |
| 169 | 169 | $statuses = $params[self::PARAM_STATUS]; |
| 170 | 170 | |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | ) |
| 181 | 181 | )->getArray() |
| 182 | 182 | ); |
| 183 | - $this->resultBuilder->markSuccess( 1 ); |
|
| 183 | + $this->resultBuilder->markSuccess(1); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -188,24 +188,24 @@ discard block |
||
| 188 | 188 | * |
| 189 | 189 | * @return EntityId[] |
| 190 | 190 | */ |
| 191 | - private function parseEntityIds( array $params ) { |
|
| 191 | + private function parseEntityIds(array $params) { |
|
| 192 | 192 | $ids = $params[self::PARAM_ID]; |
| 193 | 193 | |
| 194 | - if ( $ids === null ) { |
|
| 194 | + if ($ids === null) { |
|
| 195 | 195 | return []; |
| 196 | - } elseif ( $ids === [] ) { |
|
| 196 | + } elseif ($ids === []) { |
|
| 197 | 197 | $this->errorReporter->dieError( |
| 198 | - 'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
| 198 | + 'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - return array_map( function ( $id ) { |
|
| 201 | + return array_map(function($id) { |
|
| 202 | 202 | try { |
| 203 | - return $this->entityIdParser->parse( $id ); |
|
| 204 | - } catch ( EntityIdParsingException $e ) { |
|
| 203 | + return $this->entityIdParser->parse($id); |
|
| 204 | + } catch (EntityIdParsingException $e) { |
|
| 205 | 205 | $this->errorReporter->dieError( |
| 206 | - "Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] ); |
|
| 206 | + "Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] ); |
|
| 207 | 207 | } |
| 208 | - }, $ids ); |
|
| 208 | + }, $ids); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
@@ -213,35 +213,35 @@ discard block |
||
| 213 | 213 | * |
| 214 | 214 | * @return string[] |
| 215 | 215 | */ |
| 216 | - private function parseClaimIds( array $params ) { |
|
| 216 | + private function parseClaimIds(array $params) { |
|
| 217 | 217 | $ids = $params[self::PARAM_CLAIM_ID]; |
| 218 | 218 | |
| 219 | - if ( $ids === null ) { |
|
| 219 | + if ($ids === null) { |
|
| 220 | 220 | return []; |
| 221 | - } elseif ( $ids === [] ) { |
|
| 221 | + } elseif ($ids === []) { |
|
| 222 | 222 | $this->errorReporter->dieError( |
| 223 | - 'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
| 223 | + 'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - foreach ( $ids as $id ) { |
|
| 227 | - if ( !$this->statementGuidValidator->validate( $id ) ) { |
|
| 226 | + foreach ($ids as $id) { |
|
| 227 | + if (!$this->statementGuidValidator->validate($id)) { |
|
| 228 | 228 | $this->errorReporter->dieError( |
| 229 | - "Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] ); |
|
| 229 | + "Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] ); |
|
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | return $ids; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - private function validateParameters( array $params ) { |
|
| 237 | - if ( $params[self::PARAM_CONSTRAINT_ID] !== null |
|
| 238 | - && empty( $params[self::PARAM_CONSTRAINT_ID] ) |
|
| 236 | + private function validateParameters(array $params) { |
|
| 237 | + if ($params[self::PARAM_CONSTRAINT_ID] !== null |
|
| 238 | + && empty($params[self::PARAM_CONSTRAINT_ID]) |
|
| 239 | 239 | ) { |
| 240 | 240 | $paramConstraintId = self::PARAM_CONSTRAINT_ID; |
| 241 | 241 | $this->errorReporter->dieError( |
| 242 | 242 | "If $paramConstraintId is specified, it must be nonempty.", 'no-data' ); |
| 243 | 243 | } |
| 244 | - if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) { |
|
| 244 | + if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) { |
|
| 245 | 245 | $paramId = self::PARAM_ID; |
| 246 | 246 | $paramClaimId = self::PARAM_CLAIM_ID; |
| 247 | 247 | $this->errorReporter->dieError( |
@@ -281,11 +281,11 @@ discard block |
||
| 281 | 281 | ], |
| 282 | 282 | ApiBase::PARAM_ISMULTI => true, |
| 283 | 283 | ApiBase::PARAM_ALL => true, |
| 284 | - ApiBase::PARAM_DFLT => implode( '|', [ |
|
| 284 | + ApiBase::PARAM_DFLT => implode('|', [ |
|
| 285 | 285 | CheckResult::STATUS_VIOLATION, |
| 286 | 286 | CheckResult::STATUS_WARNING, |
| 287 | 287 | CheckResult::STATUS_BAD_PARAMETERS, |
| 288 | - ] ), |
|
| 288 | + ]), |
|
| 289 | 289 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [], |
| 290 | 290 | ], |
| 291 | 291 | ]; |
@@ -35,124 +35,124 @@ discard block |
||
| 35 | 35 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\ValueTypeChecker; |
| 36 | 36 | |
| 37 | 37 | return [ |
| 38 | - ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => function( MediaWikiServices $services ) { |
|
| 38 | + ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => function(MediaWikiServices $services) { |
|
| 39 | 39 | return new ConflictsWithChecker( |
| 40 | - WikibaseServices::getEntityLookup( $services ), |
|
| 41 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 42 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
| 40 | + WikibaseServices::getEntityLookup($services), |
|
| 41 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 42 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
| 43 | 43 | ); |
| 44 | 44 | }, |
| 45 | 45 | |
| 46 | - ConstraintCheckerServices::ITEM_CHECKER => function( MediaWikiServices $services ) { |
|
| 46 | + ConstraintCheckerServices::ITEM_CHECKER => function(MediaWikiServices $services) { |
|
| 47 | 47 | return new ItemChecker( |
| 48 | - WikibaseServices::getEntityLookup( $services ), |
|
| 49 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 50 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
| 48 | + WikibaseServices::getEntityLookup($services), |
|
| 49 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 50 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
| 51 | 51 | ); |
| 52 | 52 | }, |
| 53 | 53 | |
| 54 | - ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => function( MediaWikiServices $services ) { |
|
| 54 | + ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => function(MediaWikiServices $services) { |
|
| 55 | 55 | return new TargetRequiredClaimChecker( |
| 56 | - WikibaseServices::getEntityLookup( $services ), |
|
| 57 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 58 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
| 56 | + WikibaseServices::getEntityLookup($services), |
|
| 57 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 58 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
| 59 | 59 | ); |
| 60 | 60 | }, |
| 61 | 61 | |
| 62 | - ConstraintCheckerServices::SYMMETRIC_CHECKER => function( MediaWikiServices $services ) { |
|
| 62 | + ConstraintCheckerServices::SYMMETRIC_CHECKER => function(MediaWikiServices $services) { |
|
| 63 | 63 | return new SymmetricChecker( |
| 64 | - WikibaseServices::getEntityLookup( $services ), |
|
| 65 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
| 64 | + WikibaseServices::getEntityLookup($services), |
|
| 65 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
| 66 | 66 | ); |
| 67 | 67 | }, |
| 68 | 68 | |
| 69 | - ConstraintCheckerServices::INVERSE_CHECKER => function( MediaWikiServices $services ) { |
|
| 69 | + ConstraintCheckerServices::INVERSE_CHECKER => function(MediaWikiServices $services) { |
|
| 70 | 70 | return new InverseChecker( |
| 71 | - WikibaseServices::getEntityLookup( $services ), |
|
| 72 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 73 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
| 71 | + WikibaseServices::getEntityLookup($services), |
|
| 72 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 73 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
| 74 | 74 | ); |
| 75 | 75 | }, |
| 76 | 76 | |
| 77 | - ConstraintCheckerServices::QUALIFIER_CHECKER => function( MediaWikiServices $services ) { |
|
| 77 | + ConstraintCheckerServices::QUALIFIER_CHECKER => function(MediaWikiServices $services) { |
|
| 78 | 78 | return new QualifierChecker(); |
| 79 | 79 | }, |
| 80 | 80 | |
| 81 | - ConstraintCheckerServices::QUALIFIERS_CHECKER => function( MediaWikiServices $services ) { |
|
| 81 | + ConstraintCheckerServices::QUALIFIERS_CHECKER => function(MediaWikiServices $services) { |
|
| 82 | 82 | return new QualifiersChecker( |
| 83 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
| 83 | + ConstraintsServices::getConstraintParameterParser($services) |
|
| 84 | 84 | ); |
| 85 | 85 | }, |
| 86 | 86 | |
| 87 | - ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => function( MediaWikiServices $services ) { |
|
| 87 | + ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => function(MediaWikiServices $services) { |
|
| 88 | 88 | return new MandatoryQualifiersChecker( |
| 89 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
| 89 | + ConstraintsServices::getConstraintParameterParser($services) |
|
| 90 | 90 | ); |
| 91 | 91 | }, |
| 92 | 92 | |
| 93 | - ConstraintCheckerServices::RANGE_CHECKER => function( MediaWikiServices $services ) { |
|
| 93 | + ConstraintCheckerServices::RANGE_CHECKER => function(MediaWikiServices $services) { |
|
| 94 | 94 | return new RangeChecker( |
| 95 | - WikibaseServices::getPropertyDataTypeLookup( $services ), |
|
| 96 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 97 | - ConstraintsServices::getRangeCheckerHelper( $services ) |
|
| 95 | + WikibaseServices::getPropertyDataTypeLookup($services), |
|
| 96 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 97 | + ConstraintsServices::getRangeCheckerHelper($services) |
|
| 98 | 98 | ); |
| 99 | 99 | }, |
| 100 | 100 | |
| 101 | - ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => function( MediaWikiServices $services ) { |
|
| 101 | + ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => function(MediaWikiServices $services) { |
|
| 102 | 102 | return new DiffWithinRangeChecker( |
| 103 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 104 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
| 103 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 104 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
| 105 | 105 | $services->getMainConfig() |
| 106 | 106 | ); |
| 107 | 107 | }, |
| 108 | 108 | |
| 109 | - ConstraintCheckerServices::TYPE_CHECKER => function( MediaWikiServices $services ) { |
|
| 109 | + ConstraintCheckerServices::TYPE_CHECKER => function(MediaWikiServices $services) { |
|
| 110 | 110 | return new TypeChecker( |
| 111 | - WikibaseServices::getEntityLookup( $services ), |
|
| 112 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 113 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
| 111 | + WikibaseServices::getEntityLookup($services), |
|
| 112 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 113 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
| 114 | 114 | $services->getMainConfig() |
| 115 | 115 | ); |
| 116 | 116 | }, |
| 117 | 117 | |
| 118 | - ConstraintCheckerServices::VALUE_TYPE_CHECKER => function( MediaWikiServices $services ) { |
|
| 118 | + ConstraintCheckerServices::VALUE_TYPE_CHECKER => function(MediaWikiServices $services) { |
|
| 119 | 119 | return new ValueTypeChecker( |
| 120 | - WikibaseServices::getEntityLookup( $services ), |
|
| 121 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 122 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
| 120 | + WikibaseServices::getEntityLookup($services), |
|
| 121 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 122 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
| 123 | 123 | $services->getMainConfig() |
| 124 | 124 | ); |
| 125 | 125 | }, |
| 126 | 126 | |
| 127 | - ConstraintCheckerServices::SINGLE_VALUE_CHECKER => function( MediaWikiServices $services ) { |
|
| 127 | + ConstraintCheckerServices::SINGLE_VALUE_CHECKER => function(MediaWikiServices $services) { |
|
| 128 | 128 | return new SingleValueChecker( |
| 129 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
| 129 | + ConstraintsServices::getConstraintParameterParser($services) |
|
| 130 | 130 | ); |
| 131 | 131 | }, |
| 132 | 132 | |
| 133 | - ConstraintCheckerServices::MULTI_VALUE_CHECKER => function( MediaWikiServices $services ) { |
|
| 133 | + ConstraintCheckerServices::MULTI_VALUE_CHECKER => function(MediaWikiServices $services) { |
|
| 134 | 134 | return new MultiValueChecker( |
| 135 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
| 135 | + ConstraintsServices::getConstraintParameterParser($services) |
|
| 136 | 136 | ); |
| 137 | 137 | }, |
| 138 | 138 | |
| 139 | - ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => function( MediaWikiServices $services ) { |
|
| 139 | + ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => function(MediaWikiServices $services) { |
|
| 140 | 140 | // TODO return a different, dummy implementation if SPARQL is not available |
| 141 | 141 | return new UniqueValueChecker( |
| 142 | - ConstraintsServices::getSparqlHelper( $services ) |
|
| 142 | + ConstraintsServices::getSparqlHelper($services) |
|
| 143 | 143 | ); |
| 144 | 144 | }, |
| 145 | 145 | |
| 146 | - ConstraintCheckerServices::FORMAT_CHECKER => function( MediaWikiServices $services ) { |
|
| 146 | + ConstraintCheckerServices::FORMAT_CHECKER => function(MediaWikiServices $services) { |
|
| 147 | 147 | // TODO return a different, dummy implementation if SPARQL is not available |
| 148 | 148 | return new FormatChecker( |
| 149 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 149 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 150 | 150 | $services->getMainConfig(), |
| 151 | - ConstraintsServices::getSparqlHelper( $services ) |
|
| 151 | + ConstraintsServices::getSparqlHelper($services) |
|
| 152 | 152 | ); |
| 153 | 153 | }, |
| 154 | 154 | |
| 155 | - ConstraintCheckerServices::COMMONS_LINK_CHECKER => function( MediaWikiServices $services ) { |
|
| 155 | + ConstraintCheckerServices::COMMONS_LINK_CHECKER => function(MediaWikiServices $services) { |
|
| 156 | 156 | // TODO return different implementations for: |
| 157 | 157 | // - Wikimedia production ('commonswiki' database available) |
| 158 | 158 | // - InstantCommons wikis |
@@ -160,76 +160,76 @@ discard block |
||
| 160 | 160 | // - … |
| 161 | 161 | // ? (see also T169538) |
| 162 | 162 | return new CommonsLinkChecker( |
| 163 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 163 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 164 | 164 | $services->getTitleParser() |
| 165 | 165 | ); |
| 166 | 166 | }, |
| 167 | 167 | |
| 168 | - ConstraintCheckerServices::ONE_OF_CHECKER => function( MediaWikiServices $services ) { |
|
| 168 | + ConstraintCheckerServices::ONE_OF_CHECKER => function(MediaWikiServices $services) { |
|
| 169 | 169 | return new OneOfChecker( |
| 170 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
| 170 | + ConstraintsServices::getConstraintParameterParser($services) |
|
| 171 | 171 | ); |
| 172 | 172 | }, |
| 173 | 173 | |
| 174 | - ConstraintCheckerServices::VALUE_ONLY_CHECKER => function( MediaWikiServices $services ) { |
|
| 174 | + ConstraintCheckerServices::VALUE_ONLY_CHECKER => function(MediaWikiServices $services) { |
|
| 175 | 175 | return new ValueOnlyChecker(); |
| 176 | 176 | }, |
| 177 | 177 | |
| 178 | - ConstraintCheckerServices::REFERENCE_CHECKER => function( MediaWikiServices $services ) { |
|
| 178 | + ConstraintCheckerServices::REFERENCE_CHECKER => function(MediaWikiServices $services) { |
|
| 179 | 179 | return new ReferenceChecker(); |
| 180 | 180 | }, |
| 181 | 181 | |
| 182 | - ConstraintCheckerServices::NO_BOUNDS_CHECKER => function( MediaWikiServices $services ) { |
|
| 182 | + ConstraintCheckerServices::NO_BOUNDS_CHECKER => function(MediaWikiServices $services) { |
|
| 183 | 183 | return new NoBoundsChecker(); |
| 184 | 184 | }, |
| 185 | 185 | |
| 186 | - ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => function( MediaWikiServices $services ) { |
|
| 186 | + ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => function(MediaWikiServices $services) { |
|
| 187 | 187 | // TODO in the future, get UnitConverter from $services? |
| 188 | 188 | $repo = WikibaseRepo::getDefaultInstance(); |
| 189 | 189 | $unitConverter = $repo->getUnitConverter(); |
| 190 | 190 | |
| 191 | 191 | return new AllowedUnitsChecker( |
| 192 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 192 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 193 | 193 | $unitConverter |
| 194 | 194 | ); |
| 195 | 195 | }, |
| 196 | 196 | |
| 197 | - ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => function( MediaWikiServices $services ) { |
|
| 197 | + ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => function(MediaWikiServices $services) { |
|
| 198 | 198 | return new SingleBestValueChecker( |
| 199 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
| 199 | + ConstraintsServices::getConstraintParameterParser($services) |
|
| 200 | 200 | ); |
| 201 | 201 | }, |
| 202 | 202 | |
| 203 | - ConstraintCheckerServices::ENTITY_TYPE_CHECKER => function( MediaWikiServices $services ) { |
|
| 203 | + ConstraintCheckerServices::ENTITY_TYPE_CHECKER => function(MediaWikiServices $services) { |
|
| 204 | 204 | return new EntityTypeChecker( |
| 205 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
| 205 | + ConstraintsServices::getConstraintParameterParser($services) |
|
| 206 | 206 | ); |
| 207 | 207 | }, |
| 208 | 208 | |
| 209 | - ConstraintCheckerServices::NONE_OF_CHECKER => function( MediaWikiServices $services ) { |
|
| 209 | + ConstraintCheckerServices::NONE_OF_CHECKER => function(MediaWikiServices $services) { |
|
| 210 | 210 | return new NoneOfChecker( |
| 211 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
| 211 | + ConstraintsServices::getConstraintParameterParser($services) |
|
| 212 | 212 | ); |
| 213 | 213 | }, |
| 214 | 214 | |
| 215 | - ConstraintCheckerServices::INTEGER_CHECKER => function( MediaWikiServices $services ) { |
|
| 215 | + ConstraintCheckerServices::INTEGER_CHECKER => function(MediaWikiServices $services) { |
|
| 216 | 216 | return new IntegerChecker(); |
| 217 | 217 | }, |
| 218 | 218 | |
| 219 | - ConstraintCheckerServices::CITATION_NEEDED_CHECKER => function( MediaWikiServices $services ) { |
|
| 219 | + ConstraintCheckerServices::CITATION_NEEDED_CHECKER => function(MediaWikiServices $services) { |
|
| 220 | 220 | return new CitationNeededChecker(); |
| 221 | 221 | }, |
| 222 | 222 | |
| 223 | - ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => function( MediaWikiServices $services ) { |
|
| 223 | + ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => function(MediaWikiServices $services) { |
|
| 224 | 224 | return new PropertyScopeChecker( |
| 225 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
| 225 | + ConstraintsServices::getConstraintParameterParser($services) |
|
| 226 | 226 | ); |
| 227 | 227 | }, |
| 228 | 228 | |
| 229 | - ConstraintCheckerServices::CONTEMPORARY_CHECKER => function( MediaWikiServices $services ) { |
|
| 229 | + ConstraintCheckerServices::CONTEMPORARY_CHECKER => function(MediaWikiServices $services) { |
|
| 230 | 230 | return new ContemporaryChecker( |
| 231 | - WikibaseServices::getEntityLookup( $services ), |
|
| 232 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
| 231 | + WikibaseServices::getEntityLookup($services), |
|
| 232 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
| 233 | 233 | $services->getMainConfig() |
| 234 | 234 | ); |
| 235 | 235 | }, |
@@ -40,10 +40,10 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @throws InvalidArgumentException |
| 42 | 42 | */ |
| 43 | - public function __construct( $content, $isSortable = false, $isRawContent = false ) { |
|
| 44 | - Assert::parameterType( 'string', $content, '$content' ); |
|
| 45 | - Assert::parameterType( 'boolean', $isSortable, '$isSortable' ); |
|
| 46 | - Assert::parameterType( 'boolean', $isRawContent, '$isRawContent' ); |
|
| 43 | + public function __construct($content, $isSortable = false, $isRawContent = false) { |
|
| 44 | + Assert::parameterType('string', $content, '$content'); |
|
| 45 | + Assert::parameterType('boolean', $isSortable, '$isSortable'); |
|
| 46 | + Assert::parameterType('boolean', $isRawContent, '$isRawContent'); |
|
| 47 | 47 | |
| 48 | 48 | $this->content = $content; |
| 49 | 49 | $this->isSortable = $isSortable; |
@@ -70,18 +70,18 @@ discard block |
||
| 70 | 70 | * @return string HTML |
| 71 | 71 | */ |
| 72 | 72 | public function toHtml() { |
| 73 | - $attributes = [ 'role' => 'columnheader button' ]; |
|
| 73 | + $attributes = ['role' => 'columnheader button']; |
|
| 74 | 74 | |
| 75 | - if ( !$this->isSortable ) { |
|
| 75 | + if (!$this->isSortable) { |
|
| 76 | 76 | $attributes['class'] = 'unsortable'; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | $content = $this->content; |
| 80 | - if ( !$this->isRawContent ) { |
|
| 81 | - $content = htmlspecialchars( $this->content ); |
|
| 80 | + if (!$this->isRawContent) { |
|
| 81 | + $content = htmlspecialchars($this->content); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - return Html::rawElement( 'th', $attributes, $content ); |
|
| 84 | + return Html::rawElement('th', $attributes, $content); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | } |
@@ -38,9 +38,9 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @throws InvalidArgumentException |
| 40 | 40 | */ |
| 41 | - public function __construct( $content, array $attributes = [], $isRawContent = false ) { |
|
| 42 | - Assert::parameterType( 'string', $content, '$content' ); |
|
| 43 | - Assert::parameterType( 'boolean', $isRawContent, '$isRawContent' ); |
|
| 41 | + public function __construct($content, array $attributes = [], $isRawContent = false) { |
|
| 42 | + Assert::parameterType('string', $content, '$content'); |
|
| 43 | + Assert::parameterType('boolean', $isRawContent, '$isRawContent'); |
|
| 44 | 44 | |
| 45 | 45 | $this->content = $content; |
| 46 | 46 | $this->attributes = $attributes; |
@@ -65,10 +65,10 @@ discard block |
||
| 65 | 65 | * @return string HTML |
| 66 | 66 | */ |
| 67 | 67 | public function toHtml() { |
| 68 | - if ( $this->isRawContent ) { |
|
| 69 | - return Html::rawElement( 'td', $this->getAttributes(), $this->content ); |
|
| 68 | + if ($this->isRawContent) { |
|
| 69 | + return Html::rawElement('td', $this->getAttributes(), $this->content); |
|
| 70 | 70 | } else { |
| 71 | - return Html::element( 'td', $this->getAttributes(), $this->content ); |
|
| 71 | + return Html::element('td', $this->getAttributes(), $this->content); |
|
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | 74 | |
@@ -32,9 +32,9 @@ discard block |
||
| 32 | 32 | /** |
| 33 | 33 | * @param array $headers |
| 34 | 34 | */ |
| 35 | - public function __construct( array $headers ) { |
|
| 36 | - foreach ( $headers as $header ) { |
|
| 37 | - $this->addHeader( $header ); |
|
| 35 | + public function __construct(array $headers) { |
|
| 36 | + foreach ($headers as $header) { |
|
| 37 | + $this->addHeader($header); |
|
| 38 | 38 | } |
| 39 | 39 | } |
| 40 | 40 | |
@@ -43,16 +43,16 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @throws InvalidArgumentException |
| 45 | 45 | */ |
| 46 | - private function addHeader( $header ) { |
|
| 47 | - Assert::parameterType( 'string|' . HtmlTableHeaderBuilder::class, $header, '$header' ); |
|
| 46 | + private function addHeader($header) { |
|
| 47 | + Assert::parameterType('string|'.HtmlTableHeaderBuilder::class, $header, '$header'); |
|
| 48 | 48 | |
| 49 | - if ( is_string( $header ) ) { |
|
| 50 | - $header = new HtmlTableHeaderBuilder( $header ); |
|
| 49 | + if (is_string($header)) { |
|
| 50 | + $header = new HtmlTableHeaderBuilder($header); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | $this->headers[] = $header; |
| 54 | 54 | |
| 55 | - if ( $header->getIsSortable() ) { |
|
| 55 | + if ($header->getIsSortable()) { |
|
| 56 | 56 | $this->isSortable = true; |
| 57 | 57 | } |
| 58 | 58 | } |
@@ -85,12 +85,12 @@ discard block |
||
| 85 | 85 | * |
| 86 | 86 | * @throws InvalidArgumentException |
| 87 | 87 | */ |
| 88 | - public function appendRow( array $cells ) { |
|
| 89 | - foreach ( $cells as $key => $cell ) { |
|
| 90 | - if ( is_string( $cell ) ) { |
|
| 91 | - $cells[$key] = new HtmlTableCellBuilder( $cell ); |
|
| 92 | - } elseif ( !( $cell instanceof HtmlTableCellBuilder ) ) { |
|
| 93 | - throw new InvalidArgumentException( '$cells must be array of HtmlTableCell objects.' ); |
|
| 88 | + public function appendRow(array $cells) { |
|
| 89 | + foreach ($cells as $key => $cell) { |
|
| 90 | + if (is_string($cell)) { |
|
| 91 | + $cells[$key] = new HtmlTableCellBuilder($cell); |
|
| 92 | + } elseif (!($cell instanceof HtmlTableCellBuilder)) { |
|
| 93 | + throw new InvalidArgumentException('$cells must be array of HtmlTableCell objects.'); |
|
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | * |
| 105 | 105 | * @throws InvalidArgumentException |
| 106 | 106 | */ |
| 107 | - public function appendRows( array $rows ) { |
|
| 108 | - foreach ( $rows as $cells ) { |
|
| 109 | - if ( !is_array( $cells ) ) { |
|
| 110 | - throw new InvalidArgumentException( '$rows must be array of arrays of HtmlTableCell objects.' ); |
|
| 107 | + public function appendRows(array $rows) { |
|
| 108 | + foreach ($rows as $cells) { |
|
| 109 | + if (!is_array($cells)) { |
|
| 110 | + throw new InvalidArgumentException('$rows must be array of arrays of HtmlTableCell objects.'); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - $this->appendRow( $cells ); |
|
| 113 | + $this->appendRow($cells); |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | |
@@ -122,34 +122,34 @@ discard block |
||
| 122 | 122 | public function toHtml() { |
| 123 | 123 | // Open table |
| 124 | 124 | $tableClasses = 'wikitable'; |
| 125 | - if ( $this->isSortable ) { |
|
| 125 | + if ($this->isSortable) { |
|
| 126 | 126 | $tableClasses .= ' sortable jquery-tablesort'; |
| 127 | 127 | } |
| 128 | - $html = Html::openElement( 'table', [ 'class' => $tableClasses ] ); |
|
| 128 | + $html = Html::openElement('table', ['class' => $tableClasses]); |
|
| 129 | 129 | |
| 130 | 130 | // Write headers |
| 131 | - $html .= Html::openElement( 'tr' ); |
|
| 132 | - foreach ( $this->headers as $header ) { |
|
| 131 | + $html .= Html::openElement('tr'); |
|
| 132 | + foreach ($this->headers as $header) { |
|
| 133 | 133 | $html .= $header->toHtml(); |
| 134 | 134 | } |
| 135 | - $html .= Html::closeElement( 'tr' ); |
|
| 135 | + $html .= Html::closeElement('tr'); |
|
| 136 | 136 | |
| 137 | 137 | // Write rows |
| 138 | - foreach ( $this->rows as $row ) { |
|
| 139 | - $html .= Html::openElement( 'tr' ); |
|
| 138 | + foreach ($this->rows as $row) { |
|
| 139 | + $html .= Html::openElement('tr'); |
|
| 140 | 140 | |
| 141 | 141 | /** |
| 142 | 142 | * @var HtmlTableCellBuilder $cell |
| 143 | 143 | */ |
| 144 | - foreach ( $row as $cell ) { |
|
| 144 | + foreach ($row as $cell) { |
|
| 145 | 145 | $html .= $cell->toHtml(); |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - $html .= Html::closeElement( 'tr' ); |
|
| 148 | + $html .= Html::closeElement('tr'); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // Close table |
| 152 | - $html .= Html::closeElement( 'table' ); |
|
| 152 | + $html .= Html::closeElement('table'); |
|
| 153 | 153 | |
| 154 | 154 | return $html; |
| 155 | 155 | } |
@@ -114,18 +114,18 @@ discard block |
||
| 114 | 114 | $this->dataFactory = $dataFactory; |
| 115 | 115 | $this->defaultUserAgent = $defaultUserAgent; |
| 116 | 116 | |
| 117 | - $this->entityPrefix = $rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY ); |
|
| 117 | + $this->entityPrefix = $rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY); |
|
| 118 | 118 | $this->prefixes = <<<EOT |
| 119 | -PREFIX wd: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY )}> |
|
| 120 | -PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}> |
|
| 121 | -PREFIX wdt: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_DIRECT_CLAIM )}> |
|
| 122 | -PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}> |
|
| 123 | -PREFIX p: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM )}> |
|
| 124 | -PREFIX ps: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM_STATEMENT )}> |
|
| 125 | -PREFIX pq: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER )}> |
|
| 126 | -PREFIX pqv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER_VALUE )}> |
|
| 127 | -PREFIX pr: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE )}> |
|
| 128 | -PREFIX prv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE_VALUE )}> |
|
| 119 | +PREFIX wd: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY)}> |
|
| 120 | +PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}> |
|
| 121 | +PREFIX wdt: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_DIRECT_CLAIM)}> |
|
| 122 | +PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}> |
|
| 123 | +PREFIX p: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM)}> |
|
| 124 | +PREFIX ps: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM_STATEMENT)}> |
|
| 125 | +PREFIX pq: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER)}> |
|
| 126 | +PREFIX pqv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER_VALUE)}> |
|
| 127 | +PREFIX pr: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE)}> |
|
| 128 | +PREFIX prv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE_VALUE)}> |
|
| 129 | 129 | PREFIX wikibase: <http://wikiba.se/ontology#> |
| 130 | 130 | PREFIX wikibase-beta: <http://wikiba.se/ontology-beta#> |
| 131 | 131 | EOT; |
@@ -140,21 +140,21 @@ discard block |
||
| 140 | 140 | * @return CachedBool |
| 141 | 141 | * @throws SparqlHelperException if the query times out or some other error occurs |
| 142 | 142 | */ |
| 143 | - public function hasType( $id, array $classes, $withInstance ) { |
|
| 144 | - $instanceOfId = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
| 145 | - $subclassOfId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
| 143 | + public function hasType($id, array $classes, $withInstance) { |
|
| 144 | + $instanceOfId = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
| 145 | + $subclassOfId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
| 146 | 146 | |
| 147 | - $path = ( $withInstance ? "wdt:$instanceOfId/" : "" ) . "wdt:$subclassOfId*"; |
|
| 147 | + $path = ($withInstance ? "wdt:$instanceOfId/" : "")."wdt:$subclassOfId*"; |
|
| 148 | 148 | |
| 149 | 149 | $metadatas = []; |
| 150 | 150 | |
| 151 | - foreach ( array_chunk( $classes, 20 ) as $classesChunk ) { |
|
| 152 | - $classesValues = implode( ' ', array_map( |
|
| 153 | - function( $class ) { |
|
| 154 | - return 'wd:' . $class; |
|
| 151 | + foreach (array_chunk($classes, 20) as $classesChunk) { |
|
| 152 | + $classesValues = implode(' ', array_map( |
|
| 153 | + function($class) { |
|
| 154 | + return 'wd:'.$class; |
|
| 155 | 155 | }, |
| 156 | 156 | $classesChunk |
| 157 | - ) ); |
|
| 157 | + )); |
|
| 158 | 158 | |
| 159 | 159 | $query = <<<EOF |
| 160 | 160 | ASK { |
@@ -165,19 +165,19 @@ discard block |
||
| 165 | 165 | EOF; |
| 166 | 166 | // TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually |
| 167 | 167 | |
| 168 | - $result = $this->runQuery( $query ); |
|
| 168 | + $result = $this->runQuery($query); |
|
| 169 | 169 | $metadatas[] = $result->getMetadata(); |
| 170 | - if ( $result->getArray()['boolean'] ) { |
|
| 170 | + if ($result->getArray()['boolean']) { |
|
| 171 | 171 | return new CachedBool( |
| 172 | 172 | true, |
| 173 | - Metadata::merge( $metadatas ) |
|
| 173 | + Metadata::merge($metadatas) |
|
| 174 | 174 | ); |
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | return new CachedBool( |
| 179 | 179 | false, |
| 180 | - Metadata::merge( $metadatas ) |
|
| 180 | + Metadata::merge($metadatas) |
|
| 181 | 181 | ); |
| 182 | 182 | } |
| 183 | 183 | |
@@ -193,10 +193,10 @@ discard block |
||
| 193 | 193 | $ignoreDeprecatedStatements |
| 194 | 194 | ) { |
| 195 | 195 | $pid = $statement->getPropertyId()->serialize(); |
| 196 | - $guid = str_replace( '$', '-', $statement->getGuid() ); |
|
| 196 | + $guid = str_replace('$', '-', $statement->getGuid()); |
|
| 197 | 197 | |
| 198 | 198 | $deprecatedFilter = ''; |
| 199 | - if ( $ignoreDeprecatedStatements ) { |
|
| 199 | + if ($ignoreDeprecatedStatements) { |
|
| 200 | 200 | $deprecatedFilter .= 'MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }'; |
| 201 | 201 | $deprecatedFilter .= 'MINUS { ?otherStatement wikibase-beta:rank wikibase-beta:DeprecatedRank. }'; |
| 202 | 202 | } |
@@ -216,9 +216,9 @@ discard block |
||
| 216 | 216 | LIMIT 10 |
| 217 | 217 | EOF; |
| 218 | 218 | |
| 219 | - $result = $this->runQuery( $query ); |
|
| 219 | + $result = $this->runQuery($query); |
|
| 220 | 220 | |
| 221 | - return $this->getOtherEntities( $result ); |
|
| 221 | + return $this->getOtherEntities($result); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | /** |
@@ -243,16 +243,15 @@ discard block |
||
| 243 | 243 | $dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty( |
| 244 | 244 | $snak->getPropertyId() |
| 245 | 245 | ); |
| 246 | - list( $value, $isFullValue ) = $this->getRdfLiteral( $dataType, $dataValue ); |
|
| 247 | - if ( $isFullValue ) { |
|
| 246 | + list($value, $isFullValue) = $this->getRdfLiteral($dataType, $dataValue); |
|
| 247 | + if ($isFullValue) { |
|
| 248 | 248 | $prefix .= 'v'; |
| 249 | 249 | } |
| 250 | 250 | $path = $type === Context::TYPE_QUALIFIER ? |
| 251 | - "$prefix:$pid" : |
|
| 252 | - "prov:wasDerivedFrom/$prefix:$pid"; |
|
| 251 | + "$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid"; |
|
| 253 | 252 | |
| 254 | 253 | $deprecatedFilter = ''; |
| 255 | - if ( $ignoreDeprecatedStatements ) { |
|
| 254 | + if ($ignoreDeprecatedStatements) { |
|
| 256 | 255 | $deprecatedFilter = <<< EOF |
| 257 | 256 | MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. } |
| 258 | 257 | MINUS { ?otherStatement wikibase-beta:rank wikibase-beta:DeprecatedRank. } |
@@ -273,9 +272,9 @@ discard block |
||
| 273 | 272 | LIMIT 10 |
| 274 | 273 | EOF; |
| 275 | 274 | |
| 276 | - $result = $this->runQuery( $query ); |
|
| 275 | + $result = $this->runQuery($query); |
|
| 277 | 276 | |
| 278 | - return $this->getOtherEntities( $result ); |
|
| 277 | + return $this->getOtherEntities($result); |
|
| 279 | 278 | } |
| 280 | 279 | |
| 281 | 280 | /** |
@@ -285,8 +284,8 @@ discard block |
||
| 285 | 284 | * |
| 286 | 285 | * @return string |
| 287 | 286 | */ |
| 288 | - private function stringLiteral( $text ) { |
|
| 289 | - return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"'; |
|
| 287 | + private function stringLiteral($text) { |
|
| 288 | + return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"'; |
|
| 290 | 289 | } |
| 291 | 290 | |
| 292 | 291 | /** |
@@ -296,17 +295,17 @@ discard block |
||
| 296 | 295 | * |
| 297 | 296 | * @return CachedEntityIds |
| 298 | 297 | */ |
| 299 | - private function getOtherEntities( CachedQueryResults $results ) { |
|
| 300 | - return new CachedEntityIds( array_map( |
|
| 301 | - function ( $resultBindings ) { |
|
| 298 | + private function getOtherEntities(CachedQueryResults $results) { |
|
| 299 | + return new CachedEntityIds(array_map( |
|
| 300 | + function($resultBindings) { |
|
| 302 | 301 | $entityIRI = $resultBindings['otherEntity']['value']; |
| 303 | - $entityPrefixLength = strlen( $this->entityPrefix ); |
|
| 304 | - if ( substr( $entityIRI, 0, $entityPrefixLength ) === $this->entityPrefix ) { |
|
| 302 | + $entityPrefixLength = strlen($this->entityPrefix); |
|
| 303 | + if (substr($entityIRI, 0, $entityPrefixLength) === $this->entityPrefix) { |
|
| 305 | 304 | try { |
| 306 | 305 | return $this->entityIdParser->parse( |
| 307 | - substr( $entityIRI, $entityPrefixLength ) |
|
| 306 | + substr($entityIRI, $entityPrefixLength) |
|
| 308 | 307 | ); |
| 309 | - } catch ( EntityIdParsingException $e ) { |
|
| 308 | + } catch (EntityIdParsingException $e) { |
|
| 310 | 309 | // fall through |
| 311 | 310 | } |
| 312 | 311 | } |
@@ -314,7 +313,7 @@ discard block |
||
| 314 | 313 | return null; |
| 315 | 314 | }, |
| 316 | 315 | $results->getArray()['results']['bindings'] |
| 317 | - ), $results->getMetadata() ); |
|
| 316 | + ), $results->getMetadata()); |
|
| 318 | 317 | } |
| 319 | 318 | |
| 320 | 319 | // @codingStandardsIgnoreStart cyclomatic complexity of this function is too high |
@@ -327,47 +326,47 @@ discard block |
||
| 327 | 326 | * @return array the literal or IRI as a string in SPARQL syntax, |
| 328 | 327 | * and a boolean indicating whether it refers to a full value node or not |
| 329 | 328 | */ |
| 330 | - private function getRdfLiteral( $dataType, DataValue $dataValue ) { |
|
| 331 | - switch ( $dataType ) { |
|
| 329 | + private function getRdfLiteral($dataType, DataValue $dataValue) { |
|
| 330 | + switch ($dataType) { |
|
| 332 | 331 | case 'string': |
| 333 | 332 | case 'external-id': |
| 334 | - return [ $this->stringLiteral( $dataValue->getValue() ), false ]; |
|
| 333 | + return [$this->stringLiteral($dataValue->getValue()), false]; |
|
| 335 | 334 | case 'commonsMedia': |
| 336 | - $url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() ); |
|
| 337 | - return [ '<' . $url . '>', false ]; |
|
| 335 | + $url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue()); |
|
| 336 | + return ['<'.$url.'>', false]; |
|
| 338 | 337 | case 'geo-shape': |
| 339 | - $url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() ); |
|
| 340 | - return [ '<' . $url . '>', false ]; |
|
| 338 | + $url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue()); |
|
| 339 | + return ['<'.$url.'>', false]; |
|
| 341 | 340 | case 'tabular-data': |
| 342 | - $url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() ); |
|
| 343 | - return [ '<' . $url . '>', false ]; |
|
| 341 | + $url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue()); |
|
| 342 | + return ['<'.$url.'>', false]; |
|
| 344 | 343 | case 'url': |
| 345 | 344 | $url = $dataValue->getValue(); |
| 346 | - if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) { |
|
| 345 | + if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) { |
|
| 347 | 346 | // not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF) |
| 348 | 347 | // such an URL should never reach us, so just throw |
| 349 | - throw new InvalidArgumentException( 'invalid URL: ' . $url ); |
|
| 348 | + throw new InvalidArgumentException('invalid URL: '.$url); |
|
| 350 | 349 | } |
| 351 | - return [ '<' . $url . '>', false ]; |
|
| 350 | + return ['<'.$url.'>', false]; |
|
| 352 | 351 | case 'wikibase-item': |
| 353 | 352 | case 'wikibase-property': |
| 354 | 353 | /** @var EntityIdValue $dataValue */ |
| 355 | - return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ]; |
|
| 354 | + return ['wd:'.$dataValue->getEntityId()->getSerialization(), false]; |
|
| 356 | 355 | case 'monolingualtext': |
| 357 | 356 | /** @var MonolingualTextValue $dataValue */ |
| 358 | 357 | $lang = $dataValue->getLanguageCode(); |
| 359 | - if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) { |
|
| 358 | + if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) { |
|
| 360 | 359 | // not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG) |
| 361 | 360 | // such a language tag should never reach us, so just throw |
| 362 | - throw new InvalidArgumentException( 'invalid language tag: ' . $lang ); |
|
| 361 | + throw new InvalidArgumentException('invalid language tag: '.$lang); |
|
| 363 | 362 | } |
| 364 | - return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ]; |
|
| 363 | + return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false]; |
|
| 365 | 364 | case 'globe-coordinate': |
| 366 | 365 | case 'quantity': |
| 367 | 366 | case 'time': |
| 368 | - return [ 'wdv:' . $dataValue->getHash(), true ]; |
|
| 367 | + return ['wdv:'.$dataValue->getHash(), true]; |
|
| 369 | 368 | default: |
| 370 | - throw new InvalidArgumentException( 'unknown data type: ' . $dataType ); |
|
| 369 | + throw new InvalidArgumentException('unknown data type: '.$dataType); |
|
| 371 | 370 | } |
| 372 | 371 | } |
| 373 | 372 | // @codingStandardsIgnoreEnd |
@@ -380,44 +379,44 @@ discard block |
||
| 380 | 379 | * @throws SparqlHelperException if the query times out or some other error occurs |
| 381 | 380 | * @throws ConstraintParameterException if the $regex is invalid |
| 382 | 381 | */ |
| 383 | - public function matchesRegularExpression( $text, $regex ) { |
|
| 382 | + public function matchesRegularExpression($text, $regex) { |
|
| 384 | 383 | // caching wrapper around matchesRegularExpressionWithSparql |
| 385 | 384 | |
| 386 | - $textHash = hash( 'sha256', $text ); |
|
| 385 | + $textHash = hash('sha256', $text); |
|
| 387 | 386 | $cacheKey = $this->cache->makeKey( |
| 388 | 387 | 'WikibaseQualityConstraints', // extension |
| 389 | 388 | 'regex', // action |
| 390 | 389 | 'WDQS-Java', // regex flavor |
| 391 | - hash( 'sha256', $regex ) |
|
| 390 | + hash('sha256', $regex) |
|
| 392 | 391 | ); |
| 393 | - $cacheMapSize = $this->config->get( 'WBQualityConstraintsFormatCacheMapSize' ); |
|
| 392 | + $cacheMapSize = $this->config->get('WBQualityConstraintsFormatCacheMapSize'); |
|
| 394 | 393 | |
| 395 | 394 | $cacheMapArray = $this->cache->getWithSetCallback( |
| 396 | 395 | $cacheKey, |
| 397 | 396 | WANObjectCache::TTL_DAY, |
| 398 | - function( $cacheMapArray ) use ( $text, $regex, $textHash, $cacheMapSize ) { |
|
| 397 | + function($cacheMapArray) use ($text, $regex, $textHash, $cacheMapSize) { |
|
| 399 | 398 | // Initialize the cache map if not set |
| 400 | - if ( $cacheMapArray === false ) { |
|
| 399 | + if ($cacheMapArray === false) { |
|
| 401 | 400 | $key = 'wikibase.quality.constraints.regex.cache.refresh.init'; |
| 402 | - $this->dataFactory->increment( $key ); |
|
| 401 | + $this->dataFactory->increment($key); |
|
| 403 | 402 | return []; |
| 404 | 403 | } |
| 405 | 404 | |
| 406 | 405 | $key = 'wikibase.quality.constraints.regex.cache.refresh'; |
| 407 | - $this->dataFactory->increment( $key ); |
|
| 408 | - $cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $cacheMapSize ); |
|
| 409 | - if ( $cacheMap->has( $textHash ) ) { |
|
| 406 | + $this->dataFactory->increment($key); |
|
| 407 | + $cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $cacheMapSize); |
|
| 408 | + if ($cacheMap->has($textHash)) { |
|
| 410 | 409 | $key = 'wikibase.quality.constraints.regex.cache.refresh.hit'; |
| 411 | - $this->dataFactory->increment( $key ); |
|
| 412 | - $cacheMap->get( $textHash ); // ping cache |
|
| 410 | + $this->dataFactory->increment($key); |
|
| 411 | + $cacheMap->get($textHash); // ping cache |
|
| 413 | 412 | } else { |
| 414 | 413 | $key = 'wikibase.quality.constraints.regex.cache.refresh.miss'; |
| 415 | - $this->dataFactory->increment( $key ); |
|
| 414 | + $this->dataFactory->increment($key); |
|
| 416 | 415 | try { |
| 417 | - $matches = $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
| 418 | - } catch ( ConstraintParameterException $e ) { |
|
| 419 | - $matches = $this->serializeConstraintParameterException( $e ); |
|
| 420 | - } catch ( SparqlHelperException $e ) { |
|
| 416 | + $matches = $this->matchesRegularExpressionWithSparql($text, $regex); |
|
| 417 | + } catch (ConstraintParameterException $e) { |
|
| 418 | + $matches = $this->serializeConstraintParameterException($e); |
|
| 419 | + } catch (SparqlHelperException $e) { |
|
| 421 | 420 | // don’t cache this |
| 422 | 421 | return $cacheMap->toArray(); |
| 423 | 422 | } |
@@ -441,42 +440,42 @@ discard block |
||
| 441 | 440 | ] |
| 442 | 441 | ); |
| 443 | 442 | |
| 444 | - if ( isset( $cacheMapArray[$textHash] ) ) { |
|
| 443 | + if (isset($cacheMapArray[$textHash])) { |
|
| 445 | 444 | $key = 'wikibase.quality.constraints.regex.cache.hit'; |
| 446 | - $this->dataFactory->increment( $key ); |
|
| 445 | + $this->dataFactory->increment($key); |
|
| 447 | 446 | $matches = $cacheMapArray[$textHash]; |
| 448 | - if ( is_bool( $matches ) ) { |
|
| 447 | + if (is_bool($matches)) { |
|
| 449 | 448 | return $matches; |
| 450 | - } elseif ( is_array( $matches ) && |
|
| 451 | - $matches['type'] == ConstraintParameterException::class ) { |
|
| 452 | - throw $this->deserializeConstraintParameterException( $matches ); |
|
| 449 | + } elseif (is_array($matches) && |
|
| 450 | + $matches['type'] == ConstraintParameterException::class) { |
|
| 451 | + throw $this->deserializeConstraintParameterException($matches); |
|
| 453 | 452 | } else { |
| 454 | 453 | throw new MWException( |
| 455 | - 'Value of unknown type in object cache (' . |
|
| 456 | - 'cache key: ' . $cacheKey . ', ' . |
|
| 457 | - 'cache map key: ' . $textHash . ', ' . |
|
| 458 | - 'value type: ' . gettype( $matches ) . ')' |
|
| 454 | + 'Value of unknown type in object cache ('. |
|
| 455 | + 'cache key: '.$cacheKey.', '. |
|
| 456 | + 'cache map key: '.$textHash.', '. |
|
| 457 | + 'value type: '.gettype($matches).')' |
|
| 459 | 458 | ); |
| 460 | 459 | } |
| 461 | 460 | } else { |
| 462 | 461 | $key = 'wikibase.quality.constraints.regex.cache.miss'; |
| 463 | - $this->dataFactory->increment( $key ); |
|
| 464 | - return $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
| 462 | + $this->dataFactory->increment($key); |
|
| 463 | + return $this->matchesRegularExpressionWithSparql($text, $regex); |
|
| 465 | 464 | } |
| 466 | 465 | } |
| 467 | 466 | |
| 468 | - private function serializeConstraintParameterException( ConstraintParameterException $cpe ) { |
|
| 467 | + private function serializeConstraintParameterException(ConstraintParameterException $cpe) { |
|
| 469 | 468 | return [ |
| 470 | 469 | 'type' => ConstraintParameterException::class, |
| 471 | - 'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ), |
|
| 470 | + 'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()), |
|
| 472 | 471 | ]; |
| 473 | 472 | } |
| 474 | 473 | |
| 475 | - private function deserializeConstraintParameterException( array $serialization ) { |
|
| 474 | + private function deserializeConstraintParameterException(array $serialization) { |
|
| 476 | 475 | $message = $this->violationMessageDeserializer->deserialize( |
| 477 | 476 | $serialization['violationMessage'] |
| 478 | 477 | ); |
| 479 | - return new ConstraintParameterException( $message ); |
|
| 478 | + return new ConstraintParameterException($message); |
|
| 480 | 479 | } |
| 481 | 480 | |
| 482 | 481 | /** |
@@ -490,25 +489,25 @@ discard block |
||
| 490 | 489 | * @throws SparqlHelperException if the query times out or some other error occurs |
| 491 | 490 | * @throws ConstraintParameterException if the $regex is invalid |
| 492 | 491 | */ |
| 493 | - public function matchesRegularExpressionWithSparql( $text, $regex ) { |
|
| 494 | - $textStringLiteral = $this->stringLiteral( $text ); |
|
| 495 | - $regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' ); |
|
| 492 | + public function matchesRegularExpressionWithSparql($text, $regex) { |
|
| 493 | + $textStringLiteral = $this->stringLiteral($text); |
|
| 494 | + $regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$'); |
|
| 496 | 495 | |
| 497 | 496 | $query = <<<EOF |
| 498 | 497 | SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {} |
| 499 | 498 | EOF; |
| 500 | 499 | |
| 501 | - $result = $this->runQuery( $query ); |
|
| 500 | + $result = $this->runQuery($query); |
|
| 502 | 501 | |
| 503 | 502 | $vars = $result->getArray()['results']['bindings'][0]; |
| 504 | - if ( array_key_exists( 'matches', $vars ) ) { |
|
| 503 | + if (array_key_exists('matches', $vars)) { |
|
| 505 | 504 | // true or false ⇒ regex okay, text matches or not |
| 506 | 505 | return $vars['matches']['value'] === 'true'; |
| 507 | 506 | } else { |
| 508 | 507 | // empty result: regex broken |
| 509 | 508 | throw new ConstraintParameterException( |
| 510 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
| 511 | - ->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
| 509 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
| 510 | + ->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE) |
|
| 512 | 511 | ); |
| 513 | 512 | } |
| 514 | 513 | } |
@@ -520,14 +519,14 @@ discard block |
||
| 520 | 519 | * |
| 521 | 520 | * @return boolean |
| 522 | 521 | */ |
| 523 | - public function isTimeout( $responseContent ) { |
|
| 524 | - $timeoutRegex = implode( '|', array_map( |
|
| 525 | - function ( $fqn ) { |
|
| 526 | - return preg_quote( $fqn, '/' ); |
|
| 522 | + public function isTimeout($responseContent) { |
|
| 523 | + $timeoutRegex = implode('|', array_map( |
|
| 524 | + function($fqn) { |
|
| 525 | + return preg_quote($fqn, '/'); |
|
| 527 | 526 | }, |
| 528 | - $this->config->get( 'WBQualityConstraintsSparqlTimeoutExceptionClasses' ) |
|
| 529 | - ) ); |
|
| 530 | - return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent ); |
|
| 527 | + $this->config->get('WBQualityConstraintsSparqlTimeoutExceptionClasses') |
|
| 528 | + )); |
|
| 529 | + return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent); |
|
| 531 | 530 | } |
| 532 | 531 | |
| 533 | 532 | /** |
@@ -539,17 +538,17 @@ discard block |
||
| 539 | 538 | * @return integer|boolean the max-age (in seconds) |
| 540 | 539 | * or a plain boolean if no max-age can be determined |
| 541 | 540 | */ |
| 542 | - public function getCacheMaxAge( $responseHeaders ) { |
|
| 541 | + public function getCacheMaxAge($responseHeaders) { |
|
| 543 | 542 | if ( |
| 544 | - array_key_exists( 'x-cache-status', $responseHeaders ) && |
|
| 545 | - preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] ) |
|
| 543 | + array_key_exists('x-cache-status', $responseHeaders) && |
|
| 544 | + preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0]) |
|
| 546 | 545 | ) { |
| 547 | 546 | $maxage = []; |
| 548 | 547 | if ( |
| 549 | - array_key_exists( 'cache-control', $responseHeaders ) && |
|
| 550 | - preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage ) |
|
| 548 | + array_key_exists('cache-control', $responseHeaders) && |
|
| 549 | + preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage) |
|
| 551 | 550 | ) { |
| 552 | - return intval( $maxage[1] ); |
|
| 551 | + return intval($maxage[1]); |
|
| 553 | 552 | } else { |
| 554 | 553 | return true; |
| 555 | 554 | } |
@@ -567,59 +566,58 @@ discard block |
||
| 567 | 566 | * |
| 568 | 567 | * @throws SparqlHelperException if the query times out or some other error occurs |
| 569 | 568 | */ |
| 570 | - public function runQuery( $query ) { |
|
| 571 | - $endpoint = $this->config->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
| 572 | - $maxQueryTimeMillis = $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' ); |
|
| 573 | - $url = $endpoint . '?' . http_build_query( |
|
| 569 | + public function runQuery($query) { |
|
| 570 | + $endpoint = $this->config->get('WBQualityConstraintsSparqlEndpoint'); |
|
| 571 | + $maxQueryTimeMillis = $this->config->get('WBQualityConstraintsSparqlMaxMillis'); |
|
| 572 | + $url = $endpoint.'?'.http_build_query( |
|
| 574 | 573 | [ |
| 575 | - 'query' => "#wbqc\n" . $this->prefixes . $query, |
|
| 574 | + 'query' => "#wbqc\n".$this->prefixes.$query, |
|
| 576 | 575 | 'format' => 'json', |
| 577 | 576 | 'maxQueryTimeMillis' => $maxQueryTimeMillis, |
| 578 | 577 | ], |
| 579 | - null, ini_get( 'arg_separator.output' ), |
|
| 578 | + null, ini_get('arg_separator.output'), |
|
| 580 | 579 | // encode spaces with %20, not + |
| 581 | 580 | PHP_QUERY_RFC3986 |
| 582 | 581 | ); |
| 583 | 582 | |
| 584 | 583 | $options = [ |
| 585 | 584 | 'method' => 'GET', |
| 586 | - 'timeout' => (int)round( ( $maxQueryTimeMillis + 1000 ) / 1000 ), |
|
| 585 | + 'timeout' => (int) round(($maxQueryTimeMillis + 1000) / 1000), |
|
| 587 | 586 | 'connectTimeout' => 'default', |
| 588 | 587 | 'userAgent' => $this->defaultUserAgent, |
| 589 | 588 | ]; |
| 590 | - $request = MWHttpRequest::factory( $url, $options ); |
|
| 591 | - $startTime = microtime( true ); |
|
| 589 | + $request = MWHttpRequest::factory($url, $options); |
|
| 590 | + $startTime = microtime(true); |
|
| 592 | 591 | $status = $request->execute(); |
| 593 | - $endTime = microtime( true ); |
|
| 592 | + $endTime = microtime(true); |
|
| 594 | 593 | $this->dataFactory->timing( |
| 595 | 594 | 'wikibase.quality.constraints.sparql.timing', |
| 596 | - ( $endTime - $startTime ) * 1000 |
|
| 595 | + ($endTime - $startTime) * 1000 |
|
| 597 | 596 | ); |
| 598 | 597 | |
| 599 | - $maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() ); |
|
| 600 | - if ( $maxAge ) { |
|
| 601 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' ); |
|
| 598 | + $maxAge = $this->getCacheMaxAge($request->getResponseHeaders()); |
|
| 599 | + if ($maxAge) { |
|
| 600 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.cached'); |
|
| 602 | 601 | } |
| 603 | 602 | |
| 604 | - if ( $status->isOK() ) { |
|
| 603 | + if ($status->isOK()) { |
|
| 605 | 604 | $json = $request->getContent(); |
| 606 | - $arr = json_decode( $json, true ); |
|
| 605 | + $arr = json_decode($json, true); |
|
| 607 | 606 | return new CachedQueryResults( |
| 608 | 607 | $arr, |
| 609 | 608 | Metadata::ofCachingMetadata( |
| 610 | 609 | $maxAge ? |
| 611 | - CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) : |
|
| 612 | - CachingMetadata::fresh() |
|
| 610 | + CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh() |
|
| 613 | 611 | ) |
| 614 | 612 | ); |
| 615 | 613 | } else { |
| 616 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' ); |
|
| 614 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.error'); |
|
| 617 | 615 | |
| 618 | 616 | $this->dataFactory->increment( |
| 619 | 617 | "wikibase.quality.constraints.sparql.error.http.{$request->getStatus()}" |
| 620 | 618 | ); |
| 621 | 619 | |
| 622 | - if ( $this->isTimeout( $request->getContent() ) ) { |
|
| 620 | + if ($this->isTimeout($request->getContent())) { |
|
| 623 | 621 | $this->dataFactory->increment( |
| 624 | 622 | 'wikibase.quality.constraints.sparql.error.timeout' |
| 625 | 623 | ); |