Completed
Push — master ( 34e257...1bc588 )
by
unknown
04:04
created
src/UpdateConstraintsTableJob.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -28,8 +28,8 @@  discard block
 block discarded – undo
28 28
 
29 29
 	const BATCH_SIZE = 10;
30 30
 
31
-	public static function newFromGlobalState( Title $title, array $params ) {
32
-		Assert::parameterType( 'string', $params['propertyId'], '$params["propertyId"]' );
31
+	public static function newFromGlobalState(Title $title, array $params) {
32
+		Assert::parameterType('string', $params['propertyId'], '$params["propertyId"]');
33 33
 		$repo = WikibaseRepo::getDefaultInstance();
34 34
 		return new UpdateConstraintsTableJob(
35 35
 			$title,
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 			$params['revisionId'] ?? null,
39 39
 			MediaWikiServices::getInstance()->getMainConfig(),
40 40
 			ConstraintsServices::getConstraintRepository(),
41
-			$repo->getEntityRevisionLookup( Store::LOOKUP_CACHING_DISABLED ),
41
+			$repo->getEntityRevisionLookup(Store::LOOKUP_CACHING_DISABLED),
42 42
 			$repo->getBaseDataModelSerializerFactory()->newSnakSerializer()
43 43
 		);
44 44
 	}
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 		EntityRevisionLookup $entityRevisionLookup,
94 94
 		Serializer $snakSerializer
95 95
 	) {
96
-		parent::__construct( 'constraintsTableUpdate', $title, $params );
96
+		parent::__construct('constraintsTableUpdate', $title, $params);
97 97
 
98 98
 		$this->propertyId = $propertyId;
99 99
 		$this->revisionId = $revisionId;
@@ -103,11 +103,11 @@  discard block
 block discarded – undo
103 103
 		$this->snakSerializer = $snakSerializer;
104 104
 	}
105 105
 
