Completed
Push — master ( e76c99...c0a2f5 )
by
unknown
02:13
created
src/ConstraintCheck/Api/CachingResultsBuilder.php 1 patch
Spacing   +32 added lines, -33 removed lines patch added patch discarded remove patch
@@ -87,26 +87,26 @@  discard block
 block discarded – undo
87 87
 	) {
88 88
 		$results = [];
89 89
 		$metadatas = [];
90
-		if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds ) ) {
90
+		if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds)) {
91 91
 			$storedEntityIds = [];
92
-			foreach ( $entityIds as $entityId ) {
93
-				$storedResults = $this->getStoredResults( $entityId );
94
-				if ( $storedResults !== null ) {
92
+			foreach ($entityIds as $entityId) {
93
+				$storedResults = $this->getStoredResults($entityId);
94
+				if ($storedResults !== null) {
95 95
 					$results += $storedResults->getArray();
96 96
 					$metadatas[] = $storedResults->getMetadata();
97 97
 					$storedEntityIds[] = $entityId;
98 98
 				}
99 99
 			}
100
-			$entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) );
100
+			$entityIds = array_values(array_diff($entityIds, $storedEntityIds));
101 101
 		}
102
-		if ( $entityIds !== [] || $claimIds !== [] ) {
103
-			$response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds );
102
+		if ($entityIds !== [] || $claimIds !== []) {
103
+			$response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds);
104 104
 			$results += $response->getArray();
105 105
 			$metadatas[] = $response->getMetadata();
106 106
 		}
107 107
 		return new CachedCheckConstraintsResponse(
108 108
 			$results,
109
-			Metadata::merge( $metadatas )
109
+			Metadata::merge($metadatas)
110 110
 		);
111 111
 	}
112 112
 
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 	 * @param EntityId $entityId
133 133
 	 * @return string cache key
134 134
 	 */
