Completed
Push — master ( 44effd...b7045c )
by
unknown
05:40 queued 02:09
created
src/Api/ResultsCache.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -18,10 +18,10 @@  discard block
 block discarded – undo
18 18
 	private $cache;
19 19
 
20 20
 	public static function getDefaultInstance() {
21
-		return new self( MediaWikiServices::getInstance()->getMainWANObjectCache() );
21
+		return new self(MediaWikiServices::getInstance()->getMainWANObjectCache());
22 22
 	}
23 23
 
24
-	public function __construct( WANObjectCache $cache ) {
24
+	public function __construct(WANObjectCache $cache) {
25 25
 		$this->cache = $cache;
26 26
 	}
27 27
 
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 * @param EntityId $entityId
30 30
 	 * @return string cache key
31 31
 	 */
32
-	public function makeKey( EntityId $entityId ) {
32
+	public function makeKey(EntityId $entityId) {
33 33
 		return $this->cache->makeKey(
34 34
 			'WikibaseQualityConstraints', // extension
35 35
 			'checkConstraints', // action
@@ -45,8 +45,8 @@  discard block
 block discarded – undo
45 45
 	 * @param float &$asOf
46 46
 	 * @return mixed
47 47
 	 */
48
-	public function get( EntityId $key, &$curTTL = null, array $checkKeys = [], &$asOf = null ) {
49
-		return $this->cache->get( $this->makeKey( $key ), $curTTL, $checkKeys, $asOf );
48
+	public function get(EntityId $key, &$curTTL = null, array $checkKeys = [], &$asOf = null) {
49
+		return $this->cache->get($this->makeKey($key), $curTTL, $checkKeys, $asOf);
50 50
 	}
51 51
 
52 52
 	/**
@@ -56,16 +56,16 @@  discard block
 block discarded – undo
56 56
 	 * @param array $opts
57 57
 	 * @return bool
58 58
 	 */
59
-	public function set( EntityId $key, $value, $ttl = 0, array $opts = [] ) {
60
-		return $this->cache->set( $this->makeKey( $key ), $value, $ttl, $opts );
59
+	public function set(EntityId $key, $value, $ttl = 0, array $opts = []) {
60
+		return $this->cache->set($this->makeKey($key), $value, $ttl, $opts);
61 61
 	}
62 62
 
63 63
 	/**
64 64
 	 * @param EntityId $key
65 65
 	 * @return bool
66 66
 	 */
67
-	public function delete( EntityId $key ) {
68
-		return $this->cache->delete( $this->makeKey( $key ) );
67
+	public function delete(EntityId $key) {
68
+		return $this->cache->delete($this->makeKey($key));
69 69
 	}
70 70
 
71 71
 }
Please login to merge, or discard this patch.
src/Api/CheckConstraints.php 1 patch
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -66,22 +66,22 @@  discard block
 block discarded – undo
66 66
 	 *
67 67
 	 * @return self
68 68
 	 */
69
-	public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) {
69
+	public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') {
70 70
 		$repo = WikibaseRepo::getDefaultInstance();
71 71
 
72 72
 		$language = $repo->getUserLanguage();
73 73
 		$formatterOptions = new FormatterOptions();
74
-		$formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() );
74
+		$formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode());
75 75
 		$valueFormatterFactory = $repo->getValueFormatterFactory();
76
-		$valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions );
76
+		$valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions);
77 77
 
78 78
 		$languageFallbackLabelDescriptionLookupFactory = $repo->getLanguageFallbackLabelDescriptionLookupFactory();
79
-		$labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup( $language );
79
+		$labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup($language);
80 80
 		$entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory();
81
-		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup );
81
+		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($labelDescriptionLookup);
82 82
 		$entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory();
83
-		$entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup );
84
-		$constraintParameterRenderer = new ConstraintParameterRenderer( $entityIdHtmlLinkFormatter, $valueFormatter );
83
+		$entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($labelDescriptionLookup);
84
+		$constraintParameterRenderer = new ConstraintParameterRenderer($entityIdHtmlLinkFormatter, $valueFormatter);
85 85
 		$config = MediaWikiServices::getInstance()->getMainConfig();
