Completed
Push — master ( 5ce08f...b7f7c6 )
by
unknown
01:53
created
src/Api/CheckConstraintParameters.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -79,15 +79,15 @@  discard block
 block discarded – undo
79 79
 		DelegatingConstraintChecker $delegatingConstraintChecker
80 80
 	): self {
81 81
 		$repo = WikibaseRepo::getDefaultInstance();
82
-		$helperFactory = $repo->getApiHelperFactory( $main->getContext() );
82
+		$helperFactory = $repo->getApiHelperFactory($main->getContext());
83 83
 		$language = WikibaseRepo::getUserLanguage();
84 84
 
85 85
 		$entityIdHtmlLinkFormatter = $entityIdFormatterFactory
86
-			->getEntityIdFormatter( $language );
86
+			->getEntityIdFormatter($language);
87 87
 		$formatterOptions = new FormatterOptions();
88
-		$formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() );
88
+		$formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode());
89 89
 		$dataValueFormatter = $valueFormatterFactory
90
-			->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions );
90
+			->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions);
91 91
 		$violationMessageRenderer = new MultilingualTextViolationMessageRenderer(
92 92
 			$entityIdHtmlLinkFormatter,
93 93
 			$dataValueFormatter,
@@ -123,9 +123,9 @@  discard block
 block discarded – undo
123 123
 		StatementGuidParser $statementGuidParser,
124 124
 		IBufferingStatsdDataFactory $dataFactory
125 125
 	) {
126
-		parent::__construct( $main, $name );
126
+		parent::__construct($main, $name);
127 127
 
128
-		$this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this );
128
+		$this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this);
129 129
 		$this->delegatingConstraintChecker = $delegatingConstraintChecker;
130 130
 		$this->violationMessageRenderer = $violationMessageRenderer;
131 131
 		$this->statementGuidParser = $statementGuidParser;
@@ -140,39 +140,39 @@  discard block
 block discarded – undo
140 140
 		$params = $this->extractRequestParams();
141 141
 		$result = $this->getResult();
142 142
 
143
-		$propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] );
144
-		$constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] );
143
+		$propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]);
144
+		$constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]);
145 145
 
146
-		$this->checkPropertyIds( $propertyIds, $result );
147
-		$this->checkConstraintIds( $constraintIds, $result );
146
+		$this->checkPropertyIds($propertyIds, $result);
147
+		$this->checkConstraintIds($constraintIds, $result);
148 148
 
149
-		$result->addValue( null, 'success', 1 );
149
+		$result->addValue(null, 'success', 1);
150 150
 	}
151 151
 
152 152
 	/**
153 153
 	 * @param array|null $propertyIdSerializations
154 154
 	 * @return PropertyId[]
155 155
 	 */