135
-	public function getKey( EntityId $entityId ) {
135
+	public function getKey(EntityId $entityId) {
136 136
 		return $this->cache->makeKey(
137 137
 			'WikibaseQualityConstraints', // extension
138 138
 			'checkConstraints', // action
@@ -152,18 +152,18 @@  discard block
 block discarded – undo
152 152
 		array $claimIds,
153 153
 		array $constraintIds = null
154 154
 	) {
155
-		$results = $this->resultsBuilder->getResults( $entityIds, $claimIds, $constraintIds );
155
+		$results = $this->resultsBuilder->getResults($entityIds, $claimIds, $constraintIds);
156 156
 
157
-		if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds ) ) {
158
-			foreach ( $entityIds as $entityId ) {
159
-				$key = $this->getKey( $entityId );
157
+		if ($this->canStoreResults($entityIds, $claimIds, $constraintIds)) {
158
+			foreach ($entityIds as $entityId) {
159
+				$key = $this->getKey($entityId);
160 160
 				$value = [
161 161
 					'results' => $results->getArray()[$entityId->getSerialization()],
162 162
 					'latestRevisionIds' => $this->getLatestRevisionIds(
163 163
 						$results->getMetadata()->getDependencyMetadata()->getEntityIds()
164 164
 					),
165 165
 				];
166
-				$this->cache->set( $key, $value, $this->ttlInSeconds );
166
+				$this->cache->set($key, $value, $this->ttlInSeconds);
167 167
 			}
168 168
 		}
169 169
 
@@ -196,41 +196,40 @@  discard block
 block discarded – undo
196 196
 	public function getStoredResults(
197 197
 		EntityId $entityId
198 198
 	) {
199
-		$key = $this->getKey( $entityId );
200
-		$value = $this->cache->get( $key, $curTTL, [], $asOf );
201
-		$now = call_user_func( $this->microtime, true );
199
+		$key = $this->getKey($entityId);
200
+		$value = $this->cache->get($key, $curTTL, [], $asOf);
201
+		$now = call_user_func($this->microtime, true);
202 202
 
203
-		if ( $value === false ) {
203
+		if ($value === false) {
204 204
 			return null;
205 205
 		}
206 206
 
207
-		$ageInSeconds = (integer)ceil( $now - $asOf );
207
+		$ageInSeconds = (integer) ceil($now - $asOf);
208 208
 
209 209
 		$dependedEntityIds = array_map(
210
-			[ $this->entityIdParser, "parse" ],
211
-			array_keys( $value['latestRevisionIds'] )
210
+			[$this->entityIdParser, "parse"],
211
+			array_keys($value['latestRevisionIds'])
212 212
 		);
213 213
 
214
-		if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) {
214
+		if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) {
215 215
 			return null;
216 216
 		}
217 217
 
218 218
 		return new CachedCheckConstraintsResponse(
219
-			[ $entityId->getSerialization() => $value['results'] ],
219
+			[$entityId->getSerialization() => $value['results']],
220 220
 			array_reduce(
221 221
 				$dependedEntityIds,
222
-				function( Metadata $metadata, EntityId $entityId ) {
223
-					return Metadata::merge( [
222
+				function(Metadata $metadata, EntityId $entityId) {
223
+					return Metadata::merge([
224 224
 						$metadata,
225 225
 						Metadata::ofDependencyMetadata(
226
-							DependencyMetadata::ofEntityId( $entityId )
226
+							DependencyMetadata::ofEntityId($entityId)
227 227
 						)
228
-					] );
228
+					]);
229 229
 				},
230 230
 				Metadata::ofCachingMetadata(
231 231
 					$ageInSeconds > 0 ?
232
-						CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) :
233
-						CachingMetadata::fresh()
232
+						CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh()
234 233
 				)
235 234
 			)
236 235
 		);
@@ -240,11 +239,11 @@  discard block
 block discarded – undo
240 239
 	 * @param EntityId[] $entityIds
241 240
 	 * @return int[]
242 241
 	 */
243
-	private function getLatestRevisionIds( array $entityIds ) {
242
+	private function getLatestRevisionIds(array $entityIds) {
244 243
 		$latestRevisionIds = [];
245
-		foreach ( $entityIds as $entityId ) {
244
+		foreach ($entityIds as $entityId) {
246 245
 			$serialization = $entityId->getSerialization();
247
-			$latestRevisionId = $this->entityRevisionLookup->getLatestRevisionId( $entityId );
246
+			$latestRevisionId = $this->entityRevisionLookup->getLatestRevisionId($entityId);
248 247
 			$latestRevisionIds[$serialization] = $latestRevisionId;
249 248
 		}
250 249
 		return $latestRevisionIds;
@@ -255,7 +254,7 @@  discard block
 block discarded – undo
255 254
 	 *
256 255
 	 * @param callable $microtime
257 256
 	 */
258
-	public function setMicrotimeFunction( callable $microtime ) {
257
+	public function setMicrotimeFunction(callable $microtime) {
259 258
 		$this->microtime = $microtime;
260 259
 	}
261 260
 
Please login to merge, or discard this patch.
src/Api/CheckConstraints.php 1 patch
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -69,22 +69,22 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @return self
71 71
 	 */
72
-	public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) {
72
+	public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') {
73 73
 		$repo = WikibaseRepo::getDefaultInstance();
74 74
 
75 75
 		$language = $repo->getUserLanguage();
76 76
 		$formatterOptions = new FormatterOptions();
77
-		$formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() );
77
+		$formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode());
78 78
 		$valueFormatterFactory = $repo->getValueFormatterFactory();
79
-		$valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions );
79
+		$valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions);
80 80
 
81 81
 		$languageFallbackLabelDescriptionLookupFactory = $repo->getLanguageFallbackLabelDescriptionLookupFactory();
82
-		$labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup( $language );
82
+		$labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup($language);
83 83
 		$entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory();
84
-		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup );
84
+		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($labelDescriptionLookup);
85 85
 		$entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory();
86
-		$entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup );
87
-		$constraintParameterRenderer = new ConstraintParameterRenderer( $entityIdHtmlLinkFormatter, $valueFormatter );
86
+		$entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($labelDescriptionLookup);
87
+		$constraintParameterRenderer = new ConstraintParameterRenderer($entityIdHtmlLinkFormatter, $valueFormatter);
88 88
 		$config = MediaWikiServices::getInstance()->getMainConfig();
89 89
 		$titleParser = MediaWikiServices::getInstance()->getTitleParser();
90 90
 		$unitConverter = $repo->getUnitConverter();
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 			$constraintParameterRenderer,
113 113
 			$config
114 114
 		);
115
-		if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) {
115
+		if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) {
116 116
 			$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
117 117
 			$entityRevisionLookup = $repo->getEntityRevisionLookup();
118 118
 			$entityIdParser = $repo->getEntityIdParser();
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 				$cache,
122 122
 				$entityRevisionLookup,
123 123
 				$entityIdParser,
124
-				$config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' )
124
+				$config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds')
125 125
 			);
126 126
 		}
127 127
 
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 			$prefix,
132 132
 			$repo->getEntityIdParser(),
133 133
 			$repo->getStatementGuidValidator(),
134
-			$repo->getApiHelperFactory( RequestContext::getMain() ),
134
+			$repo->getApiHelperFactory(RequestContext::getMain()),
135 135
 			$resultsBuilder
136 136
 		);
137 137
 	}
@@ -145,16 +145,16 @@  discard block
 block discarded – undo
145 145
 	 * @param ApiHelperFactory $apiHelperFactory
146 146
 	 * @param ResultsBuilder $resultsBuilder
147 147
 	 */