86 86
 		$titleParser = MediaWikiServices::getInstance()->getTitleParser();
87 87
 		$unitConverter = $repo->getUnitConverter();
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 			$constraintParameterRenderer,
110 110
 			$config
111 111
 		);
112
-		if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) {
112
+		if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) {
113 113
 			$entityRevisionLookup = $repo->getEntityRevisionLookup();
114 114
 			$entityIdParser = $repo->getEntityIdParser();
115 115
 			$resultsBuilder = new CachingResultsBuilder(
@@ -117,12 +117,12 @@  discard block
 block discarded – undo
117 117
 				ResultsCache::getDefaultInstance(),
118 118
 				$entityRevisionLookup,
119 119
 				$entityIdParser,
120
-				$config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ),
120
+				$config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'),
121 121
 				[
122
-					$config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ),
123
-					$config->get( 'WBQualityConstraintsTypeConstraintId' ),
124
-					$config->get( 'WBQualityConstraintsValueTypeConstraintId' ),
125
-					$config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ),
122
+					$config->get('WBQualityConstraintsCommonsLinkConstraintId'),
123
+					$config->get('WBQualityConstraintsTypeConstraintId'),
124
+					$config->get('WBQualityConstraintsValueTypeConstraintId'),
125
+					$config->get('WBQualityConstraintsDistinctValuesConstraintId'),
126 126
 				]
127 127
 			);
128 128
 		}
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 			$prefix,
134 134
 			$repo->getEntityIdParser(),
135 135
 			$repo->getStatementGuidValidator(),
136
-			$repo->getApiHelperFactory( RequestContext::getMain() ),
136
+			$repo->getApiHelperFactory(RequestContext::getMain()),
137 137
 			$resultsBuilder
138 138
 		);
139 139
 	}
@@ -147,16 +147,16 @@  discard block
 block discarded – undo
147 147
 	 * @param ApiHelperFactory $apiHelperFactory
148 148
 	 * @param ResultsBuilder $resultsBuilder
149 149
 	 */
