@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * then using the main DBLoadBalancer service may be incorrect. |
26 | 26 | * @param string|false $dbName Database name ($domain for ILoadBalancer methods). |
27 | 27 | */ |
28 | - public function __construct( ILoadBalancer $lb, $dbName ) { |
|
28 | + public function __construct(ILoadBalancer $lb, $dbName) { |
|
29 | 29 | $this->lb = $lb; |
30 | 30 | $this->dbName = $dbName; |
31 | 31 | } |
@@ -35,17 +35,17 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @return Constraint[] |
37 | 37 | */ |
38 | - public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
39 | - $dbr = $this->lb->getConnectionRef( ILoadBalancer::DB_REPLICA, [], $this->dbName ); |
|
38 | + public function queryConstraintsForProperty(PropertyId $propertyId) { |
|
39 | + $dbr = $this->lb->getConnectionRef(ILoadBalancer::DB_REPLICA, [], $this->dbName); |
|
40 | 40 | |
41 | 41 | $results = $dbr->select( |
42 | 42 | 'wbqc_constraints', |
43 | 43 | '*', |
44 | - [ 'pid' => $propertyId->getNumericId() ], |
|
44 | + ['pid' => $propertyId->getNumericId()], |
|
45 | 45 | __METHOD__ |
46 | 46 | ); |
47 | 47 | |
48 | - return $this->convertToConstraints( $results ); |
|
48 | + return $this->convertToConstraints($results); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -53,26 +53,26 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return Constraint[] |
55 | 55 | */ |
56 | - private function convertToConstraints( IResultWrapper $results ) { |
|
56 | + private function convertToConstraints(IResultWrapper $results) { |
|
57 | 57 | $constraints = []; |
58 | - $logger = LoggerFactory::getInstance( 'WikibaseQualityConstraints' ); |
|
59 | - foreach ( $results as $result ) { |
|
58 | + $logger = LoggerFactory::getInstance('WikibaseQualityConstraints'); |
|
59 | + foreach ($results as $result) { |
|
60 | 60 | $constraintTypeItemId = $result->constraint_type_qid; |
61 | - $constraintParameters = json_decode( $result->constraint_parameters, true ); |
|
61 | + $constraintParameters = json_decode($result->constraint_parameters, true); |
|
62 | 62 | |
63 | - if ( $constraintParameters === null ) { |
|
63 | + if ($constraintParameters === null) { |
|
64 | 64 | // T171295 |
65 | - $logger->warning( 'Constraint {constraintId} has invalid constraint parameters.', [ |
|
65 | + $logger->warning('Constraint {constraintId} has invalid constraint parameters.', [ |
|
66 | 66 | 'method' => __METHOD__, |
67 | 67 | 'constraintId' => $result->constraint_guid, |
68 | 68 | 'constraintParameters' => $result->constraint_parameters, |
69 | - ] ); |
|
70 | - $constraintParameters = [ '@error' => [ /* unknown */ ] ]; |
|
69 | + ]); |
|
70 | + $constraintParameters = ['@error' => [/* unknown */]]; |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | $constraints[] = new Constraint( |
74 | 74 | $result->constraint_guid, |
75 | - PropertyId::newFromNumber( $result->pid ), |
|
75 | + PropertyId::newFromNumber($result->pid), |
|
76 | 76 | $constraintTypeItemId, |
77 | 77 | $constraintParameters |
78 | 78 | ); |
@@ -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 |
@@ -28,25 +28,25 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @param DatabaseUpdater $updater |
30 | 30 | */ |
31 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
31 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
32 | 32 | $updater->addExtensionTable( |
33 | 33 | 'wbqc_constraints', |
34 | - __DIR__ . '/../sql/create_wbqc_constraints.sql' |
|
34 | + __DIR__.'/../sql/create_wbqc_constraints.sql' |
|
35 | 35 | ); |
36 | 36 | $updater->addExtensionField( |
37 | 37 | 'wbqc_constraints', |
38 | 38 | 'constraint_id', |
39 | - __DIR__ . '/../sql/patch-wbqc_constraints-constraint_id.sql' |
|
39 | + __DIR__.'/../sql/patch-wbqc_constraints-constraint_id.sql' |
|
40 | 40 | ); |
41 | 41 | $updater->addExtensionIndex( |
42 | 42 | 'wbqc_constraints', |
43 | 43 | 'wbqc_constraints_guid_uniq', |
44 | - __DIR__ . '/../sql/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
44 | + __DIR__.'/../sql/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
45 | 45 | ); |
46 | 46 | } |
47 | 47 | |
48 | - public static function onWikibaseChange( Change $change ) { |
|
49 | - if ( !( $change instanceof EntityChange ) ) { |
|
48 | + public static function onWikibaseChange(Change $change) { |
|
49 | + if (!($change instanceof EntityChange)) { |
|
50 | 50 | return; |
51 | 51 | } |
52 | 52 | |
@@ -55,48 +55,48 @@ discard block |
||
55 | 55 | |
56 | 56 | // If jobs are enabled and the results would be stored in some way run a job. |
57 | 57 | if ( |
58 | - $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobs' ) && |
|
59 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) && |
|
58 | + $config->get('WBQualityConstraintsEnableConstraintsCheckJobs') && |
|
59 | + $config->get('WBQualityConstraintsCacheCheckConstraintsResults') && |
|
60 | 60 | self::isSelectedForJobRunBasedOnPercentage() |
61 | 61 | ) { |
62 | - $params = [ 'entityId' => $change->getEntityId()->getSerialization() ]; |
|
62 | + $params = ['entityId' => $change->getEntityId()->getSerialization()]; |
|
63 | 63 | JobQueueGroup::singleton()->push( |
64 | - new JobSpecification( CheckConstraintsJob::COMMAND, $params ) |
|
64 | + new JobSpecification(CheckConstraintsJob::COMMAND, $params) |
|
65 | 65 | ); |
66 | 66 | } |
67 | 67 | |
68 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
69 | - self::isConstraintStatementsChange( $config, $change ) |
|
68 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
69 | + self::isConstraintStatementsChange($config, $change) |
|
70 | 70 | ) { |
71 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
71 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
72 | 72 | $metadata = $change->getMetadata(); |
73 | - if ( array_key_exists( 'rev_id', $metadata ) ) { |
|
73 | + if (array_key_exists('rev_id', $metadata)) { |
|
74 | 74 | $params['revisionId'] = $metadata['rev_id']; |
75 | 75 | } |
76 | 76 | JobQueueGroup::singleton()->push( |
77 | - new JobSpecification( 'constraintsTableUpdate', $params ) |
|
77 | + new JobSpecification('constraintsTableUpdate', $params) |
|
78 | 78 | ); |
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
82 | 82 | private static function isSelectedForJobRunBasedOnPercentage() { |
83 | 83 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
84 | - $percentage = $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobsRatio' ); |
|
84 | + $percentage = $config->get('WBQualityConstraintsEnableConstraintsCheckJobsRatio'); |
|
85 | 85 | |
86 | - return mt_rand( 1, 100 ) <= $percentage; |
|
86 | + return mt_rand(1, 100) <= $percentage; |
|
87 | 87 | } |
88 | 88 | |
89 | - public static function isConstraintStatementsChange( Config $config, Change $change ) { |
|
90 | - if ( !( $change instanceof EntityChange ) || |
|
89 | + public static function isConstraintStatementsChange(Config $config, Change $change) { |
|
90 | + if (!($change instanceof EntityChange) || |
|
91 | 91 | $change->getAction() !== EntityChange::UPDATE || |
92 | - !( $change->getEntityId() instanceof PropertyId ) |
|
92 | + !($change->getEntityId() instanceof PropertyId) |
|
93 | 93 | ) { |
94 | 94 | return false; |
95 | 95 | } |
96 | 96 | |
97 | 97 | $info = $change->getInfo(); |
98 | 98 | |
99 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
99 | + if (!array_key_exists('compactDiff', $info)) { |
|
100 | 100 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
101 | 101 | // so we only know that the change *might* affect the constraint statements |
102 | 102 | return true; |
@@ -105,47 +105,47 @@ discard block |
||
105 | 105 | /** @var EntityDiffChangedAspects $aspects */ |
106 | 106 | $aspects = $info['compactDiff']; |
107 | 107 | |
108 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
109 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
108 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
109 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
110 | 110 | } |
111 | 111 | |
112 | - public static function onArticlePurge( WikiPage $wikiPage ) { |
|
112 | + public static function onArticlePurge(WikiPage $wikiPage) { |
|
113 | 113 | $repo = WikibaseRepo::getDefaultInstance(); |
114 | 114 | |
115 | 115 | $entityContentFactory = $repo->getEntityContentFactory(); |
116 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
116 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
117 | 117 | $entityIdLookup = $repo->getEntityIdLookup(); |
118 | - $entityId = $entityIdLookup->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
119 | - if ( $entityId !== null ) { |
|
118 | + $entityId = $entityIdLookup->getEntityIdForTitle($wikiPage->getTitle()); |
|
119 | + if ($entityId !== null) { |
|
120 | 120 | $resultsCache = ResultsCache::getDefaultInstance(); |
121 | - $resultsCache->delete( $entityId ); |
|
121 | + $resultsCache->delete($entityId); |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
126 | - public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) { |
|
126 | + public static function onBeforePageDisplay(OutputPage $out, Skin $skin) { |
|
127 | 127 | $repo = WikibaseRepo::getDefaultInstance(); |
128 | 128 | |
129 | 129 | $lookup = $repo->getEntityNamespaceLookup(); |
130 | 130 | $title = $out->getTitle(); |
131 | - if ( $title === null ) { |
|
131 | + if ($title === null) { |
|
132 | 132 | return; |
133 | 133 | } |
134 | 134 | |
135 | - if ( !$lookup->isNamespaceWithEntities( $title->getNamespace() ) ) { |
|
135 | + if (!$lookup->isNamespaceWithEntities($title->getNamespace())) { |
|
136 | 136 | return; |
137 | 137 | } |
138 | - if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) { |
|
138 | + if (empty($out->getJsConfigVars()['wbIsEditView'])) { |
|
139 | 139 | return; |
140 | 140 | } |
141 | 141 | |
142 | - $out->addModules( 'wikibase.quality.constraints.suggestions' ); |
|
142 | + $out->addModules('wikibase.quality.constraints.suggestions'); |
|
143 | 143 | |
144 | - if ( !$out->getUser()->isLoggedIn() ) { |
|
144 | + if (!$out->getUser()->isLoggedIn()) { |
|
145 | 145 | return; |
146 | 146 | } |
147 | 147 | |
148 | - $out->addModules( 'wikibase.quality.constraints.gadget' ); |
|
148 | + $out->addModules('wikibase.quality.constraints.gadget'); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | } |
@@ -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 |