156
-	private function parsePropertyIds( $propertyIdSerializations ) {
157
-		if ( $propertyIdSerializations === null ) {
156
+	private function parsePropertyIds($propertyIdSerializations) {
157
+		if ($propertyIdSerializations === null) {
158 158
 			return [];
159
-		} elseif ( empty( $propertyIdSerializations ) ) {
159
+		} elseif (empty($propertyIdSerializations)) {
160 160
 			$this->apiErrorReporter->dieError(
161
-				'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.',
161
+				'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.',
162 162
 				'no-data'
163 163
 			);
164 164
 		}
165 165
 
166 166
 		return array_map(
167
-			function ( $propertyIdSerialization ) {
167
+			function($propertyIdSerialization) {
168 168
 				try {
169
-					return new PropertyId( $propertyIdSerialization );
170
-				} catch ( InvalidArgumentException $e ) {
169
+					return new PropertyId($propertyIdSerialization);
170
+				} catch (InvalidArgumentException $e) {
171 171
 					$this->apiErrorReporter->dieError(
172 172
 						"Invalid id: $propertyIdSerialization",
173 173
 						'invalid-property-id',
174 174
 						0, // default argument
175
-						[ self::PARAM_PROPERTY_ID => $propertyIdSerialization ]
175
+						[self::PARAM_PROPERTY_ID => $propertyIdSerialization]
176 176
 					);
177 177
 				}
178 178
 			},
@@ -184,35 +184,35 @@  discard block
 block discarded – undo
184 184
 	 * @param array|null $constraintIds
185 185
 	 * @return string[]
186 186
 	 */
187
-	private function parseConstraintIds( $constraintIds ) {
188
-		if ( $constraintIds === null ) {
187
+	private function parseConstraintIds($constraintIds) {
188
+		if ($constraintIds === null) {
189 189
 			return [];
190
-		} elseif ( empty( $constraintIds ) ) {
190
+		} elseif (empty($constraintIds)) {
191 191
 			$this->apiErrorReporter->dieError(
192
-				'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.',
192
+				'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.',
193 193
 				'no-data'
194 194
 			);
195 195
 		}
196 196
 
197 197
 		return array_map(
198
-			function ( $constraintId ) {
198
+			function($constraintId) {
199 199
 				try {
200
-					$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
201
-					if ( !$propertyId instanceof PropertyId ) {
200
+					$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
201
+					if (!$propertyId instanceof PropertyId) {
202 202
 						$this->apiErrorReporter->dieError(
203 203
 							"Invalid property ID: {$propertyId->getSerialization()}",
204 204
 							'invalid-property-id',
205 205
 							0, // default argument
206
-							[ self::PARAM_CONSTRAINT_ID => $constraintId ]
206
+							[self::PARAM_CONSTRAINT_ID => $constraintId]
207 207
 						);
208 208
 					}
209 209
 					return $constraintId;
210
-				} catch ( StatementGuidParsingException $e ) {
210
+				} catch (StatementGuidParsingException $e) {
211 211
 					$this->apiErrorReporter->dieError(
212 212
 						"Invalid statement GUID: $constraintId",
213 213
 						'invalid-guid',
214 214
 						0, // default argument
215
-						[ self::PARAM_CONSTRAINT_ID => $constraintId ]
215
+						[self::PARAM_CONSTRAINT_ID => $constraintId]
216 216
 					);
217 217
 				}
218 218
 			},
@@ -224,12 +224,12 @@  discard block
 block discarded – undo
224 224
 	 * @param PropertyId[] $propertyIds
225 225
 	 * @param ApiResult $result
226 226
 	 */
227
-	private function checkPropertyIds( array $propertyIds, ApiResult $result ) {
228
-		foreach ( $propertyIds as $propertyId ) {
229
-			$result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' );
227
+	private function checkPropertyIds(array $propertyIds, ApiResult $result) {
228
+		foreach ($propertyIds as $propertyId) {
229
+			$result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc');
230 230
 			$allConstraintExceptions = $this->delegatingConstraintChecker
231
-				->checkConstraintParametersOnPropertyId( $propertyId );
232
-			foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) {
231
+				->checkConstraintParametersOnPropertyId($propertyId);
232
+			foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) {
233 233
 				$this->addConstraintParameterExceptionsToResult(
234 234
 					$constraintId,
235 235
 					$constraintParameterExceptions,
@@ -243,15 +243,15 @@  discard block
 block discarded – undo
243 243
 	 * @param string[] $constraintIds
244 244
 	 * @param ApiResult $result
245 245
 	 */
246
-	private function checkConstraintIds( array $constraintIds, ApiResult $result ) {
247
-		foreach ( $constraintIds as $constraintId ) {
248
-			if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) {
246
+	private function checkConstraintIds(array $constraintIds, ApiResult $result) {
247
+		foreach ($constraintIds as $constraintId) {
248
+			if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) {
249 249
 				// already checked as part of checkPropertyIds()
250 250
 				continue;
251 251
 			}
252 252
 			$constraintParameterExceptions = $this->delegatingConstraintChecker
253
-				->checkConstraintParametersOnConstraintId( $constraintId );
254
-			$this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result );
253
+				->checkConstraintParametersOnConstraintId($constraintId);
254
+			$this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result);
255 255
 		}
256 256
 	}
257 257
 
@@ -259,18 +259,18 @@  discard block
 block discarded – undo
259 259
 	 * @param PropertyId $propertyId
260 260
 	 * @return string[]
261 261
 	 */
262
-	private function getResultPathForPropertyId( PropertyId $propertyId ) {
263
-		return [ $this->getModuleName(), $propertyId->getSerialization() ];
262
+	private function getResultPathForPropertyId(PropertyId $propertyId) {
263
+		return [$this->getModuleName(), $propertyId->getSerialization()];
264 264
 	}
265 265
 
266 266
 	/**
267 267
 	 * @param string $constraintId
268 268
 	 * @return string[]
269 269
 	 */
270
-	private function getResultPathForConstraintId( $constraintId ) {
271
-		$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
270
+	private function getResultPathForConstraintId($constraintId) {
271
+		$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
272 272
 		'@phan-var PropertyId $propertyId';
273
-		return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] );
273
+		return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]);
274 274
 	}
275 275
 
276 276
 	/**
@@ -285,8 +285,8 @@  discard block
 block discarded – undo
285 285
 		$constraintParameterExceptions,
286 286
 		ApiResult $result
287 287
 	) {
288
-		$path = $this->getResultPathForConstraintId( $constraintId );
289
-		if ( $constraintParameterExceptions === null ) {
288
+		$path = $this->getResultPathForConstraintId($constraintId);
289
+		if ($constraintParameterExceptions === null) {
290 290
 			$result->addValue(
291 291
 				$path,
292 292
 				self::KEY_STATUS,
@@ -296,12 +296,12 @@  discard block
 block discarded – undo
296 296
 			$result->addValue(
297 297
 				$path,
298 298
 				self::KEY_STATUS,
299
-				empty( $constraintParameterExceptions ) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY
299
+				empty($constraintParameterExceptions) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY
300 300
 			);
301 301
 			$result->addValue(
302 302
 				$path,
303 303
 				self::KEY_PROBLEMS,
304
-				array_map( [ $this, 'formatConstraintParameterException' ], $constraintParameterExceptions )
304
+				array_map([$this, 'formatConstraintParameterException'], $constraintParameterExceptions)
305 305
 			);
306 306
 		}
307 307
 	}
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
 	 * @param ConstraintParameterException $e
313 313
 	 * @return string[]
314 314
 	 */
315
-	private function formatConstraintParameterException( ConstraintParameterException $e ) {
315
+	private function formatConstraintParameterException(ConstraintParameterException $e) {
316 316
 		return [
317 317
 			self::KEY_MESSAGE_HTML => $this->violationMessageRenderer->render(
318 318
 				$e->getViolationMessage()
@@ -345,8 +345,8 @@  discard block
 block discarded – undo
345 345
 		return [
346 346
 			'action=wbcheckconstraintparameters&propertyid=P247'
347 347
 				=> 'apihelp-wbcheckconstraintparameters-example-propertyid-1',
348
-			'action=wbcheckconstraintparameters&' .
349
-			'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|' .
348
+			'action=wbcheckconstraintparameters&'.
349
+			'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|'.
350 350
 			'P225$cdc71e4a-47a0-12c5-dfb3-3f6fc0b6613f'
351 351
 				=> 'apihelp-wbcheckconstraintparameters-example-constraintid-2',
352 352
 		];
Please login to merge, or discard this patch.
src/Api/CheckConstraints.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -87,12 +87,12 @@  discard block
 block discarded – undo
87 87
 
88 88
 		$language = WikibaseRepo::getUserLanguage();
89 89
 		$formatterOptions = new FormatterOptions();
90
-		$formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() );
91
-		$valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions );
90
+		$formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode());
91
+		$valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions);
92 92
 
93
-		$entityIdHtmlLinkFormatter = $entityIdFormatterFactory->getEntityIdFormatter( $language );
93
+		$entityIdHtmlLinkFormatter = $entityIdFormatterFactory->getEntityIdFormatter($language);
94 94
 		$entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory();
95
-		$entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $language );
95
+		$entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($language);
96 96
 
97 97
 		$checkResultsRenderer = new CheckResultsRenderer(
98 98
 			$entityTitleLookup,
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 			$name,
111 111
 			$entityIdParser,
112 112
 			$statementGuidValidator,
113
-			$repo->getApiHelperFactory( $main->getContext() ),
113
+			$repo->getApiHelperFactory($main->getContext()),
114 114
 			$resultsSource,
115 115
 			$checkResultsRenderer,
116 116
 			$dataFactory
@@ -137,11 +137,11 @@  discard block
 block discarded – undo
137 137
 		CheckResultsRenderer $checkResultsRenderer,
138 138
 		IBufferingStatsdDataFactory $dataFactory
139 139
 	) {
140
-		parent::__construct( $main, $name );
140
+		parent::__construct($main, $name);
141 141
 		$this->entityIdParser = $entityIdParser;
142 142
 		$this->statementGuidValidator = $statementGuidValidator;
143
-		$this->resultBuilder = $apiHelperFactory->getResultBuilder( $this );
144
-		$this->errorReporter = $apiHelperFactory->getErrorReporter( $this );
143
+		$this->resultBuilder = $apiHelperFactory->getResultBuilder($this);
144
+		$this->errorReporter = $apiHelperFactory->getErrorReporter($this);
145 145
 		$this->resultsSource = $resultsSource;
146 146
 		$this->checkResultsRenderer = $checkResultsRenderer;
147 147
 		$this->dataFactory = $dataFactory;
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
 
158 158
 		$params = $this->extractRequestParams();
159 159
 
160
-		$this->validateParameters( $params );
161
-		$entityIds = $this->parseEntityIds( $params );
162
-		$claimIds = $this->parseClaimIds( $params );
160
+		$this->validateParameters($params);
161
+		$entityIds = $this->parseEntityIds($params);
162
+		$claimIds = $this->parseClaimIds($params);
163 163
 		$constraintIDs = $params[self::PARAM_CONSTRAINT_ID];
164 164
 		$statuses = $params[self::PARAM_STATUS];
165 165
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 				)
176 176
 			)->getArray()
177 177
 		);
178
-		$this->resultBuilder->markSuccess( 1 );
178
+		$this->resultBuilder->markSuccess(1);
179 179
 	}
180 180
 
181 181
 	/**
@@ -183,24 +183,24 @@  discard block
 block discarded – undo
183 183
 	 *
184 184
 	 * @return EntityId[]
185 185
 	 */
186
-	private function parseEntityIds( array $params ) {
186
+	private function parseEntityIds(array $params) {
187 187
 		$ids = $params[self::PARAM_ID];
188 188
 
189
-		if ( $ids === null ) {
189
+		if ($ids === null) {
190 190
 			return [];
191
-		} elseif ( $ids === [] ) {
191
+		} elseif ($ids === []) {
192 192
 			$this->errorReporter->dieError(
193
-				'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' );
193
+				'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' );
194 194
 		}
195 195
 
196
-		return array_map( function ( $id ) {
196
+		return array_map(function($id) {
197 197
 			try {
198
-				return $this->entityIdParser->parse( $id );
199
-			} catch ( EntityIdParsingException $e ) {
198
+				return $this->entityIdParser->parse($id);
199
+			} catch (EntityIdParsingException $e) {
200 200
 				$this->errorReporter->dieError(
201
-					"Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] );
201
+					"Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] );
202 202
 			}
203
-		}, $ids );
203
+		}, $ids);
204 204
 	}
205 205
 
206 206
 	/**
@@ -208,35 +208,35 @@  discard block
 block discarded – undo
208 208
 	 *
209 209
 	 * @return string[]
210 210
 	 */
211
-	private function parseClaimIds( array $params ) {
211
+	private function parseClaimIds(array $params) {
212 212
 		$ids = $params[self::PARAM_CLAIM_ID];
213 213
 
214
-		if ( $ids === null ) {
214
+		if ($ids === null) {
215 215
 			return [];
216
-		} elseif ( $ids === [] ) {
216
+		} elseif ($ids === []) {
217 217
 			$this->errorReporter->dieError(
218
-				'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' );
218
+				'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' );
219 219
 		}
220 220
 
221
-		foreach ( $ids as $id ) {
222
-			if ( !$this->statementGuidValidator->validate( $id ) ) {
221
+		foreach ($ids as $id) {
222
+			if (!$this->statementGuidValidator->validate($id)) {
223 223
 				$this->errorReporter->dieError(
224
-					"Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] );
224
+					"Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] );
225 225
 			}
226 226
 		}
227 227
 
228 228
 		return $ids;
229 229
 	}
230 230
 
231
-	private function validateParameters( array $params ) {
232
-		if ( $params[self::PARAM_CONSTRAINT_ID] !== null
233
-			 && empty( $params[self::PARAM_CONSTRAINT_ID] )
231
+	private function validateParameters(array $params) {
232
+		if ($params[self::PARAM_CONSTRAINT_ID] !== null
233
+			 && empty($params[self::PARAM_CONSTRAINT_ID])
234 234
 		) {
235 235
 			$paramConstraintId = self::PARAM_CONSTRAINT_ID;
236 236
 			$this->errorReporter->dieError(
237 237
 				"If $paramConstraintId is specified, it must be nonempty.", 'no-data' );
238 238
 		}
239
-		if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) {
239
+		if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) {
240 240
 			$paramId = self::PARAM_ID;
241 241
 			$paramClaimId = self::PARAM_CLAIM_ID;
242 242
 			$this->errorReporter->dieError(
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 				],
278 278
 				ApiBase::PARAM_ISMULTI => true,
279 279
 				ApiBase::PARAM_ALL => true,
280
-				ApiBase::PARAM_DFLT => implode( '|', CachingResultsSource::CACHED_STATUSES ),
280
+				ApiBase::PARAM_DFLT => implode('|', CachingResultsSource::CACHED_STATUSES),
281 281
 				ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
282 282
 			],
283 283
 		];
Please login to merge, or discard this patch.