106
-	public function extractParametersFromQualifiers( SnakList $qualifiers ) {
106
+	public function extractParametersFromQualifiers(SnakList $qualifiers) {
107 107
 		$parameters = [];
108
-		foreach ( $qualifiers as $qualifier ) {
108
+		foreach ($qualifiers as $qualifier) {
109 109
 			$qualifierId = $qualifier->getPropertyId()->getSerialization();
110
-			$paramSerialization = $this->snakSerializer->serialize( $qualifier );
110
+			$paramSerialization = $this->snakSerializer->serialize($qualifier);
111 111
 			$parameters[$qualifierId][] = $paramSerialization;
112 112
 		}
113 113
 		return $parameters;
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 		'@phan-var \Wikibase\DataModel\Entity\EntityIdValue $dataValue';
125 125
 		$entityId = $dataValue->getEntityId();
126 126
 		$constraintTypeQid = $entityId->getSerialization();
127
-		$parameters = $this->extractParametersFromQualifiers( $constraintStatement->getQualifiers() );
127
+		$parameters = $this->extractParametersFromQualifiers($constraintStatement->getQualifiers());
128 128
 		return new Constraint(
129 129
 			$constraintId,
130 130
 			$propertyId,
@@ -139,17 +139,17 @@  discard block
 block discarded – undo
139 139
 		PropertyId $propertyConstraintPropertyId
140 140
 	) {
141 141
 		$constraintsStatements = $property->getStatements()
142
-			->getByPropertyId( $propertyConstraintPropertyId )
143
-			->getByRank( [ Statement::RANK_PREFERRED, Statement::RANK_NORMAL ] );
142
+			->getByPropertyId($propertyConstraintPropertyId)
143
+			->getByRank([Statement::RANK_PREFERRED, Statement::RANK_NORMAL]);
144 144
 		$constraints = [];
145
-		foreach ( $constraintsStatements->getIterator() as $constraintStatement ) {
146
-			$constraints[] = $this->extractConstraintFromStatement( $property->getId(), $constraintStatement );
147
-			if ( count( $constraints ) >= self::BATCH_SIZE ) {
148
-				$constraintRepo->insertBatch( $constraints );
145
+		foreach ($constraintsStatements->getIterator() as $constraintStatement) {
146
+			$constraints[] = $this->extractConstraintFromStatement($property->getId(), $constraintStatement);
147
+			if (count($constraints) >= self::BATCH_SIZE) {
148
+				$constraintRepo->insertBatch($constraints);
149 149
 				$constraints = [];
150 150
 			}
151 151
 		}
152
-		$constraintRepo->insertBatch( $constraints );
152
+		$constraintRepo->insertBatch($constraints);
153 153
 	}
154 154
 
155 155
 	/**
@@ -160,19 +160,19 @@  discard block
 block discarded – undo
160 160
 	public function run() {
161 161
 		// TODO in the future: only touch constraints affected by the edit (requires T163465)
162 162
 
163
-		$propertyId = new PropertyId( $this->propertyId );
163
+		$propertyId = new PropertyId($this->propertyId);
164 164
 		$propertyRevision = $this->entityRevisionLookup->getEntityRevision(
165 165
 			$propertyId,
166 166
 			0, // latest
167 167
 			EntityRevisionLookup::LATEST_FROM_REPLICA
168 168
 		);
169 169
 
170
-		if ( $this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId ) {
171
-			JobQueueGroup::singleton()->push( $this );
170
+		if ($this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId) {
171
+			JobQueueGroup::singleton()->push($this);
172 172
 			return true;
173 173
 		}
174 174
 
175
-		$this->constraintRepo->deleteForProperty( $propertyId );
175
+		$this->constraintRepo->deleteForProperty($propertyId);
176 176
 
177 177
 		/** @var Property $property */
178 178
 		$property = $propertyRevision->getEntity();
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 		$this->importConstraintsForProperty(
181 181
 			$property,
182 182
 			$this->constraintRepo,
183
-			new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) )
183
+			new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId'))
184 184
 		);
185 185
 
186 186
 		return true;
Please login to merge, or discard this patch.
src/Job/CheckConstraintsJob.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -42,26 +42,26 @@  discard block
 block discarded – undo
42 42
 	 * @param Title $title
43 43
 	 * @param string[] $params should contain 'entityId' => 'Q1234'
44 44
 	 */
45
-	public function __construct( Title $title, array $params ) {
46
-		parent::__construct( self::COMMAND, $title, $params );
45
+	public function __construct(Title $title, array $params) {
46
+		parent::__construct(self::COMMAND, $title, $params);
47 47
 		$this->removeDuplicates = true;
48 48
 
49
-		Assert::parameterType( 'string', $params['entityId'], '$params[\'entityId\']' );
49
+		Assert::parameterType('string', $params['entityId'], '$params[\'entityId\']');
50 50
 		$this->entityId = $params['entityId'];
51 51
 
52
-		$resultSource = ConstraintsServices::getResultsSource( MediaWikiServices::getInstance() );
52
+		$resultSource = ConstraintsServices::getResultsSource(MediaWikiServices::getInstance());
53 53
 		'@phan-var CachingResultsSource $resultSource';
54 54
 		// This job should only ever be used when caching result sources are used.
55
-		$this->setResultsSource( $resultSource );
55
+		$this->setResultsSource($resultSource);
56 56
 
57
-		$this->setEntityIdParser( WikibaseRepo::getDefaultInstance()->getEntityIdParser() );
57
+		$this->setEntityIdParser(WikibaseRepo::getDefaultInstance()->getEntityIdParser());
58 58
 	}
59 59
 
60
-	public function setResultsSource( CachingResultsSource $resultsSource ) {
60
+	public function setResultsSource(CachingResultsSource $resultsSource) {
61 61
 		$this->resultsSource = $resultsSource;
62 62
 	}
63 63
 
64
-	public function setEntityIdParser( EntityIdParser $parser ) {
64
+	public function setEntityIdParser(EntityIdParser $parser) {
65 65
 		$this->entityIdParser = $parser;
66 66
 	}
67 67
 
@@ -72,19 +72,19 @@  discard block
 block discarded – undo
72 72
 	 */
73 73
 	public function run() {
74 74
 		try {
75
-			$entityId = $this->entityIdParser->parse( $this->entityId );
76
-		} catch ( EntityIdParsingException $e ) {
75
+			$entityId = $this->entityIdParser->parse($this->entityId);
76
+		} catch (EntityIdParsingException $e) {
77 77
 			return false;
78 78
 		}
79 79
 
80
-		$this->checkConstraints( $entityId );
80
+		$this->checkConstraints($entityId);
81 81
 
82 82
 		return true;
83 83
 	}
84 84
 
85
-	private function checkConstraints( EntityId $entityId ) {
85
+	private function checkConstraints(EntityId $entityId) {
86 86
 		$this->resultsSource->getResults(
87
-			[ $entityId ],
87
+			[$entityId],
88 88
 			[],
89 89
 			null,
90 90
 			[]
Please login to merge, or discard this patch.
src/Api/CheckConstraintParameters.php 1 patch
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -74,19 +74,19 @@  discard block
 block discarded – undo
74 74
 	 *
75 75
 	 * @return self
76 76
 	 */
77
-	public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) {
77
+	public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') {
78 78
 		$repo = WikibaseRepo::getDefaultInstance();
79
-		$helperFactory = $repo->getApiHelperFactory( RequestContext::getMain() );
79
+		$helperFactory = $repo->getApiHelperFactory(RequestContext::getMain());
80 80
 		$language = $repo->getUserLanguage();
81 81
 
82 82
 		$entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory();
83 83
 		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory
84
-			->getEntityIdFormatter( $language );
84
+			->getEntityIdFormatter($language);
85 85
 		$formatterOptions = new FormatterOptions();
86
-		$formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() );
86
+		$formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode());
87 87
 		$valueFormatterFactory = $repo->getValueFormatterFactory();
88 88
 		$dataValueFormatter = $valueFormatterFactory
89
-			->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions );
89
+			->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions);
90 90
 		$config = MediaWikiServices::getInstance()->getMainConfig();
91 91
 		$violationMessageRenderer = new MultilingualTextViolationMessageRenderer(
92 92
 			$entityIdHtmlLinkFormatter,
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
 		StatementGuidParser $statementGuidParser,
127 127
 		IBufferingStatsdDataFactory $dataFactory
128 128
 	) {
129
-		parent::__construct( $main, $name, $prefix );
129
+		parent::__construct($main, $name, $prefix);
130 130
 
131
-		$this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this );
131
+		$this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this);
132 132
 		$this->delegatingConstraintChecker = $delegatingConstraintChecker;
133 133
 		$this->violationMessageRenderer = $violationMessageRenderer;
134 134
 		$this->statementGuidParser = $statementGuidParser;
@@ -143,39 +143,39 @@  discard block
 block discarded – undo
143 143
 		$params = $this->extractRequestParams();
144 144
 		$result = $this->getResult();
145 145
 
146
-		$propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] );
147
-		$constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] );
146
+		$propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]);
147
+		$constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]);
148 148
 