148
-	public function __construct( ApiMain $main, $name, $prefix = '', EntityIdParser $entityIdParser,
148
+	public function __construct(ApiMain $main, $name, $prefix = '', EntityIdParser $entityIdParser,
149 149
 								 StatementGuidValidator $statementGuidValidator,
150 150
 								 ApiHelperFactory $apiHelperFactory,
151 151
 								 ResultsBuilder $resultsBuilder
152 152
 	) {
153
-		parent::__construct( $main, $name, $prefix );
153
+		parent::__construct($main, $name, $prefix);
154 154
 		$this->entityIdParser = $entityIdParser;
155 155
 		$this->statementGuidValidator = $statementGuidValidator;
156
-		$this->resultBuilder = $apiHelperFactory->getResultBuilder( $this );
157
-		$this->errorReporter = $apiHelperFactory->getErrorReporter( $this );
156
+		$this->resultBuilder = $apiHelperFactory->getResultBuilder($this);
157
+		$this->errorReporter = $apiHelperFactory->getErrorReporter($this);
158 158
 		$this->resultsBuilder = $resultsBuilder;
159 159
 	}
160 160
 
@@ -163,13 +163,13 @@  discard block
 block discarded – undo
163 163
 	 */
164 164
 	public function execute() {
165 165
 		MediaWikiServices::getInstance()->getStatsdDataFactory()
166
-			->increment( 'wikibase.quality.constraints.api.checkConstraints.execute' );
166
+			->increment('wikibase.quality.constraints.api.checkConstraints.execute');
167 167
 
168 168
 		$params = $this->extractRequestParams();
169 169
 
170
-		$this->validateParameters( $params );
171
-		$entityIds = $this->parseEntityIds( $params );
172
-		$claimIds = $this->parseClaimIds( $params );
170
+		$this->validateParameters($params);
171
+		$entityIds = $this->parseEntityIds($params);
172
+		$claimIds = $this->parseClaimIds($params);
173 173
 		$constraintIDs = $params[self::PARAM_CONSTRAINT_ID];
174 174
 
175 175
 		$this->getResult()->addValue(
@@ -181,64 +181,64 @@  discard block
 block discarded – undo
181 181
 			)->getArray()
182 182
 		);
183 183
 		// ensure that result contains the given entity IDs even if they have no statements
184
-		foreach ( $entityIds as $entityId ) {
184
+		foreach ($entityIds as $entityId) {
185 185
 			$this->getResult()->addArrayType(
186
-				[ $this->getModuleName(), $entityId->getSerialization() ],
186
+				[$this->getModuleName(), $entityId->getSerialization()],
187 187
 				'assoc'
188 188
 			);
189 189
 		}
190
-		$this->resultBuilder->markSuccess( 1 );
190
+		$this->resultBuilder->markSuccess(1);
191 191
 	}
192 192
 
193
-	private function parseEntityIds( array $params ) {
193
+	private function parseEntityIds(array $params) {
194 194
 		$ids = $params[self::PARAM_ID];
195 195
 
196
-		if ( $ids === null ) {
196
+		if ($ids === null) {
197 197
 			return [];
198
-		} elseif ( $ids === [] ) {
198
+		} elseif ($ids === []) {
199 199
 			$this->errorReporter->dieError(
200
-				'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' );
200
+				'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' );
201 201
 		}
202 202
 
203
-		return array_map( function ( $id ) {
203
+		return array_map(function($id) {
204 204
 			try {
205
-				return $this->entityIdParser->parse( $id );
206
-			} catch ( EntityIdParsingException $e ) {
205
+				return $this->entityIdParser->parse($id);
206
+			} catch (EntityIdParsingException $e) {
207 207
 				$this->errorReporter->dieError(
208
-					"Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] );
208
+					"Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] );
209 209
 			}
210
-		}, $ids );
210
+		}, $ids);
211 211
 	}
212 212
 
213
-	private function parseClaimIds( array $params ) {
213
+	private function parseClaimIds(array $params) {
214 214
 		$ids = $params[self::PARAM_CLAIM_ID];
215 215
 
216
-		if ( $ids === null ) {
216
+		if ($ids === null) {
217 217
 			return [];
218
-		} elseif ( $ids === [] ) {
218
+		} elseif ($ids === []) {
219 219
 			$this->errorReporter->dieError(
220
-				'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' );
220
+				'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' );
221 221
 		}
222 222
 
223
-		foreach ( $ids as $id ) {
224
-			if ( !$this->statementGuidValidator->validate( $id ) ) {
223
+		foreach ($ids as $id) {
224
+			if (!$this->statementGuidValidator->validate($id)) {
225 225
 				$this->errorReporter->dieError(
226
-					"Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] );
226
+					"Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] );
227 227
 			}
228 228
 		}
229 229
 
230 230
 		return $ids;
231 231
 	}
232 232
 
233
-	private function validateParameters( array $params ) {
234
-		if ( $params[self::PARAM_CONSTRAINT_ID] !== null
235
-			 && empty( $params[self::PARAM_CONSTRAINT_ID] )
233
+	private function validateParameters(array $params) {
234
+		if ($params[self::PARAM_CONSTRAINT_ID] !== null
235
+			 && empty($params[self::PARAM_CONSTRAINT_ID])
236 236
 		) {
237 237
 			$paramConstraintId = self::PARAM_CONSTRAINT_ID;
238 238
 			$this->errorReporter->dieError(
239 239
 				"If $paramConstraintId is specified, it must be nonempty.", 'no-data' );
240 240
 		}
241
-		if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) {
241
+		if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) {
242 242
 			$paramId = self::PARAM_ID;
243 243
 			$paramClaimId = self::PARAM_CLAIM_ID;
244 244
 			$this->errorReporter->dieError(
Please login to merge, or discard this patch.