@@ -17,10 +17,10 @@ discard block |
||
| 17 | 17 | use Wikibase\Repo\WikibaseRepo; |
| 18 | 18 | |
| 19 | 19 | // @codeCoverageIgnoreStart |
| 20 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
| 21 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
| 20 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
| 21 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
| 22 | 22 | |
| 23 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
| 23 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
| 24 | 24 | // @codeCoverageIgnoreEnd |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -59,20 +59,20 @@ discard block |
||
| 59 | 59 | parent::__construct(); |
| 60 | 60 | |
| 61 | 61 | $this->addDescription( |
| 62 | - 'Import entities needed for constraint checks ' . |
|
| 62 | + 'Import entities needed for constraint checks '. |
|
| 63 | 63 | 'from Wikidata into the local repository.' |
| 64 | 64 | ); |
| 65 | 65 | $this->addOption( |
| 66 | 66 | 'config-format', |
| 67 | - 'The format in which the resulting configuration will be omitted: ' . |
|
| 68 | - '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), ' . |
|
| 67 | + 'The format in which the resulting configuration will be omitted: '. |
|
| 68 | + '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), '. |
|
| 69 | 69 | 'or "wgConf" for printing parts of arrays suitable for inclusion in $wgConf->settings.' |
| 70 | 70 | ); |
| 71 | 71 | $this->addOption( |
| 72 | 72 | 'dry-run', |
| 73 | 73 | 'Don’t actually import entities, just print which ones would be imported.' |
| 74 | 74 | ); |
| 75 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
| 75 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -84,8 +84,8 @@ discard block |
||
| 84 | 84 | $this->entityDeserializer = $repo->getInternalFormatEntityDeserializer(); |
| 85 | 85 | $this->entityStore = $repo->getEntityStore(); |
| 86 | 86 | $this->httpRequestFactory = MediaWikiServices::getInstance()->getHttpRequestFactory(); |
| 87 | - if ( !$this->getOption( 'dry-run', false ) ) { |
|
| 88 | - $this->user = User::newSystemUser( 'WikibaseQualityConstraints importer' ); |
|
| 87 | + if (!$this->getOption('dry-run', false)) { |
|
| 88 | + $this->user = User::newSystemUser('WikibaseQualityConstraints importer'); |
|
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
@@ -94,21 +94,21 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | $configUpdates = []; |
| 96 | 96 | |
| 97 | - $extensionJsonFile = __DIR__ . '/../extension.json'; |
|
| 98 | - $extensionJsonText = file_get_contents( $extensionJsonFile ); |
|
| 99 | - $extensionJson = json_decode( $extensionJsonText, /* assoc = */ true ); |
|
| 97 | + $extensionJsonFile = __DIR__.'/../extension.json'; |
|
| 98 | + $extensionJsonText = file_get_contents($extensionJsonFile); |
|
| 99 | + $extensionJson = json_decode($extensionJsonText, /* assoc = */ true); |
|
| 100 | 100 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
| 101 | - $wikidataEntityIds = $this->getEntitiesToImport( $extensionJson['config'], $this->getConfig() ); |
|
| 101 | + $wikidataEntityIds = $this->getEntitiesToImport($extensionJson['config'], $this->getConfig()); |
|
| 102 | 102 | |
| 103 | - foreach ( $wikidataEntityIds as $key => $wikidataEntityId ) { |
|
| 104 | - $localEntityId = $this->importEntityFromWikidata( $wikidataEntityId ); |
|
| 103 | + foreach ($wikidataEntityIds as $key => $wikidataEntityId) { |
|
| 104 | + $localEntityId = $this->importEntityFromWikidata($wikidataEntityId); |
|
| 105 | 105 | $configUpdates[$key] = [ |
| 106 | 106 | 'wikidata' => $wikidataEntityId, |
| 107 | 107 | 'local' => $localEntityId, |
| 108 | 108 | ]; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - $this->outputConfigUpdates( $configUpdates ); |
|
| 111 | + $this->outputConfigUpdates($configUpdates); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -116,18 +116,18 @@ discard block |
||
| 116 | 116 | * @param Config $wikiConfig |
| 117 | 117 | * @return string[] |
| 118 | 118 | */ |
| 119 | - private function getEntitiesToImport( array $extensionJsonConfig, Config $wikiConfig ) { |
|
| 119 | + private function getEntitiesToImport(array $extensionJsonConfig, Config $wikiConfig) { |
|
| 120 | 120 | $wikidataEntityIds = []; |
| 121 | 121 | |
| 122 | - foreach ( $extensionJsonConfig as $key => $value ) { |
|
| 123 | - if ( !preg_match( '/Id$/', $key ) ) { |
|
| 122 | + foreach ($extensionJsonConfig as $key => $value) { |
|
| 123 | + if (!preg_match('/Id$/', $key)) { |
|
| 124 | 124 | continue; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | $wikidataEntityId = $value['value']; |
| 128 | - $localEntityId = $wikiConfig->get( $key ); |
|
| 128 | + $localEntityId = $wikiConfig->get($key); |
|
| 129 | 129 | |
| 130 | - if ( $localEntityId === $wikidataEntityId ) { |
|
| 130 | + if ($localEntityId === $wikidataEntityId) { |
|
| 131 | 131 | $wikidataEntityIds[$key] = $wikidataEntityId; |
| 132 | 132 | } |
| 133 | 133 | } |
@@ -139,10 +139,10 @@ discard block |
||
| 139 | 139 | * @param string $wikidataEntityId |
| 140 | 140 | * @return string local entity ID |
| 141 | 141 | */ |
| 142 | - private function importEntityFromWikidata( $wikidataEntityId ) { |
|
| 142 | + private function importEntityFromWikidata($wikidataEntityId) { |
|
| 143 | 143 | $wikidataEntityUrl = "https://www.wikidata.org/wiki/Special:EntityData/$wikidataEntityId.json"; |
| 144 | - $wikidataEntitiesJson = $this->httpRequestFactory->get( $wikidataEntityUrl, [], __METHOD__ ); |
|
| 145 | - return $this->importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ); |
|
| 144 | + $wikidataEntitiesJson = $this->httpRequestFactory->get($wikidataEntityUrl, [], __METHOD__); |
|
| 145 | + return $this->importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
@@ -150,24 +150,24 @@ discard block |
||
| 150 | 150 | * @param string $wikidataEntitiesJson |
| 151 | 151 | * @return string local entity ID |
| 152 | 152 | */ |
| 153 | - private function importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ) { |
|
| 153 | + private function importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson) { |
|
| 154 | 154 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
| 155 | - $wikidataEntityArray = json_decode( $wikidataEntitiesJson, true )['entities'][$wikidataEntityId]; |
|
| 156 | - $wikidataEntity = $this->entityDeserializer->deserialize( $wikidataEntityArray ); |
|
| 155 | + $wikidataEntityArray = json_decode($wikidataEntitiesJson, true)['entities'][$wikidataEntityId]; |
|
| 156 | + $wikidataEntity = $this->entityDeserializer->deserialize($wikidataEntityArray); |
|
| 157 | 157 | |
| 158 | - $wikidataEntity->setId( null ); |
|
| 158 | + $wikidataEntity->setId(null); |
|
| 159 | 159 | |
| 160 | - if ( $wikidataEntity instanceof StatementListProvider ) { |
|
| 160 | + if ($wikidataEntity instanceof StatementListProvider) { |
|
| 161 | 161 | $wikidataEntity->getStatements()->clear(); |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - if ( $wikidataEntity instanceof Item ) { |
|
| 165 | - $wikidataEntity->setSiteLinkList( new SiteLinkList() ); |
|
| 164 | + if ($wikidataEntity instanceof Item) { |
|
| 165 | + $wikidataEntity->setSiteLinkList(new SiteLinkList()); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - if ( $this->getOption( 'dry-run', false ) ) { |
|
| 169 | - $wikidataEntityJson = json_encode( $this->entitySerializer->serialize( $wikidataEntity ) ); |
|
| 170 | - $this->output( $wikidataEntityJson . "\n" ); |
|
| 168 | + if ($this->getOption('dry-run', false)) { |
|
| 169 | + $wikidataEntityJson = json_encode($this->entitySerializer->serialize($wikidataEntity)); |
|
| 170 | + $this->output($wikidataEntityJson."\n"); |
|
| 171 | 171 | return "-$wikidataEntityId"; |
| 172 | 172 | } |
| 173 | 173 | |
@@ -180,12 +180,12 @@ discard block |
||
| 180 | 180 | )->getEntity(); |
| 181 | 181 | |
| 182 | 182 | return $localEntity->getId()->getSerialization(); |
| 183 | - } catch ( StorageException $storageException ) { |
|
| 184 | - return $this->storageExceptionToEntityId( $storageException ); |
|
| 183 | + } catch (StorageException $storageException) { |
|
| 184 | + return $this->storageExceptionToEntityId($storageException); |
|
| 185 | 185 | } |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - private function storageExceptionToEntityId( StorageException $storageException ) { |
|
| 188 | + private function storageExceptionToEntityId(StorageException $storageException) { |
|
| 189 | 189 | $message = $storageException->getMessage(); |
| 190 | 190 | // example messages: |
| 191 | 191 | // * Item [[Item:Q475|Q475]] already has label "as references" |
@@ -195,25 +195,25 @@ discard block |
||
| 195 | 195 | // * Property [[Property:P694|P694]] already has label "instance of" |
| 196 | 196 | // associated with language code en. |
| 197 | 197 | $pattern = '/[[|]([^][|]*)]] already has label .* associated with language code/'; |
| 198 | - if ( preg_match( $pattern, $message, $matches ) ) { |
|
| 198 | + if (preg_match($pattern, $message, $matches)) { |
|
| 199 | 199 | return $matches[1]; |
| 200 | 200 | } else { |
| 201 | 201 | throw $storageException; |
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - private function outputConfigUpdates( array $configUpdates ) { |
|
| 206 | - $configFormat = $this->getOption( 'config-format', 'globals' ); |
|
| 207 | - switch ( $configFormat ) { |
|
| 205 | + private function outputConfigUpdates(array $configUpdates) { |
|
| 206 | + $configFormat = $this->getOption('config-format', 'globals'); |
|
| 207 | + switch ($configFormat) { |
|
| 208 | 208 | case 'globals': |
| 209 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
| 209 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
| 210 | 210 | break; |
| 211 | 211 | case 'wgConf': |
| 212 | - $this->outputConfigUpdatesWgConf( $configUpdates ); |
|
| 212 | + $this->outputConfigUpdatesWgConf($configUpdates); |
|
| 213 | 213 | break; |
| 214 | 214 | default: |
| 215 | - $this->error( "Invalid config format \"$configFormat\", using \"globals\"" ); |
|
| 216 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
| 215 | + $this->error("Invalid config format \"$configFormat\", using \"globals\""); |
|
| 216 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
| 217 | 217 | break; |
| 218 | 218 | } |
| 219 | 219 | } |
@@ -221,22 +221,22 @@ discard block |
||
| 221 | 221 | /** |
| 222 | 222 | * @param array[] $configUpdates |
| 223 | 223 | */ |
| 224 | - private function outputConfigUpdatesGlobals( array $configUpdates ) { |
|
| 225 | - foreach ( $configUpdates as $key => $value ) { |
|
| 226 | - $localValueCode = var_export( $value['local'], true ); |
|
| 227 | - $this->output( "\$wg$key = $localValueCode;\n" ); |
|
| 224 | + private function outputConfigUpdatesGlobals(array $configUpdates) { |
|
| 225 | + foreach ($configUpdates as $key => $value) { |
|
| 226 | + $localValueCode = var_export($value['local'], true); |
|
| 227 | + $this->output("\$wg$key = $localValueCode;\n"); |
|
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
| 232 | 232 | * @param array[] $configUpdates |
| 233 | 233 | */ |
| 234 | - private function outputConfigUpdatesWgConf( array $configUpdates ) { |
|
| 235 | - foreach ( $configUpdates as $key => $value ) { |
|
| 236 | - $keyCode = var_export( "wg$key", true ); |
|
| 237 | - $wikidataValueCode = var_export( $value['wikidata'], true ); |
|
| 238 | - $localValueCode = var_export( $value['local'], true ); |
|
| 239 | - $wikiIdCode = var_export( wfWikiID(), true ); |
|
| 234 | + private function outputConfigUpdatesWgConf(array $configUpdates) { |
|
| 235 | + foreach ($configUpdates as $key => $value) { |
|
| 236 | + $keyCode = var_export("wg$key", true); |
|
| 237 | + $wikidataValueCode = var_export($value['wikidata'], true); |
|
| 238 | + $localValueCode = var_export($value['local'], true); |
|
| 239 | + $wikiIdCode = var_export(wfWikiID(), true); |
|
| 240 | 240 | $block = <<< EOF |
| 241 | 241 | $keyCode => [ |
| 242 | 242 | 'default' => $wikidataValueCode, |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | |
| 246 | 246 | |
| 247 | 247 | EOF; |
| 248 | - $this->output( $block ); |
|
| 248 | + $this->output($block); |
|
| 249 | 249 | } |
| 250 | 250 | } |
| 251 | 251 | |
@@ -53,12 +53,12 @@ discard block |
||
| 53 | 53 | $this->dataFactory = $dataFactory; |
| 54 | 54 | $this->logger = $logger; |
| 55 | 55 | $this->constraintCheckDurationLimits = [ |
| 56 | - 'info' => $config->get( 'WBQualityConstraintsCheckDurationInfoSeconds' ), |
|
| 57 | - 'warning' => $config->get( 'WBQualityConstraintsCheckDurationWarningSeconds' ), |
|
| 56 | + 'info' => $config->get('WBQualityConstraintsCheckDurationInfoSeconds'), |
|
| 57 | + 'warning' => $config->get('WBQualityConstraintsCheckDurationWarningSeconds'), |
|
| 58 | 58 | ]; |
| 59 | 59 | $this->constraintCheckOnEntityDurationLimits = [ |
| 60 | - 'info' => $config->get( 'WBQualityConstraintsCheckOnEntityDurationInfoSeconds' ), |
|
| 61 | - 'warning' => $config->get( 'WBQualityConstraintsCheckOnEntityDurationWarningSeconds' ), |
|
| 60 | + 'info' => $config->get('WBQualityConstraintsCheckOnEntityDurationInfoSeconds'), |
|
| 61 | + 'warning' => $config->get('WBQualityConstraintsCheckOnEntityDurationWarningSeconds'), |
|
| 62 | 62 | ]; |
| 63 | 63 | } |
| 64 | 64 | |
@@ -69,23 +69,23 @@ discard block |
||
| 69 | 69 | * @param float $durationSeconds |
| 70 | 70 | * @return array [ $limitSeconds, $logLevel ] |
| 71 | 71 | */ |
| 72 | - private function findLimit( $limits, $durationSeconds ) { |
|
| 72 | + private function findLimit($limits, $durationSeconds) { |
|
| 73 | 73 | $limitSeconds = null; |
| 74 | 74 | $logLevel = null; |
| 75 | 75 | |
| 76 | - foreach ( $limits as $level => $limit ) { |
|
| 76 | + foreach ($limits as $level => $limit) { |
|
| 77 | 77 | if ( |
| 78 | 78 | // duration exceeds this limit |
| 79 | - isset( $limit ) && $durationSeconds > $limit && |
|
| 79 | + isset($limit) && $durationSeconds > $limit && |
|
| 80 | 80 | // this limit is longer than previous longest limit |
| 81 | - ( $limitSeconds === null || $limit > $limitSeconds ) |
|
| 81 | + ($limitSeconds === null || $limit > $limitSeconds) |
|
| 82 | 82 | ) { |
| 83 | 83 | $limitSeconds = $limit; |
| 84 | 84 | $logLevel = $level; |
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - return [ $limitSeconds, $logLevel ]; |
|
| 88 | + return [$limitSeconds, $logLevel]; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -110,31 +110,31 @@ discard block |
||
| 110 | 110 | $durationSeconds, |
| 111 | 111 | $method |
| 112 | 112 | ) { |
| 113 | - $constraintCheckerClassShortName = substr( strrchr( $constraintCheckerClass, '\\' ), 1 ); |
|
| 113 | + $constraintCheckerClassShortName = substr(strrchr($constraintCheckerClass, '\\'), 1); |
|
| 114 | 114 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
| 115 | 115 | |
| 116 | 116 | $this->dataFactory->timing( |
| 117 | - 'wikibase.quality.constraints.check.timing.' . |
|
| 118 | - $constraintTypeItemId . '-' . |
|
| 117 | + 'wikibase.quality.constraints.check.timing.'. |
|
| 118 | + $constraintTypeItemId.'-'. |
|
| 119 | 119 | $constraintCheckerClassShortName, |
| 120 | 120 | $durationSeconds * 1000 |
| 121 | 121 | ); |
| 122 | 122 | |
| 123 | 123 | // find the longest limit (and associated log level) that the duration exceeds |
| 124 | - list( $limitSeconds, $logLevel ) = $this->findLimit( |
|
| 124 | + list($limitSeconds, $logLevel) = $this->findLimit( |
|
| 125 | 125 | $this->constraintCheckDurationLimits, |
| 126 | 126 | $durationSeconds |
| 127 | 127 | ); |
| 128 | - if ( $limitSeconds === null ) { |
|
| 128 | + if ($limitSeconds === null) { |
|
| 129 | 129 | return; |
| 130 | 130 | } |
| 131 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
| 131 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
| 132 | 132 | // TODO log less details but still log something |
| 133 | 133 | return; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | $resultMessage = $result->getMessage(); |
| 137 | - if ( $resultMessage !== null ) { |
|
| 137 | + if ($resultMessage !== null) { |
|
| 138 | 138 | $resultMessageKey = $resultMessage->getMessageKey(); |
| 139 | 139 | } else { |
| 140 | 140 | $resultMessageKey = null; |
@@ -142,8 +142,8 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | $this->logger->log( |
| 144 | 144 | $logLevel, |
| 145 | - 'Constraint check with {constraintCheckerClassShortName} ' . |
|
| 146 | - 'took longer than {limitSeconds} second(s) ' . |
|
| 145 | + 'Constraint check with {constraintCheckerClassShortName} '. |
|
| 146 | + 'took longer than {limitSeconds} second(s) '. |
|
| 147 | 147 | '(duration: {durationSeconds} seconds).', |
| 148 | 148 | [ |
| 149 | 149 | 'method' => $method, |
@@ -153,13 +153,13 @@ discard block |
||
| 153 | 153 | 'constraintId' => $constraint->getConstraintId(), |
| 154 | 154 | 'constraintPropertyId' => $constraint->getPropertyId()->getSerialization(), |
| 155 | 155 | 'constraintTypeItemId' => $constraintTypeItemId, |
| 156 | - 'constraintParameters' => json_encode( $constraint->getConstraintParameters() ), |
|
| 156 | + 'constraintParameters' => json_encode($constraint->getConstraintParameters()), |
|
| 157 | 157 | 'constraintCheckerClass' => $constraintCheckerClass, |
| 158 | 158 | 'constraintCheckerClassShortName' => $constraintCheckerClassShortName, |
| 159 | 159 | 'entityId' => $context->getEntity()->getId()->getSerialization(), |
| 160 | 160 | 'statementGuid' => $context->getSnakStatement()->getGuid(), |
| 161 | 161 | 'resultStatus' => $result->getStatus(), |
| 162 | - 'resultParameters' => json_encode( $result->getParameters() ), |
|
| 162 | + 'resultParameters' => json_encode($result->getParameters()), |
|
| 163 | 163 | 'resultMessage' => $resultMessageKey, |
| 164 | 164 | ] |
| 165 | 165 | ); |
@@ -189,18 +189,18 @@ discard block |
||
| 189 | 189 | ); |
| 190 | 190 | |
| 191 | 191 | // find the longest limit (and associated log level) that the duration exceeds |
| 192 | - list( $limitSeconds, $logLevel ) = $this->findLimit( |
|
| 192 | + list($limitSeconds, $logLevel) = $this->findLimit( |
|
| 193 | 193 | $this->constraintCheckOnEntityDurationLimits, |
| 194 | 194 | $durationSeconds |
| 195 | 195 | ); |
| 196 | - if ( $limitSeconds === null ) { |
|
| 196 | + if ($limitSeconds === null) { |
|
| 197 | 197 | return; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | $this->logger->log( |
| 201 | 201 | $logLevel, |
| 202 | - 'Full constraint check on {entityId} ' . |
|
| 203 | - 'took longer than {limitSeconds} second(s) ' . |
|
| 202 | + 'Full constraint check on {entityId} '. |
|
| 203 | + 'took longer than {limitSeconds} second(s) '. |
|
| 204 | 204 | '(duration: {durationSeconds} seconds).', |
| 205 | 205 | [ |
| 206 | 206 | 'method' => $method, |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | * |
| 219 | 219 | * @param EntityId $entityId |
| 220 | 220 | */ |
| 221 | - public function logCheckConstraintsCacheHit( EntityId $entityId ) { |
|
| 221 | + public function logCheckConstraintsCacheHit(EntityId $entityId) { |
|
| 222 | 222 | $this->dataFactory->increment( |
| 223 | 223 | 'wikibase.quality.constraints.cache.entity.hit' |
| 224 | 224 | ); |
@@ -229,10 +229,10 @@ discard block |
||
| 229 | 229 | * |
| 230 | 230 | * @param EntityId[] $entityIds |
| 231 | 231 | */ |
| 232 | - public function logCheckConstraintsCacheMisses( array $entityIds ) { |
|
| 232 | + public function logCheckConstraintsCacheMisses(array $entityIds) { |
|
| 233 | 233 | $this->dataFactory->updateCount( |
| 234 | 234 | 'wikibase.quality.constraints.cache.entity.miss', |
| 235 | - count( $entityIds ) |
|
| 235 | + count($entityIds) |
|
| 236 | 236 | ); |
| 237 | 237 | } |
| 238 | 238 | |
@@ -259,17 +259,17 @@ discard block |
||
| 259 | 259 | * @param EntityId[] $entityIds |
| 260 | 260 | * @param int $maxRevisionIds |
| 261 | 261 | */ |
| 262 | - public function logHugeDependencyMetadata( array $entityIds, $maxRevisionIds ) { |
|
| 262 | + public function logHugeDependencyMetadata(array $entityIds, $maxRevisionIds) { |
|
| 263 | 263 | $this->logger->log( |
| 264 | 264 | 'warning', |
| 265 | - 'Dependency metadata for constraint check result has huge set of entity IDs ' . |
|
| 266 | - '(count ' . count( $entityIds ) . ', limit ' . $maxRevisionIds . '); ' . |
|
| 265 | + 'Dependency metadata for constraint check result has huge set of entity IDs '. |
|
| 266 | + '(count '.count($entityIds).', limit '.$maxRevisionIds.'); '. |
|
| 267 | 267 | 'caching disabled for this check result.', |
| 268 | 268 | [ |
| 269 | 269 | 'loggingMethod' => __METHOD__, |
| 270 | 270 | 'entityIds' => json_encode( |
| 271 | 271 | array_map( |
| 272 | - function ( EntityId $entityId ) { |
|
| 272 | + function(EntityId $entityId) { |
|
| 273 | 273 | return $entityId->getSerialization(); |
| 274 | 274 | }, |
| 275 | 275 | $entityIds |
@@ -288,17 +288,17 @@ discard block |
||
| 288 | 288 | 'Sparql API replied with status 429 and a retry-after header. Requesting to retry after {retryAfterTime}', |
| 289 | 289 | [ |
| 290 | 290 | 'retryAfterTime' => $retryAfterTime, |
| 291 | - 'responseHeaders' => json_encode( $request->getResponseHeaders() ), |
|
| 291 | + 'responseHeaders' => json_encode($request->getResponseHeaders()), |
|
| 292 | 292 | 'responseContent' => $request->getContent(), |
| 293 | 293 | ] |
| 294 | 294 | ); |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | - public function logSparqlHelperTooManyRequestsRetryAfterInvalid( MWHttpRequest $request ) { |
|
| 297 | + public function logSparqlHelperTooManyRequestsRetryAfterInvalid(MWHttpRequest $request) { |
|
| 298 | 298 | $this->logger->warning( |
| 299 | 299 | 'Sparql API replied with status 429 and no valid retry-after header.', |
| 300 | 300 | [ |
| 301 | - 'responseHeaders' => json_encode( $request->getResponseHeaders() ), |
|
| 301 | + 'responseHeaders' => json_encode($request->getResponseHeaders()), |
|
| 302 | 302 | 'responseContent' => $request->getContent(), |
| 303 | 303 | ] |
| 304 | 304 | ); |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | callable $defaultResultsPerEntity = null |
| 144 | 144 | ) { |
| 145 | 145 | $checkResults = []; |
| 146 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
| 146 | + $entity = $this->entityLookup->getEntity($entityId); |
|
| 147 | 147 | |
| 148 | - if ( $entity instanceof StatementListProvidingEntity ) { |
|
| 149 | - $startTime = microtime( true ); |
|
| 148 | + if ($entity instanceof StatementListProvidingEntity) { |
|
| 149 | + $startTime = microtime(true); |
|
| 150 | 150 | |
| 151 | 151 | $checkResults = $this->checkEveryStatement( |
| 152 | 152 | $entity, |
@@ -154,9 +154,9 @@ discard block |
||
| 154 | 154 | $defaultResultsPerContext |
| 155 | 155 | ); |
| 156 | 156 | |
| 157 | - $endTime = microtime( true ); |
|
| 157 | + $endTime = microtime(true); |
|
| 158 | 158 | |
| 159 | - if ( $constraintIds === null ) { // only log full constraint checks |
|
| 159 | + if ($constraintIds === null) { // only log full constraint checks |
|
| 160 | 160 | $this->loggingHelper->logConstraintCheckOnEntity( |
| 161 | 161 | $entityId, |
| 162 | 162 | $checkResults, |
@@ -166,11 +166,11 @@ discard block |
||
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - if ( $defaultResultsPerEntity !== null ) { |
|
| 170 | - $checkResults = array_merge( $defaultResultsPerEntity( $entityId ), $checkResults ); |
|
| 169 | + if ($defaultResultsPerEntity !== null) { |
|
| 170 | + $checkResults = array_merge($defaultResultsPerEntity($entityId), $checkResults); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - return $this->sortResult( $checkResults ); |
|
| 173 | + return $this->sortResult($checkResults); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -192,19 +192,19 @@ discard block |
||
| 192 | 192 | callable $defaultResults = null |
| 193 | 193 | ) { |
| 194 | 194 | |
| 195 | - $parsedGuid = $this->statementGuidParser->parse( $guid ); |
|
| 195 | + $parsedGuid = $this->statementGuidParser->parse($guid); |
|
| 196 | 196 | $entityId = $parsedGuid->getEntityId(); |
| 197 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
| 198 | - if ( $entity instanceof StatementListProvidingEntity ) { |
|
| 199 | - $statement = $entity->getStatements()->getFirstStatementWithGuid( $guid ); |
|
| 200 | - if ( $statement ) { |
|
| 197 | + $entity = $this->entityLookup->getEntity($entityId); |
|
| 198 | + if ($entity instanceof StatementListProvidingEntity) { |
|
| 199 | + $statement = $entity->getStatements()->getFirstStatementWithGuid($guid); |
|
| 200 | + if ($statement) { |
|
| 201 | 201 | $result = $this->checkStatement( |
| 202 | 202 | $entity, |
| 203 | 203 | $statement, |
| 204 | 204 | $constraintIds, |
| 205 | 205 | $defaultResults |
| 206 | 206 | ); |
| 207 | - $output = $this->sortResult( $result ); |
|
| 207 | + $output = $this->sortResult($result); |
|
| 208 | 208 | return $output; |
| 209 | 209 | } |
| 210 | 210 | } |
@@ -212,8 +212,8 @@ discard block |
||
| 212 | 212 | return []; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - private function getAllowedContextTypes( Constraint $constraint ) { |
|
| 216 | - if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
| 215 | + private function getAllowedContextTypes(Constraint $constraint) { |
|
| 216 | + if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
| 217 | 217 | return [ |
| 218 | 218 | Context::TYPE_STATEMENT, |
| 219 | 219 | Context::TYPE_QUALIFIER, |
@@ -221,12 +221,12 @@ discard block |
||
| 221 | 221 | ]; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - return array_keys( array_filter( |
|
| 224 | + return array_keys(array_filter( |
|
| 225 | 225 | $this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedContextTypes(), |
| 226 | - function ( $resultStatus ) { |
|
| 226 | + function($resultStatus) { |
|
| 227 | 227 | return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE; |
| 228 | 228 | } |
| 229 | - ) ); |
|
| 229 | + )); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -237,32 +237,32 @@ discard block |
||
| 237 | 237 | * |
| 238 | 238 | * @return ConstraintParameterException[] |
| 239 | 239 | */ |
| 240 | - private function checkCommonConstraintParameters( Constraint $constraint ) { |
|
| 240 | + private function checkCommonConstraintParameters(Constraint $constraint) { |
|
| 241 | 241 | $constraintParameters = $constraint->getConstraintParameters(); |
| 242 | 242 | try { |
| 243 | - $this->constraintParameterParser->checkError( $constraintParameters ); |
|
| 244 | - } catch ( ConstraintParameterException $e ) { |
|
| 245 | - return [ $e ]; |
|
| 243 | + $this->constraintParameterParser->checkError($constraintParameters); |
|
| 244 | + } catch (ConstraintParameterException $e) { |
|
| 245 | + return [$e]; |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | $problems = []; |
| 249 | 249 | try { |
| 250 | - $this->constraintParameterParser->parseExceptionParameter( $constraintParameters ); |
|
| 251 | - } catch ( ConstraintParameterException $e ) { |
|
| 250 | + $this->constraintParameterParser->parseExceptionParameter($constraintParameters); |
|
| 251 | + } catch (ConstraintParameterException $e) { |
|
| 252 | 252 | $problems[] = $e; |
| 253 | 253 | } |
| 254 | 254 | try { |
| 255 | - $this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters ); |
|
| 256 | - } catch ( ConstraintParameterException $e ) { |
|
| 255 | + $this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters); |
|
| 256 | + } catch (ConstraintParameterException $e) { |
|
| 257 | 257 | $problems[] = $e; |
| 258 | 258 | } |
| 259 | 259 | try { |
| 260 | 260 | $this->constraintParameterParser->parseConstraintScopeParameter( |
| 261 | 261 | $constraintParameters, |
| 262 | 262 | $constraint->getConstraintTypeItemId(), |
| 263 | - $this->getAllowedContextTypes( $constraint ) |
|
| 263 | + $this->getAllowedContextTypes($constraint) |
|
| 264 | 264 | ); |
| 265 | - } catch ( ConstraintParameterException $e ) { |
|
| 265 | + } catch (ConstraintParameterException $e) { |
|
| 266 | 266 | $problems[] = $e; |
| 267 | 267 | } |
| 268 | 268 | return $problems; |
@@ -275,16 +275,16 @@ discard block |
||
| 275 | 275 | * @return ConstraintParameterException[][] first level indexed by constraint ID, |
| 276 | 276 | * second level like checkConstraintParametersOnConstraintId (but without possibility of null) |
| 277 | 277 | */ |
| 278 | - public function checkConstraintParametersOnPropertyId( PropertyId $propertyId ) { |
|
| 279 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
| 278 | + public function checkConstraintParametersOnPropertyId(PropertyId $propertyId) { |
|
| 279 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
| 280 | 280 | $result = []; |
| 281 | 281 | |
| 282 | - foreach ( $constraints as $constraint ) { |
|
| 283 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
| 282 | + foreach ($constraints as $constraint) { |
|
| 283 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
| 284 | 284 | |
| 285 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
| 285 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
| 286 | 286 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
| 287 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
| 287 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | $result[$constraint->getConstraintId()] = $problems; |
@@ -301,18 +301,18 @@ discard block |
||
| 301 | 301 | * @return ConstraintParameterException[]|null list of constraint parameter exceptions |
| 302 | 302 | * (empty means all parameters okay), or null if constraint is not found |
| 303 | 303 | */ |
| 304 | - public function checkConstraintParametersOnConstraintId( $constraintId ) { |
|
| 305 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
| 304 | + public function checkConstraintParametersOnConstraintId($constraintId) { |
|
| 305 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
| 306 | 306 | '@phan-var PropertyId $propertyId'; |
| 307 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
| 307 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
| 308 | 308 | |
| 309 | - foreach ( $constraints as $constraint ) { |
|
| 310 | - if ( $constraint->getConstraintId() === $constraintId ) { |
|
| 311 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
| 309 | + foreach ($constraints as $constraint) { |
|
| 310 | + if ($constraint->getConstraintId() === $constraintId) { |
|
| 311 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
| 312 | 312 | |
| 313 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
| 313 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
| 314 | 314 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
| 315 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
| 315 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | return $problems; |
@@ -337,14 +337,14 @@ discard block |
||
| 337 | 337 | $result = []; |
| 338 | 338 | |
| 339 | 339 | /** @var Statement $statement */ |
| 340 | - foreach ( $entity->getStatements() as $statement ) { |
|
| 341 | - $result = array_merge( $result, |
|
| 340 | + foreach ($entity->getStatements() as $statement) { |
|
| 341 | + $result = array_merge($result, |
|
| 342 | 342 | $this->checkStatement( |
| 343 | 343 | $entity, |
| 344 | 344 | $statement, |
| 345 | 345 | $constraintIds, |
| 346 | 346 | $defaultResultsPerContext |
| 347 | - ) ); |
|
| 347 | + )); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | return $result; |
@@ -366,32 +366,32 @@ discard block |
||
| 366 | 366 | ) { |
| 367 | 367 | $result = []; |
| 368 | 368 | |
| 369 | - $result = array_merge( $result, |
|
| 369 | + $result = array_merge($result, |
|
| 370 | 370 | $this->checkConstraintsForMainSnak( |
| 371 | 371 | $entity, |
| 372 | 372 | $statement, |
| 373 | 373 | $constraintIds, |
| 374 | 374 | $defaultResultsPerContext |
| 375 | - ) ); |
|
| 375 | + )); |
|
| 376 | 376 | |
| 377 | - if ( $this->checkQualifiers ) { |
|
| 378 | - $result = array_merge( $result, |
|
| 377 | + if ($this->checkQualifiers) { |
|
| 378 | + $result = array_merge($result, |
|
| 379 | 379 | $this->checkConstraintsForQualifiers( |
| 380 | 380 | $entity, |
| 381 | 381 | $statement, |
| 382 | 382 | $constraintIds, |
| 383 | 383 | $defaultResultsPerContext |
| 384 | - ) ); |
|
| 384 | + )); |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | - if ( $this->checkReferences ) { |
|
| 388 | - $result = array_merge( $result, |
|
| 387 | + if ($this->checkReferences) { |
|
| 388 | + $result = array_merge($result, |
|
| 389 | 389 | $this->checkConstraintsForReferences( |
| 390 | 390 | $entity, |
| 391 | 391 | $statement, |
| 392 | 392 | $constraintIds, |
| 393 | 393 | $defaultResultsPerContext |
| 394 | - ) ); |
|
| 394 | + )); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | return $result; |
@@ -406,12 +406,12 @@ discard block |
||
| 406 | 406 | * @param string[]|null $constraintIds |
| 407 | 407 | * @return Constraint[] |
| 408 | 408 | */ |
| 409 | - private function getConstraintsToUse( PropertyId $propertyId, array $constraintIds = null ) { |
|
| 410 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
| 411 | - if ( $constraintIds !== null ) { |
|
| 409 | + private function getConstraintsToUse(PropertyId $propertyId, array $constraintIds = null) { |
|
| 410 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
| 411 | + if ($constraintIds !== null) { |
|
| 412 | 412 | $constraintsToUse = []; |
| 413 | - foreach ( $constraints as $constraint ) { |
|
| 414 | - if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) { |
|
| 413 | + foreach ($constraints as $constraint) { |
|
| 414 | + if (in_array($constraint->getConstraintId(), $constraintIds)) { |
|
| 415 | 415 | $constraintsToUse[] = $constraint; |
| 416 | 416 | } |
| 417 | 417 | } |
@@ -435,18 +435,18 @@ discard block |
||
| 435 | 435 | array $constraintIds = null, |
| 436 | 436 | callable $defaultResults = null |
| 437 | 437 | ) { |
| 438 | - $context = new MainSnakContext( $entity, $statement ); |
|
| 438 | + $context = new MainSnakContext($entity, $statement); |
|
| 439 | 439 | $constraints = $this->getConstraintsToUse( |
| 440 | 440 | $statement->getPropertyId(), |
| 441 | 441 | $constraintIds |
| 442 | 442 | ); |
| 443 | - $result = $defaultResults !== null ? $defaultResults( $context ) : []; |
|
| 443 | + $result = $defaultResults !== null ? $defaultResults($context) : []; |
|
| 444 | 444 | |
| 445 | - foreach ( $constraints as $constraint ) { |
|
| 445 | + foreach ($constraints as $constraint) { |
|
| 446 | 446 | $parameters = $constraint->getConstraintParameters(); |
| 447 | 447 | try { |
| 448 | - $exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters ); |
|
| 449 | - } catch ( ConstraintParameterException $e ) { |
|
| 448 | + $exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters); |
|
| 449 | + } catch (ConstraintParameterException $e) { |
|
| 450 | 450 | $result[] = new CheckResult( |
| 451 | 451 | $context, |
| 452 | 452 | $constraint, |
@@ -456,13 +456,13 @@ discard block |
||
| 456 | 456 | continue; |
| 457 | 457 | } |
| 458 | 458 | |
| 459 | - if ( in_array( $entity->getId(), $exceptions ) ) { |
|
| 460 | - $message = new ViolationMessage( 'wbqc-violation-message-exception' ); |
|
| 461 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message ); |
|
| 459 | + if (in_array($entity->getId(), $exceptions)) { |
|
| 460 | + $message = new ViolationMessage('wbqc-violation-message-exception'); |
|
| 461 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message); |
|
| 462 | 462 | continue; |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | - $result[] = $this->getCheckResultFor( $context, $constraint ); |
|
| 465 | + $result[] = $this->getCheckResultFor($context, $constraint); |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | return $result; |
@@ -484,24 +484,24 @@ discard block |
||
| 484 | 484 | ) { |
| 485 | 485 | $result = []; |
| 486 | 486 | |
| 487 | - if ( in_array( |
|
| 487 | + if (in_array( |
|
| 488 | 488 | $statement->getPropertyId()->getSerialization(), |
| 489 | 489 | $this->propertiesWithViolatingQualifiers |
| 490 | - ) ) { |
|
| 490 | + )) { |
|
| 491 | 491 | return $result; |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | - foreach ( $statement->getQualifiers() as $qualifier ) { |
|
| 495 | - $qualifierContext = new QualifierContext( $entity, $statement, $qualifier ); |
|
| 496 | - if ( $defaultResultsPerContext !== null ) { |
|
| 497 | - $result = array_merge( $result, $defaultResultsPerContext( $qualifierContext ) ); |
|
| 494 | + foreach ($statement->getQualifiers() as $qualifier) { |
|
| 495 | + $qualifierContext = new QualifierContext($entity, $statement, $qualifier); |
|
| 496 | + if ($defaultResultsPerContext !== null) { |
|
| 497 | + $result = array_merge($result, $defaultResultsPerContext($qualifierContext)); |
|
| 498 | 498 | } |
| 499 | 499 | $qualifierConstraints = $this->getConstraintsToUse( |
| 500 | 500 | $qualifierContext->getSnak()->getPropertyId(), |
| 501 | 501 | $constraintIds |
| 502 | 502 | ); |
| 503 | - foreach ( $qualifierConstraints as $qualifierConstraint ) { |
|
| 504 | - $result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint ); |
|
| 503 | + foreach ($qualifierConstraints as $qualifierConstraint) { |
|
| 504 | + $result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint); |
|
| 505 | 505 | } |
| 506 | 506 | } |
| 507 | 507 | |
@@ -525,19 +525,19 @@ discard block |
||
| 525 | 525 | $result = []; |
| 526 | 526 | |
| 527 | 527 | /** @var Reference $reference */ |
| 528 | - foreach ( $statement->getReferences() as $reference ) { |
|
| 529 | - foreach ( $reference->getSnaks() as $snak ) { |
|
| 528 | + foreach ($statement->getReferences() as $reference) { |
|
| 529 | + foreach ($reference->getSnaks() as $snak) { |
|
| 530 | 530 | $referenceContext = new ReferenceContext( |
| 531 | 531 | $entity, $statement, $reference, $snak |
| 532 | 532 | ); |
| 533 | - if ( $defaultResultsPerContext !== null ) { |
|
| 534 | - $result = array_merge( $result, $defaultResultsPerContext( $referenceContext ) ); |
|
| 533 | + if ($defaultResultsPerContext !== null) { |
|
| 534 | + $result = array_merge($result, $defaultResultsPerContext($referenceContext)); |
|
| 535 | 535 | } |
| 536 | 536 | $referenceConstraints = $this->getConstraintsToUse( |
| 537 | 537 | $referenceContext->getSnak()->getPropertyId(), |
| 538 | 538 | $constraintIds |
| 539 | 539 | ); |
| 540 | - foreach ( $referenceConstraints as $referenceConstraint ) { |
|
| 540 | + foreach ($referenceConstraints as $referenceConstraint) { |
|
| 541 | 541 | $result[] = $this->getCheckResultFor( |
| 542 | 542 | $referenceContext, |
| 543 | 543 | $referenceConstraint |
@@ -556,20 +556,20 @@ discard block |
||
| 556 | 556 | * @throws InvalidArgumentException |
| 557 | 557 | * @return CheckResult |
| 558 | 558 | */ |
| 559 | - private function getCheckResultFor( Context $context, Constraint $constraint ) { |
|
| 560 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
| 559 | + private function getCheckResultFor(Context $context, Constraint $constraint) { |
|
| 560 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
| 561 | 561 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
| 562 | - $result = $this->handleScope( $checker, $context, $constraint ); |
|
| 562 | + $result = $this->handleScope($checker, $context, $constraint); |
|
| 563 | 563 | |
| 564 | - if ( $result !== null ) { |
|
| 565 | - $this->addMetadata( $context, $result ); |
|
| 564 | + if ($result !== null) { |
|
| 565 | + $this->addMetadata($context, $result); |
|
| 566 | 566 | return $result; |
| 567 | 567 | } |
| 568 | 568 | |
| 569 | - $startTime = microtime( true ); |
|
| 569 | + $startTime = microtime(true); |
|
| 570 | 570 | try { |
| 571 | - $result = $checker->checkConstraint( $context, $constraint ); |
|
| 572 | - } catch ( ConstraintParameterException $e ) { |
|
| 571 | + $result = $checker->checkConstraint($context, $constraint); |
|
| 572 | + } catch (ConstraintParameterException $e) { |
|
| 573 | 573 | $result = new CheckResult( |
| 574 | 574 | $context, |
| 575 | 575 | $constraint, |
@@ -577,28 +577,28 @@ discard block |
||
| 577 | 577 | CheckResult::STATUS_BAD_PARAMETERS, |
| 578 | 578 | $e->getViolationMessage() |
| 579 | 579 | ); |
| 580 | - } catch ( SparqlHelperException $e ) { |
|
| 581 | - $message = new ViolationMessage( 'wbqc-violation-message-sparql-error' ); |
|
| 582 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, $message ); |
|
| 580 | + } catch (SparqlHelperException $e) { |
|
| 581 | + $message = new ViolationMessage('wbqc-violation-message-sparql-error'); |
|
| 582 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, $message); |
|
| 583 | 583 | } |
| 584 | - $endTime = microtime( true ); |
|
| 584 | + $endTime = microtime(true); |
|
| 585 | 585 | |
| 586 | - $this->addMetadata( $context, $result ); |
|
| 586 | + $this->addMetadata($context, $result); |
|
| 587 | 587 | |
| 588 | - $this->downgradeResultStatus( $context, $result ); |
|
| 588 | + $this->downgradeResultStatus($context, $result); |
|
| 589 | 589 | |
| 590 | 590 | $this->loggingHelper->logConstraintCheck( |
| 591 | 591 | $context, |
| 592 | 592 | $constraint, |
| 593 | 593 | $result, |
| 594 | - get_class( $checker ), |
|
| 594 | + get_class($checker), |
|
| 595 | 595 | $endTime - $startTime, |
| 596 | 596 | __METHOD__ |
| 597 | 597 | ); |
| 598 | 598 | |
| 599 | 599 | return $result; |
| 600 | 600 | } else { |
| 601 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
| 601 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
| 602 | 602 | } |
| 603 | 603 | } |
| 604 | 604 | |
@@ -612,61 +612,61 @@ discard block |
||
| 612 | 612 | $constraint->getConstraintParameters(), |
| 613 | 613 | $constraint->getConstraintTypeItemId() |
| 614 | 614 | ); |
| 615 | - } catch ( ConstraintParameterException $e ) { |
|
| 616 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
| 615 | + } catch (ConstraintParameterException $e) { |
|
| 616 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
| 617 | 617 | } |
| 618 | - if ( $checkedContextTypes === null ) { |
|
| 618 | + if ($checkedContextTypes === null) { |
|
| 619 | 619 | $checkedContextTypes = $checker->getDefaultContextTypes(); |
| 620 | 620 | } |
| 621 | - if ( !in_array( $context->getType(), $checkedContextTypes ) ) { |
|
| 622 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null ); |
|
| 621 | + if (!in_array($context->getType(), $checkedContextTypes)) { |
|
| 622 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null); |
|
| 623 | 623 | } |
| 624 | - if ( $checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO ) { |
|
| 625 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
| 624 | + if ($checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO) { |
|
| 625 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
| 626 | 626 | } |
| 627 | 627 | return null; |
| 628 | 628 | } |
| 629 | 629 | |
| 630 | - private function addMetadata( Context $context, CheckResult $result ) { |
|
| 631 | - $result->withMetadata( Metadata::merge( [ |
|
| 630 | + private function addMetadata(Context $context, CheckResult $result) { |
|
| 631 | + $result->withMetadata(Metadata::merge([ |
|
| 632 | 632 | $result->getMetadata(), |
| 633 | - Metadata::ofDependencyMetadata( DependencyMetadata::merge( [ |
|
| 634 | - DependencyMetadata::ofEntityId( $context->getEntity()->getId() ), |
|
| 635 | - DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ), |
|
| 636 | - ] ) ), |
|
| 637 | - ] ) ); |
|
| 633 | + Metadata::ofDependencyMetadata(DependencyMetadata::merge([ |
|
| 634 | + DependencyMetadata::ofEntityId($context->getEntity()->getId()), |
|
| 635 | + DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()), |
|
| 636 | + ])), |
|
| 637 | + ])); |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | - private function downgradeResultStatus( Context $context, CheckResult &$result ) { |
|
| 640 | + private function downgradeResultStatus(Context $context, CheckResult &$result) { |
|
| 641 | 641 | $constraint = $result->getConstraint(); |
| 642 | 642 | try { |
| 643 | 643 | $constraintStatus = $this->constraintParameterParser |
| 644 | - ->parseConstraintStatusParameter( $constraint->getConstraintParameters() ); |
|
| 645 | - } catch ( ConstraintParameterException $e ) { |
|
| 646 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
| 644 | + ->parseConstraintStatusParameter($constraint->getConstraintParameters()); |
|
| 645 | + } catch (ConstraintParameterException $e) { |
|
| 646 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
| 647 | 647 | $constraintStatus = null; |
| 648 | 648 | } |
| 649 | - if ( $constraintStatus === null ) { |
|
| 649 | + if ($constraintStatus === null) { |
|
| 650 | 650 | // downgrade violation to warning |
| 651 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
| 652 | - $result->setStatus( CheckResult::STATUS_WARNING ); |
|
| 651 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
| 652 | + $result->setStatus(CheckResult::STATUS_WARNING); |
|
| 653 | 653 | } |
| 654 | - } elseif ( $constraintStatus === 'suggestion' ) { |
|
| 654 | + } elseif ($constraintStatus === 'suggestion') { |
|
| 655 | 655 | // downgrade violation to suggestion |
| 656 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
| 657 | - $result->setStatus( CheckResult::STATUS_SUGGESTION ); |
|
| 656 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
| 657 | + $result->setStatus(CheckResult::STATUS_SUGGESTION); |
|
| 658 | 658 | } |
| 659 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
| 659 | + $result->addParameter('constraint_status', $constraintStatus); |
|
| 660 | 660 | } else { |
| 661 | - if ( $constraintStatus !== 'mandatory' ) { |
|
| 661 | + if ($constraintStatus !== 'mandatory') { |
|
| 662 | 662 | // @codeCoverageIgnoreStart |
| 663 | 663 | throw new LogicException( |
| 664 | - "Unknown constraint status '$constraintStatus', " . |
|
| 664 | + "Unknown constraint status '$constraintStatus', ". |
|
| 665 | 665 | "only known statuses are 'mandatory' and 'suggestion'" |
| 666 | 666 | ); |
| 667 | 667 | // @codeCoverageIgnoreEnd |
| 668 | 668 | } |
| 669 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
| 669 | + $result->addParameter('constraint_status', $constraintStatus); |
|
| 670 | 670 | } |
| 671 | 671 | } |
| 672 | 672 | |
@@ -675,12 +675,12 @@ discard block |
||
| 675 | 675 | * |
| 676 | 676 | * @return CheckResult[] |
| 677 | 677 | */ |
| 678 | - private function sortResult( array $result ) { |
|
| 679 | - if ( count( $result ) < 2 ) { |
|
| 678 | + private function sortResult(array $result) { |
|
| 679 | + if (count($result) < 2) { |
|
| 680 | 680 | return $result; |
| 681 | 681 | } |
| 682 | 682 | |
| 683 | - $sortFunction = function ( CheckResult $a, CheckResult $b ) { |
|
| 683 | + $sortFunction = function(CheckResult $a, CheckResult $b) { |
|
| 684 | 684 | $orderNum = 0; |
| 685 | 685 | $order = [ |
| 686 | 686 | CheckResult::STATUS_BAD_PARAMETERS => $orderNum++, |
@@ -697,55 +697,55 @@ discard block |
||
| 697 | 697 | $statusA = $a->getStatus(); |
| 698 | 698 | $statusB = $b->getStatus(); |
| 699 | 699 | |
| 700 | - $orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ]; |
|
| 701 | - $orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ]; |
|
| 700 | + $orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other']; |
|
| 701 | + $orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other']; |
|
| 702 | 702 | |
| 703 | - if ( $orderA === $orderB ) { |
|
| 703 | + if ($orderA === $orderB) { |
|
| 704 | 704 | $cursorA = $a->getContextCursor(); |
| 705 | 705 | $cursorB = $b->getContextCursor(); |
| 706 | 706 | |
| 707 | - if ( $cursorA instanceof EntityContextCursor ) { |
|
| 707 | + if ($cursorA instanceof EntityContextCursor) { |
|
| 708 | 708 | return $cursorB instanceof EntityContextCursor ? 0 : -1; |
| 709 | 709 | } |
| 710 | - if ( $cursorB instanceof EntityContextCursor ) { |
|
| 710 | + if ($cursorB instanceof EntityContextCursor) { |
|
| 711 | 711 | return $cursorA instanceof EntityContextCursor ? 0 : 1; |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | 714 | $pidA = $cursorA->getSnakPropertyId(); |
| 715 | 715 | $pidB = $cursorB->getSnakPropertyId(); |
| 716 | 716 | |
| 717 | - if ( $pidA === $pidB ) { |
|
| 717 | + if ($pidA === $pidB) { |
|
| 718 | 718 | $hashA = $cursorA->getSnakHash(); |
| 719 | 719 | $hashB = $cursorB->getSnakHash(); |
| 720 | 720 | |
| 721 | - if ( $hashA === $hashB ) { |
|
| 722 | - if ( $a instanceof NullResult ) { |
|
| 721 | + if ($hashA === $hashB) { |
|
| 722 | + if ($a instanceof NullResult) { |
|
| 723 | 723 | return $b instanceof NullResult ? 0 : -1; |
| 724 | 724 | } |
| 725 | - if ( $b instanceof NullResult ) { |
|
| 725 | + if ($b instanceof NullResult) { |
|
| 726 | 726 | return $a instanceof NullResult ? 0 : 1; |
| 727 | 727 | } |
| 728 | 728 | |
| 729 | 729 | $typeA = $a->getConstraint()->getConstraintTypeItemId(); |
| 730 | 730 | $typeB = $b->getConstraint()->getConstraintTypeItemId(); |
| 731 | 731 | |
| 732 | - if ( $typeA == $typeB ) { |
|
| 732 | + if ($typeA == $typeB) { |
|
| 733 | 733 | return 0; |
| 734 | 734 | } else { |
| 735 | - return ( $typeA > $typeB ) ? 1 : -1; |
|
| 735 | + return ($typeA > $typeB) ? 1 : -1; |
|
| 736 | 736 | } |
| 737 | 737 | } else { |
| 738 | - return ( $hashA > $hashB ) ? 1 : -1; |
|
| 738 | + return ($hashA > $hashB) ? 1 : -1; |
|
| 739 | 739 | } |
| 740 | 740 | } else { |
| 741 | - return ( $pidA > $pidB ) ? 1 : -1; |
|
| 741 | + return ($pidA > $pidB) ? 1 : -1; |
|
| 742 | 742 | } |
| 743 | 743 | } else { |
| 744 | - return ( $orderA > $orderB ) ? 1 : -1; |
|
| 744 | + return ($orderA > $orderB) ? 1 : -1; |
|
| 745 | 745 | } |
| 746 | 746 | }; |
| 747 | 747 | |
| 748 | - uasort( $result, $sortFunction ); |
|
| 748 | + uasort($result, $sortFunction); |
|
| 749 | 749 | |
| 750 | 750 | return $result; |
| 751 | 751 | } |
@@ -9,10 +9,10 @@ discard block |
||
| 9 | 9 | use WikibaseQuality\ConstraintReport\Job\UpdateConstraintsTableJob; |
| 10 | 10 | |
| 11 | 11 | // @codeCoverageIgnoreStart |
| 12 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
| 13 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
| 12 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
| 13 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
| 14 | 14 | |
| 15 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
| 15 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
| 16 | 16 | // @codeCoverageIgnoreEnd |
| 17 | 17 | |
| 18 | 18 | /** |
@@ -37,43 +37,43 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | public function __construct() { |
| 39 | 39 | parent::__construct(); |
| 40 | - $this->newUpdateConstraintsTableJob = function ( $propertyIdSerialization ) { |
|
| 40 | + $this->newUpdateConstraintsTableJob = function($propertyIdSerialization) { |
|
| 41 | 41 | return UpdateConstraintsTableJob::newFromGlobalState( |
| 42 | 42 | Title::newMainPage(), |
| 43 | - [ 'propertyId' => $propertyIdSerialization ] |
|
| 43 | + ['propertyId' => $propertyIdSerialization] |
|
| 44 | 44 | ); |
| 45 | 45 | }; |
| 46 | 46 | |
| 47 | - $this->addDescription( 'Imports property constraints from statements on properties' ); |
|
| 48 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
| 47 | + $this->addDescription('Imports property constraints from statements on properties'); |
|
| 48 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
| 49 | 49 | |
| 50 | 50 | // Wikibase classes are not yet loaded, so setup services in a callback run in execute |
| 51 | 51 | // that can be overridden in tests. |
| 52 | - $this->setupServices = function () { |
|
| 52 | + $this->setupServices = function() { |
|
| 53 | 53 | $repo = WikibaseRepo::getDefaultInstance(); |
| 54 | 54 | $this->propertyInfoLookup = $repo->getStore()->getPropertyInfoLookup(); |
| 55 | 55 | }; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | public function execute() { |
| 59 | - ( $this->setupServices )(); |
|
| 60 | - if ( !$this->getConfig()->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) ) { |
|
| 61 | - $this->error( 'Constraint statements are not enabled. Aborting.' ); |
|
| 59 | + ($this->setupServices)(); |
|
| 60 | + if (!$this->getConfig()->get('WBQualityConstraintsEnableConstraintsImportFromStatements')) { |
|
| 61 | + $this->error('Constraint statements are not enabled. Aborting.'); |
|
| 62 | 62 | return; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - foreach ( $this->propertyInfoLookup->getAllPropertyInfo() as $propertyIdSerialization => $info ) { |
|
| 66 | - $this->output( sprintf( |
|
| 65 | + foreach ($this->propertyInfoLookup->getAllPropertyInfo() as $propertyIdSerialization => $info) { |
|
| 66 | + $this->output(sprintf( |
|
| 67 | 67 | 'Importing constraint statements for % 6s... ', |
| 68 | 68 | $propertyIdSerialization ), |
| 69 | 69 | $propertyIdSerialization |
| 70 | 70 | ); |
| 71 | - $startTime = microtime( true ); |
|
| 72 | - $job = call_user_func( $this->newUpdateConstraintsTableJob, $propertyIdSerialization ); |
|
| 71 | + $startTime = microtime(true); |
|
| 72 | + $job = call_user_func($this->newUpdateConstraintsTableJob, $propertyIdSerialization); |
|
| 73 | 73 | $job->run(); |
| 74 | - $endTime = microtime( true ); |
|
| 75 | - $millis = ( $endTime - $startTime ) * 1000; |
|
| 76 | - $this->output( sprintf( 'done in % 6.2f ms.', $millis ), $propertyIdSerialization ); |
|
| 74 | + $endTime = microtime(true); |
|
| 75 | + $millis = ($endTime - $startTime) * 1000; |
|
| 76 | + $this->output(sprintf('done in % 6.2f ms.', $millis), $propertyIdSerialization); |
|
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | |
@@ -37,25 +37,25 @@ discard block |
||
| 37 | 37 | * @param Title $title |
| 38 | 38 | * @param string[] $params should contain 'entityId' => 'Q1234' |
| 39 | 39 | */ |
| 40 | - public function __construct( Title $title, array $params ) { |
|
| 41 | - parent::__construct( self::COMMAND, $title, $params ); |
|
| 40 | + public function __construct(Title $title, array $params) { |
|
| 41 | + parent::__construct(self::COMMAND, $title, $params); |
|
| 42 | 42 | $this->removeDuplicates = true; |
| 43 | 43 | |
| 44 | - Assert::parameterType( 'string', $params['entityId'], '$params[\'entityId\']' ); |
|
| 44 | + Assert::parameterType('string', $params['entityId'], '$params[\'entityId\']'); |
|
| 45 | 45 | |
| 46 | - $resultSource = ConstraintsServices::getResultsSource( MediaWikiServices::getInstance() ); |
|
| 46 | + $resultSource = ConstraintsServices::getResultsSource(MediaWikiServices::getInstance()); |
|
| 47 | 47 | '@phan-var CachingResultsSource $resultSource'; |
| 48 | 48 | // This job should only ever be used when caching result sources are used. |
| 49 | - $this->setResultsSource( $resultSource ); |
|
| 49 | + $this->setResultsSource($resultSource); |
|
| 50 | 50 | |
| 51 | - $this->setEntityIdParser( WikibaseRepo::getEntityIdParser() ); |
|
| 51 | + $this->setEntityIdParser(WikibaseRepo::getEntityIdParser()); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - public function setResultsSource( CachingResultsSource $resultsSource ) { |
|
| 54 | + public function setResultsSource(CachingResultsSource $resultsSource) { |
|
| 55 | 55 | $this->resultsSource = $resultsSource; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - public function setEntityIdParser( EntityIdParser $parser ) { |
|
| 58 | + public function setEntityIdParser(EntityIdParser $parser) { |
|
| 59 | 59 | $this->entityIdParser = $parser; |
| 60 | 60 | } |
| 61 | 61 | |
@@ -66,19 +66,19 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function run() { |
| 68 | 68 | try { |
| 69 | - $entityId = $this->entityIdParser->parse( $this->params['entityId'] ); |
|
| 70 | - } catch ( EntityIdParsingException $e ) { |
|
| 69 | + $entityId = $this->entityIdParser->parse($this->params['entityId']); |
|
| 70 | + } catch (EntityIdParsingException $e) { |
|
| 71 | 71 | return false; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - $this->checkConstraints( $entityId ); |
|
| 74 | + $this->checkConstraints($entityId); |
|
| 75 | 75 | |
| 76 | 76 | return true; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - private function checkConstraints( EntityId $entityId ) { |
|
| 79 | + private function checkConstraints(EntityId $entityId) { |
|
| 80 | 80 | $this->resultsSource->getResults( |
| 81 | - [ $entityId ], |
|
| 81 | + [$entityId], |
|
| 82 | 82 | [], |
| 83 | 83 | null, |
| 84 | 84 | [] |
@@ -81,14 +81,14 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | $language = $repo->getUserLanguage(); |
| 83 | 83 | $formatterOptions = new FormatterOptions(); |
| 84 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
| 84 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
| 85 | 85 | $valueFormatterFactory = $repo->getValueFormatterFactory(); |
| 86 | - $valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
| 86 | + $valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions); |
|
| 87 | 87 | |
| 88 | 88 | $entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory(); |
| 89 | - $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $language ); |
|
| 89 | + $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($language); |
|
| 90 | 90 | $entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory(); |
| 91 | - $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $language ); |
|
| 91 | + $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($language); |
|
| 92 | 92 | |
| 93 | 93 | $checkResultsRenderer = new CheckResultsRenderer( |
| 94 | 94 | $repo->getEntityTitleLookup(), |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | $name, |
| 107 | 107 | $entityIdParser, |
| 108 | 108 | $repo->getStatementGuidValidator(), |
| 109 | - $repo->getApiHelperFactory( RequestContext::getMain() ), |
|
| 109 | + $repo->getApiHelperFactory(RequestContext::getMain()), |
|
| 110 | 110 | $resultsSource, |
| 111 | 111 | $checkResultsRenderer, |
| 112 | 112 | $dataFactory |
@@ -133,11 +133,11 @@ discard block |
||
| 133 | 133 | CheckResultsRenderer $checkResultsRenderer, |
| 134 | 134 | IBufferingStatsdDataFactory $dataFactory |
| 135 | 135 | ) { |
| 136 | - parent::__construct( $main, $name ); |
|
| 136 | + parent::__construct($main, $name); |
|
| 137 | 137 | $this->entityIdParser = $entityIdParser; |
| 138 | 138 | $this->statementGuidValidator = $statementGuidValidator; |
| 139 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
| 140 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
| 139 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
| 140 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
| 141 | 141 | $this->resultsSource = $resultsSource; |
| 142 | 142 | $this->checkResultsRenderer = $checkResultsRenderer; |
| 143 | 143 | $this->dataFactory = $dataFactory; |
@@ -153,9 +153,9 @@ discard block |
||
| 153 | 153 | |
| 154 | 154 | $params = $this->extractRequestParams(); |
| 155 | 155 | |
| 156 | - $this->validateParameters( $params ); |
|
| 157 | - $entityIds = $this->parseEntityIds( $params ); |
|
| 158 | - $claimIds = $this->parseClaimIds( $params ); |
|
| 156 | + $this->validateParameters($params); |
|
| 157 | + $entityIds = $this->parseEntityIds($params); |
|
| 158 | + $claimIds = $this->parseClaimIds($params); |
|
| 159 | 159 | $constraintIDs = $params[self::PARAM_CONSTRAINT_ID]; |
| 160 | 160 | $statuses = $params[self::PARAM_STATUS]; |
| 161 | 161 | |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | ) |
| 172 | 172 | )->getArray() |
| 173 | 173 | ); |
| 174 | - $this->resultBuilder->markSuccess( 1 ); |
|
| 174 | + $this->resultBuilder->markSuccess(1); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -179,24 +179,24 @@ discard block |
||
| 179 | 179 | * |
| 180 | 180 | * @return EntityId[] |
| 181 | 181 | */ |
| 182 | - private function parseEntityIds( array $params ) { |
|
| 182 | + private function parseEntityIds(array $params) { |
|
| 183 | 183 | $ids = $params[self::PARAM_ID]; |
| 184 | 184 | |
| 185 | - if ( $ids === null ) { |
|
| 185 | + if ($ids === null) { |
|
| 186 | 186 | return []; |
| 187 | - } elseif ( $ids === [] ) { |
|
| 187 | + } elseif ($ids === []) { |
|
| 188 | 188 | $this->errorReporter->dieError( |
| 189 | - 'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
| 189 | + 'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - return array_map( function ( $id ) { |
|
| 192 | + return array_map(function($id) { |
|
| 193 | 193 | try { |
| 194 | - return $this->entityIdParser->parse( $id ); |
|
| 195 | - } catch ( EntityIdParsingException $e ) { |
|
| 194 | + return $this->entityIdParser->parse($id); |
|
| 195 | + } catch (EntityIdParsingException $e) { |
|
| 196 | 196 | $this->errorReporter->dieError( |
| 197 | - "Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] ); |
|
| 197 | + "Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] ); |
|
| 198 | 198 | } |
| 199 | - }, $ids ); |
|
| 199 | + }, $ids); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -204,35 +204,35 @@ discard block |
||
| 204 | 204 | * |
| 205 | 205 | * @return string[] |
| 206 | 206 | */ |
| 207 | - private function parseClaimIds( array $params ) { |
|
| 207 | + private function parseClaimIds(array $params) { |
|
| 208 | 208 | $ids = $params[self::PARAM_CLAIM_ID]; |
| 209 | 209 | |
| 210 | - if ( $ids === null ) { |
|
| 210 | + if ($ids === null) { |
|
| 211 | 211 | return []; |
| 212 | - } elseif ( $ids === [] ) { |
|
| 212 | + } elseif ($ids === []) { |
|
| 213 | 213 | $this->errorReporter->dieError( |
| 214 | - 'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
| 214 | + 'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - foreach ( $ids as $id ) { |
|
| 218 | - if ( !$this->statementGuidValidator->validate( $id ) ) { |
|
| 217 | + foreach ($ids as $id) { |
|
| 218 | + if (!$this->statementGuidValidator->validate($id)) { |
|
| 219 | 219 | $this->errorReporter->dieError( |
| 220 | - "Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] ); |
|
| 220 | + "Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] ); |
|
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | return $ids; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - private function validateParameters( array $params ) { |
|
| 228 | - if ( $params[self::PARAM_CONSTRAINT_ID] !== null |
|
| 229 | - && empty( $params[self::PARAM_CONSTRAINT_ID] ) |
|
| 227 | + private function validateParameters(array $params) { |
|
| 228 | + if ($params[self::PARAM_CONSTRAINT_ID] !== null |
|
| 229 | + && empty($params[self::PARAM_CONSTRAINT_ID]) |
|
| 230 | 230 | ) { |
| 231 | 231 | $paramConstraintId = self::PARAM_CONSTRAINT_ID; |
| 232 | 232 | $this->errorReporter->dieError( |
| 233 | 233 | "If $paramConstraintId is specified, it must be nonempty.", 'no-data' ); |
| 234 | 234 | } |
| 235 | - if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) { |
|
| 235 | + if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) { |
|
| 236 | 236 | $paramId = self::PARAM_ID; |
| 237 | 237 | $paramClaimId = self::PARAM_CLAIM_ID; |
| 238 | 238 | $this->errorReporter->dieError( |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | ], |
| 274 | 274 | ApiBase::PARAM_ISMULTI => true, |
| 275 | 275 | ApiBase::PARAM_ALL => true, |
| 276 | - ApiBase::PARAM_DFLT => implode( '|', CachingResultsSource::CACHED_STATUSES ), |
|
| 276 | + ApiBase::PARAM_DFLT => implode('|', CachingResultsSource::CACHED_STATUSES), |
|
| 277 | 277 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [], |
| 278 | 278 | ], |
| 279 | 279 | ]; |
@@ -36,193 +36,193 @@ |
||
| 36 | 36 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\ValueTypeChecker; |
| 37 | 37 | |
| 38 | 38 | return [ |
| 39 | - ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => function ( MediaWikiServices $services ) { |
|
| 39 | + ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => function(MediaWikiServices $services) { |
|
| 40 | 40 | return new ConflictsWithChecker( |
| 41 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 42 | - ConstraintsServices::getConnectionCheckerHelper( $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 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 49 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
| 48 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 49 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
| 50 | 50 | ); |
| 51 | 51 | }, |
| 52 | 52 | |
| 53 | - ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => function ( MediaWikiServices $services ) { |
|
| 53 | + ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => function(MediaWikiServices $services) { |
|
| 54 | 54 | return new TargetRequiredClaimChecker( |
| 55 | - WikibaseServices::getEntityLookup( $services ), |
|
| 56 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 57 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
| 55 | + WikibaseServices::getEntityLookup($services), |
|
| 56 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 57 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
| 58 | 58 | ); |
| 59 | 59 | }, |
| 60 | 60 | |
| 61 | - ConstraintCheckerServices::SYMMETRIC_CHECKER => function ( MediaWikiServices $services ) { |
|
| 61 | + ConstraintCheckerServices::SYMMETRIC_CHECKER => function(MediaWikiServices $services) { |
|
| 62 | 62 | return new SymmetricChecker( |
| 63 | - WikibaseServices::getEntityLookupWithoutCache( $services ), |
|
| 64 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
| 63 | + WikibaseServices::getEntityLookupWithoutCache($services), |
|
| 64 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
| 65 | 65 | ); |
| 66 | 66 | }, |
| 67 | 67 | |
| 68 | - ConstraintCheckerServices::INVERSE_CHECKER => function ( MediaWikiServices $services ) { |
|
| 68 | + ConstraintCheckerServices::INVERSE_CHECKER => function(MediaWikiServices $services) { |
|
| 69 | 69 | return new InverseChecker( |
| 70 | - WikibaseServices::getEntityLookup( $services ), |
|
| 71 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 72 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
| 70 | + WikibaseServices::getEntityLookup($services), |
|
| 71 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 72 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
| 73 | 73 | ); |
| 74 | 74 | }, |
| 75 | 75 | |
| 76 | - ConstraintCheckerServices::QUALIFIER_CHECKER => function ( MediaWikiServices $services ) { |
|
| 76 | + ConstraintCheckerServices::QUALIFIER_CHECKER => function(MediaWikiServices $services) { |
|
| 77 | 77 | return new QualifierChecker(); |
| 78 | 78 | }, |
| 79 | 79 | |
| 80 | - ConstraintCheckerServices::QUALIFIERS_CHECKER => function ( MediaWikiServices $services ) { |
|
| 80 | + ConstraintCheckerServices::QUALIFIERS_CHECKER => function(MediaWikiServices $services) { |
|
| 81 | 81 | return new QualifiersChecker( |
| 82 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
| 82 | + ConstraintsServices::getConstraintParameterParser($services) |
|
| 83 | 83 | ); |
| 84 | 84 | }, |
| 85 | 85 | |
| 86 | - ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => function ( MediaWikiServices $services ) { |
|
| 86 | + ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => function(MediaWikiServices $services) { |
|
| 87 | 87 | return new MandatoryQualifiersChecker( |
| 88 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
| 88 | + ConstraintsServices::getConstraintParameterParser($services) |
|
| 89 | 89 | ); |
| 90 | 90 | }, |
| 91 | 91 | |
| 92 | - ConstraintCheckerServices::RANGE_CHECKER => function ( MediaWikiServices $services ) { |
|
| 92 | + ConstraintCheckerServices::RANGE_CHECKER => function(MediaWikiServices $services) { |
|
| 93 | 93 | return new RangeChecker( |
| 94 | - WikibaseServices::getPropertyDataTypeLookup( $services ), |
|
| 95 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 96 | - ConstraintsServices::getRangeCheckerHelper( $services ) |
|
| 94 | + WikibaseServices::getPropertyDataTypeLookup($services), |
|
| 95 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 96 | + ConstraintsServices::getRangeCheckerHelper($services) |
|
| 97 | 97 | ); |
| 98 | 98 | }, |
| 99 | 99 | |
| 100 | - ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => function ( MediaWikiServices $services ) { |
|
| 100 | + ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => function(MediaWikiServices $services) { |
|
| 101 | 101 | return new DiffWithinRangeChecker( |
| 102 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 103 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
| 102 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 103 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
| 104 | 104 | $services->getMainConfig() |
| 105 | 105 | ); |
| 106 | 106 | }, |
| 107 | 107 | |
| 108 | - ConstraintCheckerServices::TYPE_CHECKER => function ( MediaWikiServices $services ) { |
|
| 108 | + ConstraintCheckerServices::TYPE_CHECKER => function(MediaWikiServices $services) { |
|
| 109 | 109 | return new TypeChecker( |
| 110 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 111 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
| 110 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 111 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
| 112 | 112 | $services->getMainConfig() |
| 113 | 113 | ); |
| 114 | 114 | }, |
| 115 | 115 | |
| 116 | - ConstraintCheckerServices::VALUE_TYPE_CHECKER => function ( MediaWikiServices $services ) { |
|
| 116 | + ConstraintCheckerServices::VALUE_TYPE_CHECKER => function(MediaWikiServices $services) { |
|
| 117 | 117 | return new ValueTypeChecker( |
| 118 | - WikibaseServices::getEntityLookup( $services ), |
|
| 119 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 120 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
| 118 | + WikibaseServices::getEntityLookup($services), |
|
| 119 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 120 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
| 121 | 121 | $services->getMainConfig() |
| 122 | 122 | ); |
| 123 | 123 | }, |
| 124 | 124 | |
| 125 | - ConstraintCheckerServices::SINGLE_VALUE_CHECKER => function ( MediaWikiServices $services ) { |
|
| 125 | + ConstraintCheckerServices::SINGLE_VALUE_CHECKER => function(MediaWikiServices $services) { |
|
| 126 | 126 | return new SingleValueChecker( |
| 127 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
| 127 | + ConstraintsServices::getConstraintParameterParser($services) |
|
| 128 | 128 | ); |
| 129 | 129 | }, |
| 130 | 130 | |
| 131 | - ConstraintCheckerServices::MULTI_VALUE_CHECKER => function ( MediaWikiServices $services ) { |
|
| 131 | + ConstraintCheckerServices::MULTI_VALUE_CHECKER => function(MediaWikiServices $services) { |
|
| 132 | 132 | return new MultiValueChecker( |
| 133 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
| 133 | + ConstraintsServices::getConstraintParameterParser($services) |
|
| 134 | 134 | ); |
| 135 | 135 | }, |
| 136 | 136 | |
| 137 | - ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => function ( MediaWikiServices $services ) { |
|
| 137 | + ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => function(MediaWikiServices $services) { |
|
| 138 | 138 | // TODO return a different, dummy implementation if SPARQL is not available |
| 139 | 139 | return new UniqueValueChecker( |
| 140 | - ConstraintsServices::getSparqlHelper( $services ) |
|
| 140 | + ConstraintsServices::getSparqlHelper($services) |
|
| 141 | 141 | ); |
| 142 | 142 | }, |
| 143 | 143 | |
| 144 | - ConstraintCheckerServices::FORMAT_CHECKER => function ( MediaWikiServices $services ) { |
|
| 144 | + ConstraintCheckerServices::FORMAT_CHECKER => function(MediaWikiServices $services) { |
|
| 145 | 145 | // TODO return a different, dummy implementation if SPARQL is not available |
| 146 | 146 | return new FormatChecker( |
| 147 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 147 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 148 | 148 | $services->getMainConfig(), |
| 149 | - ConstraintsServices::getSparqlHelper( $services ) |
|
| 149 | + ConstraintsServices::getSparqlHelper($services) |
|
| 150 | 150 | ); |
| 151 | 151 | }, |
| 152 | 152 | |
| 153 | - ConstraintCheckerServices::COMMONS_LINK_CHECKER => function ( MediaWikiServices $services ) { |
|
| 153 | + ConstraintCheckerServices::COMMONS_LINK_CHECKER => function(MediaWikiServices $services) { |
|
| 154 | 154 | $pageNameNormalizer = new MediaWikiPageNameNormalizer(); |
| 155 | 155 | return new CommonsLinkChecker( |
| 156 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 156 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 157 | 157 | $pageNameNormalizer |
| 158 | 158 | ); |
| 159 | 159 | }, |
| 160 | 160 | |
| 161 | - ConstraintCheckerServices::ONE_OF_CHECKER => function ( MediaWikiServices $services ) { |
|
| 161 | + ConstraintCheckerServices::ONE_OF_CHECKER => function(MediaWikiServices $services) { |
|
| 162 | 162 | return new OneOfChecker( |
| 163 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
| 163 | + ConstraintsServices::getConstraintParameterParser($services) |
|
| 164 | 164 | ); |
| 165 | 165 | }, |
| 166 | 166 | |
| 167 | - ConstraintCheckerServices::VALUE_ONLY_CHECKER => function ( MediaWikiServices $services ) { |
|
| 167 | + ConstraintCheckerServices::VALUE_ONLY_CHECKER => function(MediaWikiServices $services) { |
|
| 168 | 168 | return new ValueOnlyChecker(); |
| 169 | 169 | }, |
| 170 | 170 | |
| 171 | - ConstraintCheckerServices::REFERENCE_CHECKER => function ( MediaWikiServices $services ) { |
|
| 171 | + ConstraintCheckerServices::REFERENCE_CHECKER => function(MediaWikiServices $services) { |
|
| 172 | 172 | return new ReferenceChecker(); |
| 173 | 173 | }, |
| 174 | 174 | |
| 175 | - ConstraintCheckerServices::NO_BOUNDS_CHECKER => function ( MediaWikiServices $services ) { |
|
| 175 | + ConstraintCheckerServices::NO_BOUNDS_CHECKER => function(MediaWikiServices $services) { |
|
| 176 | 176 | return new NoBoundsChecker(); |
| 177 | 177 | }, |
| 178 | 178 | |
| 179 | - ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => function ( MediaWikiServices $services ) { |
|
| 179 | + ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => function(MediaWikiServices $services) { |
|
| 180 | 180 | // TODO in the future, get UnitConverter from $services? |
| 181 | 181 | $repo = WikibaseRepo::getDefaultInstance(); |
| 182 | 182 | $unitConverter = $repo->getUnitConverter(); |
| 183 | 183 | |
| 184 | 184 | return new AllowedUnitsChecker( |
| 185 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 185 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 186 | 186 | $unitConverter |
| 187 | 187 | ); |
| 188 | 188 | }, |
| 189 | 189 | |
| 190 | - ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => function ( MediaWikiServices $services ) { |
|
| 190 | + ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => function(MediaWikiServices $services) { |
|
| 191 | 191 | return new SingleBestValueChecker( |
| 192 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
| 192 | + ConstraintsServices::getConstraintParameterParser($services) |
|
| 193 | 193 | ); |
| 194 | 194 | }, |
| 195 | 195 | |
| 196 | - ConstraintCheckerServices::ENTITY_TYPE_CHECKER => function ( MediaWikiServices $services ) { |
|
| 196 | + ConstraintCheckerServices::ENTITY_TYPE_CHECKER => function(MediaWikiServices $services) { |
|
| 197 | 197 | return new EntityTypeChecker( |
| 198 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
| 198 | + ConstraintsServices::getConstraintParameterParser($services) |
|
| 199 | 199 | ); |
| 200 | 200 | }, |
| 201 | 201 | |
| 202 | - ConstraintCheckerServices::NONE_OF_CHECKER => function ( MediaWikiServices $services ) { |
|
| 202 | + ConstraintCheckerServices::NONE_OF_CHECKER => function(MediaWikiServices $services) { |
|
| 203 | 203 | return new NoneOfChecker( |
| 204 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
| 204 | + ConstraintsServices::getConstraintParameterParser($services) |
|
| 205 | 205 | ); |
| 206 | 206 | }, |
| 207 | 207 | |
| 208 | - ConstraintCheckerServices::INTEGER_CHECKER => function ( MediaWikiServices $services ) { |
|
| 208 | + ConstraintCheckerServices::INTEGER_CHECKER => function(MediaWikiServices $services) { |
|
| 209 | 209 | return new IntegerChecker(); |
| 210 | 210 | }, |
| 211 | 211 | |
| 212 | - ConstraintCheckerServices::CITATION_NEEDED_CHECKER => function ( MediaWikiServices $services ) { |
|
| 212 | + ConstraintCheckerServices::CITATION_NEEDED_CHECKER => function(MediaWikiServices $services) { |
|
| 213 | 213 | return new CitationNeededChecker(); |
| 214 | 214 | }, |
| 215 | 215 | |
| 216 | - ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => function ( MediaWikiServices $services ) { |
|
| 216 | + ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => function(MediaWikiServices $services) { |
|
| 217 | 217 | return new PropertyScopeChecker( |
| 218 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
| 218 | + ConstraintsServices::getConstraintParameterParser($services) |
|
| 219 | 219 | ); |
| 220 | 220 | }, |
| 221 | 221 | |
| 222 | - ConstraintCheckerServices::CONTEMPORARY_CHECKER => function ( MediaWikiServices $services ) { |
|
| 222 | + ConstraintCheckerServices::CONTEMPORARY_CHECKER => function(MediaWikiServices $services) { |
|
| 223 | 223 | return new ContemporaryChecker( |
| 224 | - WikibaseServices::getEntityLookup( $services ), |
|
| 225 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
| 224 | + WikibaseServices::getEntityLookup($services), |
|
| 225 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
| 226 | 226 | $services->getMainConfig() |
| 227 | 227 | ); |
| 228 | 228 | }, |
@@ -142,14 +142,14 @@ discard block |
||
| 142 | 142 | ) { |
| 143 | 143 | $results = []; |
| 144 | 144 | $metadatas = []; |
| 145 | - if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
| 145 | + if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
| 146 | 146 | $storedEntityIds = []; |
| 147 | - foreach ( $entityIds as $entityId ) { |
|
| 148 | - $storedResults = $this->getStoredResults( $entityId ); |
|
| 149 | - if ( $storedResults !== null ) { |
|
| 150 | - $this->loggingHelper->logCheckConstraintsCacheHit( $entityId ); |
|
| 151 | - foreach ( $storedResults->getArray() as $checkResult ) { |
|
| 152 | - if ( $this->statusSelected( $statuses, $checkResult ) ) { |
|
| 147 | + foreach ($entityIds as $entityId) { |
|
| 148 | + $storedResults = $this->getStoredResults($entityId); |
|
| 149 | + if ($storedResults !== null) { |
|
| 150 | + $this->loggingHelper->logCheckConstraintsCacheHit($entityId); |
|
| 151 | + foreach ($storedResults->getArray() as $checkResult) { |
|
| 152 | + if ($this->statusSelected($statuses, $checkResult)) { |
|
| 153 | 153 | $results[] = $checkResult; |
| 154 | 154 | } |
| 155 | 155 | } |
@@ -157,19 +157,19 @@ discard block |
||
| 157 | 157 | $storedEntityIds[] = $entityId; |
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | - $entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) ); |
|
| 160 | + $entityIds = array_values(array_diff($entityIds, $storedEntityIds)); |
|
| 161 | 161 | } |
| 162 | - if ( $entityIds !== [] || $claimIds !== [] ) { |
|
| 163 | - if ( $entityIds !== [] ) { |
|
| 164 | - $this->loggingHelper->logCheckConstraintsCacheMisses( $entityIds ); |
|
| 162 | + if ($entityIds !== [] || $claimIds !== []) { |
|
| 163 | + if ($entityIds !== []) { |
|
| 164 | + $this->loggingHelper->logCheckConstraintsCacheMisses($entityIds); |
|
| 165 | 165 | } |
| 166 | - $response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
| 167 | - $results = array_merge( $results, $response->getArray() ); |
|
| 166 | + $response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
| 167 | + $results = array_merge($results, $response->getArray()); |
|
| 168 | 168 | $metadatas[] = $response->getMetadata(); |
| 169 | 169 | } |
| 170 | 170 | return new CachedCheckResults( |
| 171 | 171 | $results, |
| 172 | - Metadata::merge( $metadatas ) |
|
| 172 | + Metadata::merge($metadatas) |
|
| 173 | 173 | ); |
| 174 | 174 | } |
| 175 | 175 | |
@@ -192,13 +192,13 @@ discard block |
||
| 192 | 192 | ?array $constraintIds, |
| 193 | 193 | array $statuses |
| 194 | 194 | ) { |
| 195 | - if ( $claimIds !== [] ) { |
|
| 195 | + if ($claimIds !== []) { |
|
| 196 | 196 | return false; |
| 197 | 197 | } |
| 198 | - if ( $constraintIds !== null ) { |
|
| 198 | + if ($constraintIds !== null) { |
|
| 199 | 199 | return false; |
| 200 | 200 | } |
| 201 | - if ( array_diff( $statuses, self::CACHED_STATUSES ) !== [] ) { |
|
| 201 | + if (array_diff($statuses, self::CACHED_STATUSES) !== []) { |
|
| 202 | 202 | return false; |
| 203 | 203 | } |
| 204 | 204 | return true; |
@@ -213,8 +213,8 @@ discard block |
||
| 213 | 213 | * @param CheckResult $result |
| 214 | 214 | * @return bool |
| 215 | 215 | */ |
| 216 | - private function statusSelected( array $statuses, CheckResult $result ) { |
|
| 217 | - return in_array( $result->getStatus(), $statuses, true ) || |
|
| 216 | + private function statusSelected(array $statuses, CheckResult $result) { |
|
| 217 | + return in_array($result->getStatus(), $statuses, true) || |
|
| 218 | 218 | $result instanceof NullResult; |
| 219 | 219 | } |
| 220 | 220 | |
@@ -231,11 +231,11 @@ discard block |
||
| 231 | 231 | ?array $constraintIds, |
| 232 | 232 | array $statuses |
| 233 | 233 | ) { |
| 234 | - $results = $this->resultsSource->getResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
| 234 | + $results = $this->resultsSource->getResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
| 235 | 235 | |
| 236 | - if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
| 237 | - foreach ( $entityIds as $entityId ) { |
|
| 238 | - $this->storeResults( $entityId, $results ); |
|
| 236 | + if ($this->canStoreResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
| 237 | + foreach ($entityIds as $entityId) { |
|
| 238 | + $this->storeResults($entityId, $results); |
|
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | 241 | |
@@ -266,10 +266,10 @@ discard block |
||
| 266 | 266 | ?array $constraintIds, |
| 267 | 267 | array $statuses |
| 268 | 268 | ) { |
| 269 | - if ( $constraintIds !== null ) { |
|
| 269 | + if ($constraintIds !== null) { |
|
| 270 | 270 | return false; |
| 271 | 271 | } |
| 272 | - if ( array_diff( self::CACHED_STATUSES, $statuses ) !== [] ) { |
|
| 272 | + if (array_diff(self::CACHED_STATUSES, $statuses) !== []) { |
|
| 273 | 273 | return false; |
| 274 | 274 | } |
| 275 | 275 | return true; |
@@ -283,21 +283,21 @@ discard block |
||
| 283 | 283 | * May include check results for other entity IDs as well, |
| 284 | 284 | * or check results with statuses that we’re not interested in caching. |
| 285 | 285 | */ |
| 286 | - private function storeResults( EntityId $entityId, CachedCheckResults $results ) { |
|
| 286 | + private function storeResults(EntityId $entityId, CachedCheckResults $results) { |
|
| 287 | 287 | $latestRevisionIds = $this->getLatestRevisionIds( |
| 288 | 288 | $results->getMetadata()->getDependencyMetadata()->getEntityIds() |
| 289 | 289 | ); |
| 290 | - if ( $latestRevisionIds === null ) { |
|
| 290 | + if ($latestRevisionIds === null) { |
|
| 291 | 291 | return; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | $resultSerializations = []; |
| 295 | - foreach ( $results->getArray() as $checkResult ) { |
|
| 296 | - if ( $checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization() ) { |
|
| 295 | + foreach ($results->getArray() as $checkResult) { |
|
| 296 | + if ($checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization()) { |
|
| 297 | 297 | continue; |
| 298 | 298 | } |
| 299 | - if ( $this->statusSelected( self::CACHED_STATUSES, $checkResult ) ) { |
|
| 300 | - $resultSerializations[] = $this->checkResultSerializer->serialize( $checkResult ); |
|
| 299 | + if ($this->statusSelected(self::CACHED_STATUSES, $checkResult)) { |
|
| 300 | + $resultSerializations[] = $this->checkResultSerializer->serialize($checkResult); |
|
| 301 | 301 | } |
| 302 | 302 | } |
| 303 | 303 | |
@@ -306,11 +306,11 @@ discard block |
||
| 306 | 306 | 'latestRevisionIds' => $latestRevisionIds, |
| 307 | 307 | ]; |
| 308 | 308 | $futureTime = $results->getMetadata()->getDependencyMetadata()->getFutureTime(); |
| 309 | - if ( $futureTime !== null ) { |
|
| 309 | + if ($futureTime !== null) { |
|
| 310 | 310 | $value['futureTime'] = $futureTime->getArrayValue(); |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - $this->cache->set( $entityId, $value, $this->ttlInSeconds ); |
|
| 313 | + $this->cache->set($entityId, $value, $this->ttlInSeconds); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -324,31 +324,30 @@ discard block |
||
| 324 | 324 | EntityId $entityId, |
| 325 | 325 | $forRevision = 0 |
| 326 | 326 | ) { |
| 327 | - $value = $this->cache->get( $entityId, $curTTL, [], $asOf ); |
|
| 328 | - $now = call_user_func( $this->microtime, true ); |
|
| 327 | + $value = $this->cache->get($entityId, $curTTL, [], $asOf); |
|
| 328 | + $now = call_user_func($this->microtime, true); |
|
| 329 | 329 | |
| 330 | - $dependencyMetadata = $this->checkDependencyMetadata( $value, |
|
| 331 | - [ $entityId->getSerialization() => $forRevision ] ); |
|
| 332 | - if ( $dependencyMetadata === null ) { |
|
| 330 | + $dependencyMetadata = $this->checkDependencyMetadata($value, |
|
| 331 | + [$entityId->getSerialization() => $forRevision]); |
|
| 332 | + if ($dependencyMetadata === null) { |
|
| 333 | 333 | return null; |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | - $ageInSeconds = (int)ceil( $now - $asOf ); |
|
| 336 | + $ageInSeconds = (int) ceil($now - $asOf); |
|
| 337 | 337 | $cachingMetadata = $ageInSeconds > 0 ? |
| 338 | - CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) : |
|
| 339 | - CachingMetadata::fresh(); |
|
| 338 | + CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh(); |
|
| 340 | 339 | |
| 341 | 340 | $results = []; |
| 342 | - foreach ( $value['results'] as $resultSerialization ) { |
|
| 343 | - $results[] = $this->deserializeCheckResult( $resultSerialization, $cachingMetadata ); |
|
| 341 | + foreach ($value['results'] as $resultSerialization) { |
|
| 342 | + $results[] = $this->deserializeCheckResult($resultSerialization, $cachingMetadata); |
|
| 344 | 343 | } |
| 345 | 344 | |
| 346 | 345 | return new CachedCheckResults( |
| 347 | 346 | $results, |
| 348 | - Metadata::merge( [ |
|
| 349 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
| 350 | - Metadata::ofDependencyMetadata( $dependencyMetadata ), |
|
| 351 | - ] ) |
|
| 347 | + Metadata::merge([ |
|
| 348 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
| 349 | + Metadata::ofDependencyMetadata($dependencyMetadata), |
|
| 350 | + ]) |
|
| 352 | 351 | ); |
| 353 | 352 | } |
| 354 | 353 | |
@@ -364,43 +363,43 @@ discard block |
||
| 364 | 363 | * @return DependencyMetadata|null the dependency metadata, |
| 365 | 364 | * or null if $value should no longer be used |
| 366 | 365 | */ |
| 367 | - private function checkDependencyMetadata( $value, $paramRevs ) { |
|
| 368 | - if ( $value === false ) { |
|
| 366 | + private function checkDependencyMetadata($value, $paramRevs) { |
|
| 367 | + if ($value === false) { |
|
| 369 | 368 | return null; |
| 370 | 369 | } |
| 371 | 370 | |
| 372 | - if ( array_key_exists( 'futureTime', $value ) ) { |
|
| 373 | - $futureTime = TimeValue::newFromArray( $value['futureTime'] ); |
|
| 374 | - if ( !$this->timeValueComparer->isFutureTime( $futureTime ) ) { |
|
| 371 | + if (array_key_exists('futureTime', $value)) { |
|
| 372 | + $futureTime = TimeValue::newFromArray($value['futureTime']); |
|
| 373 | + if (!$this->timeValueComparer->isFutureTime($futureTime)) { |
|
| 375 | 374 | return null; |
| 376 | 375 | } |
| 377 | - $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime( $futureTime ); |
|
| 376 | + $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime($futureTime); |
|
| 378 | 377 | } else { |
| 379 | 378 | $futureTimeDependencyMetadata = DependencyMetadata::blank(); |
| 380 | 379 | } |
| 381 | 380 | |
| 382 | - foreach ( $paramRevs as $id => $revision ) { |
|
| 383 | - if ( $revision > 0 ) { |
|
| 384 | - $value['latestRevisionIds'][$id] = min( $revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX ); |
|
| 381 | + foreach ($paramRevs as $id => $revision) { |
|
| 382 | + if ($revision > 0) { |
|
| 383 | + $value['latestRevisionIds'][$id] = min($revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX); |
|
| 385 | 384 | } |
| 386 | 385 | } |
| 387 | 386 | |
| 388 | 387 | $dependedEntityIds = array_map( |
| 389 | - [ $this->entityIdParser, "parse" ], |
|
| 390 | - array_keys( $value['latestRevisionIds'] ) |
|
| 388 | + [$this->entityIdParser, "parse"], |
|
| 389 | + array_keys($value['latestRevisionIds']) |
|
| 391 | 390 | ); |
| 392 | 391 | |
| 393 | - if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) { |
|
| 392 | + if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) { |
|
| 394 | 393 | return null; |
| 395 | 394 | } |
| 396 | 395 | |
| 397 | 396 | return array_reduce( |
| 398 | 397 | $dependedEntityIds, |
| 399 | - function ( DependencyMetadata $metadata, EntityId $entityId ) { |
|
| 400 | - return DependencyMetadata::merge( [ |
|
| 398 | + function(DependencyMetadata $metadata, EntityId $entityId) { |
|
| 399 | + return DependencyMetadata::merge([ |
|
| 401 | 400 | $metadata, |
| 402 | - DependencyMetadata::ofEntityId( $entityId ) |
|
| 403 | - ] ); |
|
| 401 | + DependencyMetadata::ofEntityId($entityId) |
|
| 402 | + ]); |
|
| 404 | 403 | }, |
| 405 | 404 | $futureTimeDependencyMetadata |
| 406 | 405 | ); |
@@ -420,13 +419,13 @@ discard block |
||
| 420 | 419 | array $resultSerialization, |
| 421 | 420 | CachingMetadata $cachingMetadata |
| 422 | 421 | ) { |
| 423 | - $result = $this->checkResultDeserializer->deserialize( $resultSerialization ); |
|
| 424 | - if ( $this->isPossiblyStaleResult( $result ) ) { |
|
| 422 | + $result = $this->checkResultDeserializer->deserialize($resultSerialization); |
|
| 423 | + if ($this->isPossiblyStaleResult($result)) { |
|
| 425 | 424 | $result->withMetadata( |
| 426 | - Metadata::merge( [ |
|
| 425 | + Metadata::merge([ |
|
| 427 | 426 | $result->getMetadata(), |
| 428 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
| 429 | - ] ) |
|
| 427 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
| 428 | + ]) |
|
| 430 | 429 | ); |
| 431 | 430 | } |
| 432 | 431 | return $result; |
@@ -436,8 +435,8 @@ discard block |
||
| 436 | 435 | * @param CheckResult $result |
| 437 | 436 | * @return bool |
| 438 | 437 | */ |
| 439 | - private function isPossiblyStaleResult( CheckResult $result ) { |
|
| 440 | - if ( $result instanceof NullResult ) { |
|
| 438 | + private function isPossiblyStaleResult(CheckResult $result) { |
|
| 439 | + if ($result instanceof NullResult) { |
|
| 441 | 440 | return false; |
| 442 | 441 | } |
| 443 | 442 | |
@@ -452,14 +451,14 @@ discard block |
||
| 452 | 451 | * @return int[]|null array from entity ID serializations to revision ID, |
| 453 | 452 | * or null to indicate that not all revision IDs could be loaded |
| 454 | 453 | */ |
| 455 | - private function getLatestRevisionIds( array $entityIds ) { |
|
| 456 | - if ( $entityIds === [] ) { |
|
| 454 | + private function getLatestRevisionIds(array $entityIds) { |
|
| 455 | + if ($entityIds === []) { |
|
| 457 | 456 | $this->loggingHelper->logEmptyDependencyMetadata(); |
| 458 | 457 | return []; |
| 459 | 458 | } |
| 460 | - if ( count( $entityIds ) > $this->maxRevisionIds ) { |
|
| 459 | + if (count($entityIds) > $this->maxRevisionIds) { |
|
| 461 | 460 | // one of those entities will probably be edited soon, so might as well skip caching |
| 462 | - $this->loggingHelper->logHugeDependencyMetadata( $entityIds, $this->maxRevisionIds ); |
|
| 461 | + $this->loggingHelper->logHugeDependencyMetadata($entityIds, $this->maxRevisionIds); |
|
| 463 | 462 | return null; |
| 464 | 463 | } |
| 465 | 464 | |
@@ -467,7 +466,7 @@ discard block |
||
| 467 | 466 | $entityIds, |
| 468 | 467 | LookupConstants::LATEST_FROM_REPLICA |
| 469 | 468 | ); |
| 470 | - if ( $this->hasFalseElements( $latestRevisionIds ) ) { |
|
| 469 | + if ($this->hasFalseElements($latestRevisionIds)) { |
|
| 471 | 470 | return null; |
| 472 | 471 | } |
| 473 | 472 | return $latestRevisionIds; |
@@ -477,8 +476,8 @@ discard block |
||
| 477 | 476 | * @param array $array |
| 478 | 477 | * @return bool |
| 479 | 478 | */ |
| 480 | - private function hasFalseElements( array $array ) { |
|
| 481 | - return in_array( false, $array, true ); |
|
| 479 | + private function hasFalseElements(array $array) { |
|
| 480 | + return in_array(false, $array, true); |
|
| 482 | 481 | } |
| 483 | 482 | |
| 484 | 483 | /** |
@@ -486,7 +485,7 @@ discard block |
||
| 486 | 485 | * |
| 487 | 486 | * @param callable $microtime |
| 488 | 487 | */ |
| 489 | - public function setMicrotimeFunction( callable $microtime ) { |
|
| 488 | + public function setMicrotimeFunction(callable $microtime) { |
|
| 490 | 489 | $this->microtime = $microtime; |
| 491 | 490 | } |
| 492 | 491 | |
@@ -75,17 +75,17 @@ discard block |
||
| 75 | 75 | DelegatingConstraintChecker $delegatingConstraintChecker |
| 76 | 76 | ): self { |
| 77 | 77 | $repo = WikibaseRepo::getDefaultInstance(); |
| 78 | - $helperFactory = $repo->getApiHelperFactory( RequestContext::getMain() ); |
|
| 78 | + $helperFactory = $repo->getApiHelperFactory(RequestContext::getMain()); |
|
| 79 | 79 | $language = $repo->getUserLanguage(); |
| 80 | 80 | |
| 81 | 81 | $entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory(); |
| 82 | 82 | $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory |
| 83 | - ->getEntityIdFormatter( $language ); |
|
| 83 | + ->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 | 87 | $dataValueFormatter = $valueFormatterFactory |
| 88 | - ->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
| 88 | + ->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions); |
|
| 89 | 89 | $violationMessageRenderer = new MultilingualTextViolationMessageRenderer( |
| 90 | 90 | $entityIdHtmlLinkFormatter, |
| 91 | 91 | $dataValueFormatter, |
@@ -121,9 +121,9 @@ discard block |
||
| 121 | 121 | StatementGuidParser $statementGuidParser, |
| 122 | 122 | IBufferingStatsdDataFactory $dataFactory |
| 123 | 123 | ) { |
| 124 | - parent::__construct( $main, $name ); |
|
| 124 | + parent::__construct($main, $name); |
|
| 125 | 125 | |
| 126 | - $this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
| 126 | + $this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this); |
|
| 127 | 127 | $this->delegatingConstraintChecker = $delegatingConstraintChecker; |
| 128 | 128 | $this->violationMessageRenderer = $violationMessageRenderer; |
| 129 | 129 | $this->statementGuidParser = $statementGuidParser; |
@@ -138,39 +138,39 @@ discard block |
||
| 138 | 138 | $params = $this->extractRequestParams(); |
| 139 | 139 | $result = $this->getResult(); |
| 140 | 140 | |
| 141 | - $propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] ); |
|
| 142 | - $constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] ); |
|
| 141 | + $propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]); |
|
| 142 | + $constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]); |
|
| 143 | 143 | |
| 144 | - $this->checkPropertyIds( $propertyIds, $result ); |
|
| 145 | - $this->checkConstraintIds( $constraintIds, $result ); |
|
| 144 | + $this->checkPropertyIds($propertyIds, $result); |
|
| 145 | + $this->checkConstraintIds($constraintIds, $result); |
|
| 146 | 146 | |
| 147 | - $result->addValue( null, 'success', 1 ); |
|
| 147 | + $result->addValue(null, 'success', 1); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
| 151 | 151 | * @param array|null $propertyIdSerializations |
| 152 | 152 | * @return PropertyId[] |
| 153 | 153 | */ |
| 154 | - private function parsePropertyIds( $propertyIdSerializations ) { |
|
| 155 | - if ( $propertyIdSerializations === null ) { |
|
| 154 | + private function parsePropertyIds($propertyIdSerializations) { |
|
| 155 | + if ($propertyIdSerializations === null) { |
|
| 156 | 156 | return []; |
| 157 | - } elseif ( empty( $propertyIdSerializations ) ) { |
|
| 157 | + } elseif (empty($propertyIdSerializations)) { |
|
| 158 | 158 | $this->apiErrorReporter->dieError( |
| 159 | - 'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.', |
|
| 159 | + 'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.', |
|
| 160 | 160 | 'no-data' |
| 161 | 161 | ); |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | return array_map( |
| 165 | - function ( $propertyIdSerialization ) { |
|
| 165 | + function($propertyIdSerialization) { |
|
| 166 | 166 | try { |
| 167 | - return new PropertyId( $propertyIdSerialization ); |
|
| 168 | - } catch ( InvalidArgumentException $e ) { |
|
| 167 | + return new PropertyId($propertyIdSerialization); |
|
| 168 | + } catch (InvalidArgumentException $e) { |
|
| 169 | 169 | $this->apiErrorReporter->dieError( |
| 170 | 170 | "Invalid id: $propertyIdSerialization", |
| 171 | 171 | 'invalid-property-id', |
| 172 | 172 | 0, // default argument |
| 173 | - [ self::PARAM_PROPERTY_ID => $propertyIdSerialization ] |
|
| 173 | + [self::PARAM_PROPERTY_ID => $propertyIdSerialization] |
|
| 174 | 174 | ); |
| 175 | 175 | } |
| 176 | 176 | }, |
@@ -182,35 +182,35 @@ discard block |
||
| 182 | 182 | * @param array|null $constraintIds |
| 183 | 183 | * @return string[] |
| 184 | 184 | */ |
| 185 | - private function parseConstraintIds( $constraintIds ) { |
|
| 186 | - if ( $constraintIds === null ) { |
|
| 185 | + private function parseConstraintIds($constraintIds) { |
|
| 186 | + if ($constraintIds === null) { |
|
| 187 | 187 | return []; |
| 188 | - } elseif ( empty( $constraintIds ) ) { |
|
| 188 | + } elseif (empty($constraintIds)) { |
|
| 189 | 189 | $this->apiErrorReporter->dieError( |
| 190 | - 'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.', |
|
| 190 | + 'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.', |
|
| 191 | 191 | 'no-data' |
| 192 | 192 | ); |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | return array_map( |
| 196 | - function ( $constraintId ) { |
|
| 196 | + function($constraintId) { |
|
| 197 | 197 | try { |
| 198 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
| 199 | - if ( !$propertyId instanceof PropertyId ) { |
|
| 198 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
| 199 | + if (!$propertyId instanceof PropertyId) { |
|
| 200 | 200 | $this->apiErrorReporter->dieError( |
| 201 | 201 | "Invalid property ID: {$propertyId->getSerialization()}", |
| 202 | 202 | 'invalid-property-id', |
| 203 | 203 | 0, // default argument |
| 204 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
| 204 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
| 205 | 205 | ); |
| 206 | 206 | } |
| 207 | 207 | return $constraintId; |
| 208 | - } catch ( StatementGuidParsingException $e ) { |
|
| 208 | + } catch (StatementGuidParsingException $e) { |
|
| 209 | 209 | $this->apiErrorReporter->dieError( |
| 210 | 210 | "Invalid statement GUID: $constraintId", |
| 211 | 211 | 'invalid-guid', |
| 212 | 212 | 0, // default argument |
| 213 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
| 213 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
| 214 | 214 | ); |
| 215 | 215 | } |
| 216 | 216 | }, |
@@ -222,12 +222,12 @@ discard block |
||
| 222 | 222 | * @param PropertyId[] $propertyIds |
| 223 | 223 | * @param ApiResult $result |
| 224 | 224 | */ |
| 225 | - private function checkPropertyIds( array $propertyIds, ApiResult $result ) { |
|
| 226 | - foreach ( $propertyIds as $propertyId ) { |
|
| 227 | - $result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' ); |
|
| 225 | + private function checkPropertyIds(array $propertyIds, ApiResult $result) { |
|
| 226 | + foreach ($propertyIds as $propertyId) { |
|
| 227 | + $result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc'); |
|
| 228 | 228 | $allConstraintExceptions = $this->delegatingConstraintChecker |
| 229 | - ->checkConstraintParametersOnPropertyId( $propertyId ); |
|
| 230 | - foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) { |
|
| 229 | + ->checkConstraintParametersOnPropertyId($propertyId); |
|
| 230 | + foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) { |
|
| 231 | 231 | $this->addConstraintParameterExceptionsToResult( |
| 232 | 232 | $constraintId, |
| 233 | 233 | $constraintParameterExceptions, |
@@ -241,15 +241,15 @@ discard block |
||
| 241 | 241 | * @param string[] $constraintIds |
| 242 | 242 | * @param ApiResult $result |
| 243 | 243 | */ |
| 244 | - private function checkConstraintIds( array $constraintIds, ApiResult $result ) { |
|
| 245 | - foreach ( $constraintIds as $constraintId ) { |
|
| 246 | - if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) { |
|
| 244 | + private function checkConstraintIds(array $constraintIds, ApiResult $result) { |
|
| 245 | + foreach ($constraintIds as $constraintId) { |
|
| 246 | + if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) { |
|
| 247 | 247 | // already checked as part of checkPropertyIds() |
| 248 | 248 | continue; |
| 249 | 249 | } |
| 250 | 250 | $constraintParameterExceptions = $this->delegatingConstraintChecker |
| 251 | - ->checkConstraintParametersOnConstraintId( $constraintId ); |
|
| 252 | - $this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result ); |
|
| 251 | + ->checkConstraintParametersOnConstraintId($constraintId); |
|
| 252 | + $this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result); |
|
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | 255 | |
@@ -257,18 +257,18 @@ discard block |
||
| 257 | 257 | * @param PropertyId $propertyId |
| 258 | 258 | * @return string[] |
| 259 | 259 | */ |
| 260 | - private function getResultPathForPropertyId( PropertyId $propertyId ) { |
|
| 261 | - return [ $this->getModuleName(), $propertyId->getSerialization() ]; |
|
| 260 | + private function getResultPathForPropertyId(PropertyId $propertyId) { |
|
| 261 | + return [$this->getModuleName(), $propertyId->getSerialization()]; |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
| 265 | 265 | * @param string $constraintId |
| 266 | 266 | * @return string[] |
| 267 | 267 | */ |
| 268 | - private function getResultPathForConstraintId( $constraintId ) { |
|
| 269 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
| 268 | + private function getResultPathForConstraintId($constraintId) { |
|
| 269 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
| 270 | 270 | '@phan-var PropertyId $propertyId'; |
| 271 | - return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] ); |
|
| 271 | + return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
@@ -283,8 +283,8 @@ discard block |
||
| 283 | 283 | $constraintParameterExceptions, |
| 284 | 284 | ApiResult $result |
| 285 | 285 | ) { |
| 286 | - $path = $this->getResultPathForConstraintId( $constraintId ); |
|
| 287 | - if ( $constraintParameterExceptions === null ) { |
|
| 286 | + $path = $this->getResultPathForConstraintId($constraintId); |
|
| 287 | + if ($constraintParameterExceptions === null) { |
|
| 288 | 288 | $result->addValue( |
| 289 | 289 | $path, |
| 290 | 290 | self::KEY_STATUS, |
@@ -294,12 +294,12 @@ discard block |
||
| 294 | 294 | $result->addValue( |
| 295 | 295 | $path, |
| 296 | 296 | self::KEY_STATUS, |
| 297 | - empty( $constraintParameterExceptions ) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
| 297 | + empty($constraintParameterExceptions) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
| 298 | 298 | ); |
| 299 | 299 | $result->addValue( |
| 300 | 300 | $path, |
| 301 | 301 | self::KEY_PROBLEMS, |
| 302 | - array_map( [ $this, 'formatConstraintParameterException' ], $constraintParameterExceptions ) |
|
| 302 | + array_map([$this, 'formatConstraintParameterException'], $constraintParameterExceptions) |
|
| 303 | 303 | ); |
| 304 | 304 | } |
| 305 | 305 | } |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | * @param ConstraintParameterException $e |
| 311 | 311 | * @return string[] |
| 312 | 312 | */ |
| 313 | - private function formatConstraintParameterException( ConstraintParameterException $e ) { |
|
| 313 | + private function formatConstraintParameterException(ConstraintParameterException $e) { |
|
| 314 | 314 | return [ |
| 315 | 315 | self::KEY_MESSAGE_HTML => $this->violationMessageRenderer->render( |
| 316 | 316 | $e->getViolationMessage() |
@@ -343,8 +343,8 @@ discard block |
||
| 343 | 343 | return [ |
| 344 | 344 | 'action=wbcheckconstraintparameters&propertyid=P247' |
| 345 | 345 | => 'apihelp-wbcheckconstraintparameters-example-propertyid-1', |
| 346 | - 'action=wbcheckconstraintparameters&' . |
|
| 347 | - 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|' . |
|
| 346 | + 'action=wbcheckconstraintparameters&'. |
|
| 347 | + 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|'. |
|
| 348 | 348 | 'P225$cdc71e4a-47a0-12c5-dfb3-3f6fc0b6613f' |
| 349 | 349 | => 'apihelp-wbcheckconstraintparameters-example-constraintid-2', |
| 350 | 350 | ]; |