149
-		$this->checkPropertyIds( $propertyIds, $result );
150
-		$this->checkConstraintIds( $constraintIds, $result );
149
+		$this->checkPropertyIds($propertyIds, $result);
150
+		$this->checkConstraintIds($constraintIds, $result);
151 151
 
152
-		$result->addValue( null, 'success', 1 );
152
+		$result->addValue(null, 'success', 1);
153 153
 	}
154 154
 
155 155
 	/**
156 156
 	 * @param array|null $propertyIdSerializations
157 157
 	 * @return PropertyId[]
158 158
 	 */
159
-	private function parsePropertyIds( $propertyIdSerializations ) {
160
-		if ( $propertyIdSerializations === null ) {
159
+	private function parsePropertyIds($propertyIdSerializations) {
160
+		if ($propertyIdSerializations === null) {
161 161
 			return [];
162
-		} elseif ( empty( $propertyIdSerializations ) ) {
162
+		} elseif (empty($propertyIdSerializations)) {
163 163
 			$this->apiErrorReporter->dieError(
164
-				'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.',
164
+				'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.',
165 165
 				'no-data'
166 166
 			);
167 167
 		}
168 168
 
169 169
 		return array_map(
170
-			function( $propertyIdSerialization ) {
170
+			function($propertyIdSerialization) {
171 171
 				try {
172
-					return new PropertyId( $propertyIdSerialization );
173
-				} catch ( InvalidArgumentException $e ) {
172
+					return new PropertyId($propertyIdSerialization);
173
+				} catch (InvalidArgumentException $e) {
174 174
 					$this->apiErrorReporter->dieError(
175 175
 						"Invalid id: $propertyIdSerialization",
176 176
 						'invalid-property-id',
177 177
 						0, // default argument
178
-						[ self::PARAM_PROPERTY_ID => $propertyIdSerialization ]
178
+						[self::PARAM_PROPERTY_ID => $propertyIdSerialization]
179 179
 					);
180 180
 				}
181 181
 			},
@@ -187,35 +187,35 @@  discard block
 block discarded – undo
187 187
 	 * @param array|null $constraintIds
188 188
 	 * @return string[]
189 189
 	 */
190
-	private function parseConstraintIds( $constraintIds ) {
191
-		if ( $constraintIds === null ) {
190
+	private function parseConstraintIds($constraintIds) {
191
+		if ($constraintIds === null) {
192 192
 			return [];
193
-		} elseif ( empty( $constraintIds ) ) {
193
+		} elseif (empty($constraintIds)) {
194 194
 			$this->apiErrorReporter->dieError(
195
-				'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.',
195
+				'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.',
196 196
 				'no-data'
197 197
 			);
198 198
 		}
199 199
 
200 200
 		return array_map(
201
-			function( $constraintId ) {
201
+			function($constraintId) {
202 202
 				try {
203
-					$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
204
-					if ( !$propertyId instanceof PropertyId ) {
203
+					$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
204
+					if (!$propertyId instanceof PropertyId) {
205 205
 						$this->apiErrorReporter->dieError(
206 206
 							"Invalid property ID: {$propertyId->getSerialization()}",
207 207
 							'invalid-property-id',
208 208
 							0, // default argument
209
-							[ self::PARAM_CONSTRAINT_ID => $constraintId ]
209
+							[self::PARAM_CONSTRAINT_ID => $constraintId]
210 210
 						);
211 211
 					}
212 212
 					return $constraintId;
213
-				} catch ( StatementGuidParsingException $e ) {
213
+				} catch (StatementGuidParsingException $e) {
214 214
 					$this->apiErrorReporter->dieError(
215 215
 						"Invalid statement GUID: $constraintId",
216 216
 						'invalid-guid',
217 217
 						0, // default argument
218
-						[ self::PARAM_CONSTRAINT_ID => $constraintId ]
218
+						[self::PARAM_CONSTRAINT_ID => $constraintId]
219 219
 					);
220 220
 				}
221 221
 			},
@@ -227,12 +227,12 @@  discard block
 block discarded – undo
227 227
 	 * @param PropertyId[] $propertyIds
228 228
 	 * @param ApiResult $result
229 229
 	 */
230
-	private function checkPropertyIds( array $propertyIds, ApiResult $result ) {
231
-		foreach ( $propertyIds as $propertyId ) {
232
-			$result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' );
230
+	private function checkPropertyIds(array $propertyIds, ApiResult $result) {
231
+		foreach ($propertyIds as $propertyId) {
232
+			$result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc');
233 233
 			$allConstraintExceptions = $this->delegatingConstraintChecker
234
-				->checkConstraintParametersOnPropertyId( $propertyId );
235
-			foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) {
234
+				->checkConstraintParametersOnPropertyId($propertyId);
235
+			foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) {
236 236
 				$this->addConstraintParameterExceptionsToResult(
237 237
 					$constraintId,
238 238
 					$constraintParameterExceptions,
@@ -246,15 +246,15 @@  discard block
 block discarded – undo
246 246
 	 * @param string[] $constraintIds
247 247
 	 * @param ApiResult $result
248 248
 	 */
249
-	private function checkConstraintIds( array $constraintIds, ApiResult $result ) {
250
-		foreach ( $constraintIds as $constraintId ) {
251
-			if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) {
249
+	private function checkConstraintIds(array $constraintIds, ApiResult $result) {
250
+		foreach ($constraintIds as $constraintId) {
251
+			if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) {
252 252
 				// already checked as part of checkPropertyIds()
253 253
 				continue;
254 254
 			}
255 255
 			$constraintParameterExceptions = $this->delegatingConstraintChecker
256
-				->checkConstraintParametersOnConstraintId( $constraintId );
257
-			$this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result );
256
+				->checkConstraintParametersOnConstraintId($constraintId);
257
+			$this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result);
258 258
 		}
259 259
 	}
260 260
 
@@ -262,18 +262,18 @@  discard block
 block discarded – undo
262 262
 	 * @param PropertyId $propertyId
263 263
 	 * @return string[]
264 264
 	 */
265
-	private function getResultPathForPropertyId( PropertyId $propertyId ) {
266
-		return [ $this->getModuleName(), $propertyId->getSerialization() ];
265
+	private function getResultPathForPropertyId(PropertyId $propertyId) {
266
+		return [$this->getModuleName(), $propertyId->getSerialization()];
267 267
 	}
268 268
 
269 269
 	/**
270 270
 	 * @param string $constraintId
271 271
 	 * @return string[]
272 272
 	 */
273
-	private function getResultPathForConstraintId( $constraintId ) {
274
-		$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
273
+	private function getResultPathForConstraintId($constraintId) {
274
+		$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
275 275
 		'@phan-var PropertyId $propertyId';
276
-		return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] );
276
+		return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]);
277 277
 	}
278 278
 
279 279
 	/**
@@ -288,8 +288,8 @@  discard block
 block discarded – undo
288 288
 		$constraintParameterExceptions,
289 289
 		ApiResult $result
290 290
 	) {
291
-		$path = $this->getResultPathForConstraintId( $constraintId );
292
-		if ( $constraintParameterExceptions === null ) {
291
+		$path = $this->getResultPathForConstraintId($constraintId);
292
+		if ($constraintParameterExceptions === null) {
293 293
 			$result->addValue(
294 294
 				$path,
295 295
 				self::KEY_STATUS,
@@ -299,12 +299,12 @@  discard block
 block discarded – undo
299 299
 			$result->addValue(
300 300
 				$path,
301 301
 				self::KEY_STATUS,
302
-				empty( $constraintParameterExceptions ) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY
302
+				empty($constraintParameterExceptions) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY
303 303
 			);
304 304
 			$result->addValue(
305 305
 				$path,
306 306
 				self::KEY_PROBLEMS,
307
-				array_map( [ $this, 'formatConstraintParameterException' ], $constraintParameterExceptions )
307
+				array_map([$this, 'formatConstraintParameterException'], $constraintParameterExceptions)
308 308
 			);
309 309
 		}
310 310
 	}
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 	 * @param ConstraintParameterException $e
316 316
 	 * @return string[]
317 317
 	 */
318
-	private function formatConstraintParameterException( ConstraintParameterException $e ) {
318
+	private function formatConstraintParameterException(ConstraintParameterException $e) {
319 319
 		return [
320 320
 			self::KEY_MESSAGE_HTML => $this->violationMessageRenderer->render(
321 321
 				$e->getViolationMessage()
@@ -348,8 +348,8 @@  discard block
 block discarded – undo
348 348
 		return [
349 349
 			'action=wbcheckconstraintparameters&propertyid=P247'
350 350
 				=> 'apihelp-wbcheckconstraintparameters-example-propertyid-1',
351
-			'action=wbcheckconstraintparameters&' .
352
-			'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|' .
351
+			'action=wbcheckconstraintparameters&'.
352
+			'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|'.
353 353
 			'P225$cdc71e4a-47a0-12c5-dfb3-3f6fc0b6613f'
354 354
 				=> 'apihelp-wbcheckconstraintparameters-example-constraintid-2',
355 355
 		];
Please login to merge, or discard this patch.