150
-	public function __construct( ApiMain $main, $name, $prefix = '', EntityIdParser $entityIdParser,
150
+	public function __construct(ApiMain $main, $name, $prefix = '', EntityIdParser $entityIdParser,
151 151
 								 StatementGuidValidator $statementGuidValidator,
152 152
 								 ApiHelperFactory $apiHelperFactory,
153 153
 								 ResultsBuilder $resultsBuilder
154 154
 	) {
155
-		parent::__construct( $main, $name, $prefix );
155
+		parent::__construct($main, $name, $prefix);
156 156
 		$this->entityIdParser = $entityIdParser;
157 157
 		$this->statementGuidValidator = $statementGuidValidator;
158
-		$this->resultBuilder = $apiHelperFactory->getResultBuilder( $this );
159
-		$this->errorReporter = $apiHelperFactory->getErrorReporter( $this );
158
+		$this->resultBuilder = $apiHelperFactory->getResultBuilder($this);
159
+		$this->errorReporter = $apiHelperFactory->getErrorReporter($this);
160 160
 		$this->resultsBuilder = $resultsBuilder;
161 161
 	}
162 162
 
@@ -165,13 +165,13 @@  discard block
 block discarded – undo
165 165
 	 */
166 166
 	public function execute() {
167 167
 		MediaWikiServices::getInstance()->getStatsdDataFactory()
168
-			->increment( 'wikibase.quality.constraints.api.checkConstraints.execute' );
168
+			->increment('wikibase.quality.constraints.api.checkConstraints.execute');
169 169
 
170 170
 		$params = $this->extractRequestParams();
171 171
 
172
-		$this->validateParameters( $params );
173
-		$entityIds = $this->parseEntityIds( $params );
174
-		$claimIds = $this->parseClaimIds( $params );
172
+		$this->validateParameters($params);
173
+		$entityIds = $this->parseEntityIds($params);
174
+		$claimIds = $this->parseClaimIds($params);
175 175
 		$constraintIDs = $params[self::PARAM_CONSTRAINT_ID];
176 176
 
177 177
 		$this->getResult()->addValue(
@@ -183,64 +183,64 @@  discard block
 block discarded – undo
183 183
 			)->getArray()
184 184
 		);
185 185
 		// ensure that result contains the given entity IDs even if they have no statements
186
-		foreach ( $entityIds as $entityId ) {
186
+		foreach ($entityIds as $entityId) {
187 187
 			$this->getResult()->addArrayType(
188
-				[ $this->getModuleName(), $entityId->getSerialization() ],
188
+				[$this->getModuleName(), $entityId->getSerialization()],
189 189
 				'assoc'
190 190
 			);
191 191
 		}
192
-		$this->resultBuilder->markSuccess( 1 );
192
+		$this->resultBuilder->markSuccess(1);
193 193
 	}
194 194
 
195
-	private function parseEntityIds( array $params ) {
195
+	private function parseEntityIds(array $params) {
196 196
 		$ids = $params[self::PARAM_ID];
197 197
 
198
-		if ( $ids === null ) {
198
+		if ($ids === null) {
199 199
 			return [];
200
-		} elseif ( $ids === [] ) {
200
+		} elseif ($ids === []) {
201 201
 			$this->errorReporter->dieError(
202
-				'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' );
202
+				'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' );
203 203
 		}
204 204
 
205
-		return array_map( function ( $id ) {
205
+		return array_map(function($id) {
206 206
 			try {
207
-				return $this->entityIdParser->parse( $id );
208
-			} catch ( EntityIdParsingException $e ) {
207
+				return $this->entityIdParser->parse($id);
208
+			} catch (EntityIdParsingException $e) {
209 209
 				$this->errorReporter->dieError(
210
-					"Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] );
210
+					"Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] );
211 211
 			}
212
-		}, $ids );
212
+		}, $ids);
213 213
 	}
214 214
 
215
-	private function parseClaimIds( array $params ) {
215
+	private function parseClaimIds(array $params) {
216 216
 		$ids = $params[self::PARAM_CLAIM_ID];
217 217
 
218
-		if ( $ids === null ) {
218
+		if ($ids === null) {
219 219
 			return [];
220
-		} elseif ( $ids === [] ) {
220
+		} elseif ($ids === []) {
221 221
 			$this->errorReporter->dieError(
222
-				'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' );
222
+				'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' );
223 223
 		}
224 224
 
225
-		foreach ( $ids as $id ) {
226
-			if ( !$this->statementGuidValidator->validate( $id ) ) {
225
+		foreach ($ids as $id) {
226
+			if (!$this->statementGuidValidator->validate($id)) {
227 227
 				$this->errorReporter->dieError(
228
-					"Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] );
228
+					"Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] );
229 229
 			}
230 230
 		}
231 231
 
232 232
 		return $ids;
233 233
 	}
234 234
 
235
-	private function validateParameters( array $params ) {
236
-		if ( $params[self::PARAM_CONSTRAINT_ID] !== null
237
-			 && empty( $params[self::PARAM_CONSTRAINT_ID] )
235
+	private function validateParameters(array $params) {
236
+		if ($params[self::PARAM_CONSTRAINT_ID] !== null
237
+			 && empty($params[self::PARAM_CONSTRAINT_ID])
238 238
 		) {
239 239
 			$paramConstraintId = self::PARAM_CONSTRAINT_ID;
240 240
 			$this->errorReporter->dieError(
241 241
 				"If $paramConstraintId is specified, it must be nonempty.", 'no-data' );
242 242
 		}
243
-		if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) {
243
+		if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) {
244 244
 			$paramId = self::PARAM_ID;
245 245
 			$paramClaimId = self::PARAM_CLAIM_ID;
246 246
 			$this->errorReporter->dieError(
Please login to merge, or discard this patch.
src/Api/CachingResultsBuilder.php 1 patch
Spacing   +45 added lines, -46 removed lines patch added patch discarded remove patch
@@ -106,26 +106,26 @@  discard block
 block discarded – undo
106 106
 	) {
107 107
 		$results = [];
108 108
 		$metadatas = [];
109
-		if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds ) ) {
109
+		if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds)) {
110 110
 			$storedEntityIds = [];
111
-			foreach ( $entityIds as $entityId ) {
112
-				$storedResults = $this->getStoredResults( $entityId );
113
-				if ( $storedResults !== null ) {
111
+			foreach ($entityIds as $entityId) {
112
+				$storedResults = $this->getStoredResults($entityId);
113
+				if ($storedResults !== null) {
114 114
 					$results += $storedResults->getArray();
115 115
 					$metadatas[] = $storedResults->getMetadata();
116 116
 					$storedEntityIds[] = $entityId;
117 117
 				}
118 118
 			}
119
-			$entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) );
119
+			$entityIds = array_values(array_diff($entityIds, $storedEntityIds));
120 120
 		}
121
-		if ( $entityIds !== [] || $claimIds !== [] ) {
122
-			$response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds );
121
+		if ($entityIds !== [] || $claimIds !== []) {
122
+			$response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds);
123 123
 			$results += $response->getArray();
124 124
 			$metadatas[] = $response->getMetadata();
125 125
 		}
126 126
 		return new CachedCheckConstraintsResponse(
127 127
 			$results,
128
-			Metadata::merge( $metadatas )
128
+			Metadata::merge($metadatas)
129 129
 		);
130 130
 	}
131 131
 
@@ -158,17 +158,17 @@  discard block
 block discarded – undo
158 158
 		array $claimIds,
159 159
 		array $constraintIds = null
160 160
 	) {
161
-		$results = $this->resultsBuilder->getResults( $entityIds, $claimIds, $constraintIds );
161
+		$results = $this->resultsBuilder->getResults($entityIds, $claimIds, $constraintIds);
162 162
 
163
-		if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds ) ) {
164
-			foreach ( $entityIds as $entityId ) {
163
+		if ($this->canStoreResults($entityIds, $claimIds, $constraintIds)) {
164
+			foreach ($entityIds as $entityId) {
165 165
 				$value = [
166 166
 					'results' => $results->getArray()[$entityId->getSerialization()],
167 167
 					'latestRevisionIds' => $this->getLatestRevisionIds(
168 168
 						$results->getMetadata()->getDependencyMetadata()->getEntityIds()
169 169
 					),
170 170
 				];
171
-				$this->cache->set( $entityId, $value, $this->ttlInSeconds );
171
+				$this->cache->set($entityId, $value, $this->ttlInSeconds);
172 172
 			}
173 173
 		}
174 174
 
@@ -201,45 +201,44 @@  discard block
 block discarded – undo
201 201
 	public function getStoredResults(
202 202
 		EntityId $entityId
203 203
 	) {
204
-		$value = $this->cache->get( $entityId, $curTTL, [], $asOf );
205
-		$now = call_user_func( $this->microtime, true );
204
+		$value = $this->cache->get($entityId, $curTTL, [], $asOf);
205
+		$now = call_user_func($this->microtime, true);
206 206
 
207
-		if ( $value === false ) {
207
+		if ($value === false) {
208 208
 			return null;
209 209
 		}
210 210
 
211
-		$ageInSeconds = (int)ceil( $now - $asOf );
211
+		$ageInSeconds = (int) ceil($now - $asOf);
212 212
 
213 213
 		$dependedEntityIds = array_map(
214
-			[ $this->entityIdParser, "parse" ],
215
-			array_keys( $value['latestRevisionIds'] )
214
+			[$this->entityIdParser, "parse"],
215
+			array_keys($value['latestRevisionIds'])
216 216
 		);
217 217
 
218
-		if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) {
218
+		if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) {
219 219
 			return null;
220 220
 		}
221 221
 
222 222
 		$cachingMetadata = $ageInSeconds > 0 ?
223
-			CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) :
224
-			CachingMetadata::fresh();
223
+			CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh();
225 224
 
226
-		if ( is_array( $value['results'] ) ) {
227
-			array_walk( $value['results'], [ $this, 'updateCachingMetadata' ], $cachingMetadata );
225
+		if (is_array($value['results'])) {
226
+			array_walk($value['results'], [$this, 'updateCachingMetadata'], $cachingMetadata);
228 227
 		}
229 228
 
230 229
 		return new CachedCheckConstraintsResponse(
231
-			[ $entityId->getSerialization() => $value['results'] ],
230
+			[$entityId->getSerialization() => $value['results']],
232 231
 			array_reduce(
233 232
 				$dependedEntityIds,
234
-				function( Metadata $metadata, EntityId $entityId ) {
235
-					return Metadata::merge( [
233
+				function(Metadata $metadata, EntityId $entityId) {
234
+					return Metadata::merge([
236 235
 						$metadata,
237 236
 						Metadata::ofDependencyMetadata(
238
-							DependencyMetadata::ofEntityId( $entityId )
237
+							DependencyMetadata::ofEntityId($entityId)
239 238
 						)
240
-					] );
239
+					]);
241 240
 				},
242
-				Metadata::ofCachingMetadata( $cachingMetadata )
241
+				Metadata::ofCachingMetadata($cachingMetadata)
243 242
 			)
244 243
 		);
245 244
 	}
@@ -248,37 +247,37 @@  discard block
 block discarded – undo
248 247
 	 * @param EntityId[] $entityIds
249 248
 	 * @return int[]
250 249
 	 */
251
-	private function getLatestRevisionIds( array $entityIds ) {
250
+	private function getLatestRevisionIds(array $entityIds) {
252 251
 		$latestRevisionIds = [];
253
-		foreach ( $entityIds as $entityId ) {
252
+		foreach ($entityIds as $entityId) {
254 253
 			$serialization = $entityId->getSerialization();
255
-			$latestRevisionId = $this->entityRevisionLookup->getLatestRevisionId( $entityId );
254
+			$latestRevisionId = $this->entityRevisionLookup->getLatestRevisionId($entityId);
256 255
 			$latestRevisionIds[$serialization] = $latestRevisionId;
257 256
 		}
258 257
 		return $latestRevisionIds;
259 258
 	}
260 259
 
261
-	public function updateCachingMetadata( &$element, $key, CachingMetadata $cachingMetadata ) {
262
-		if ( $key === 'cached' ) {
263
-			$element = CachingMetadata::merge( [
260
+	public function updateCachingMetadata(&$element, $key, CachingMetadata $cachingMetadata) {
261
+		if ($key === 'cached') {
262
+			$element = CachingMetadata::merge([
264 263
 				$cachingMetadata,
265
-				CachingMetadata::ofArray( $element ),
266
-			] )->toArray();
264
+				CachingMetadata::ofArray($element),
265
+			])->toArray();
267 266
 		}
268 267
 		if (
269
-			is_array( $element ) &&
270
-			array_key_exists( 'constraint', $element ) &&
271
-			in_array( $element['constraint']['type'], $this->possiblyStaleConstraintTypes, true )
268
+			is_array($element) &&
269
+			array_key_exists('constraint', $element) &&
270
+			in_array($element['constraint']['type'], $this->possiblyStaleConstraintTypes, true)
272 271
 		) {
273
-			$element['cached'] = CachingMetadata::merge( [
272
+			$element['cached'] = CachingMetadata::merge([
274 273
 				$cachingMetadata,
275 274
 				CachingMetadata::ofArray(
276
-					array_key_exists( 'cached', $element ) ? $element['cached'] : null
275
+					array_key_exists('cached', $element) ? $element['cached'] : null
277 276
 				),
278
-			] )->toArray();
277
+			])->toArray();
279 278
 		}
280
-		if ( is_array( $element ) ) {
281
-			array_walk( $element, [ $this, __FUNCTION__ ], $cachingMetadata );
279
+		if (is_array($element)) {
280
+			array_walk($element, [$this, __FUNCTION__], $cachingMetadata);
282 281
 		}
283 282
 	}
284 283
 
@@ -287,7 +286,7 @@  discard block
 block discarded – undo
287 286
 	 *
288 287
 	 * @param callable $microtime
289 288
 	 */
290
-	public function setMicrotimeFunction( callable $microtime ) {
289
+	public function setMicrotimeFunction(callable $microtime) {
291 290
 		$this->microtime = $microtime;
292 291
 	}
293 292
 
Please login to merge, or discard this patch.