Completed
Push — master ( e0d9db...fc532a )
by
unknown
20s
created
src/Api/CheckConstraintParameters.php 1 patch
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types=1);
4 4
 
5 5
 namespace WikibaseQuality\ConstraintReport\Api;
6 6
 
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 			$delegatingConstraintChecker,
66 66
 			$violationMessageRendererFactory,
67 67
 			$statementGuidParser,
68
-			$statsFactory->withComponent( 'WikibaseQualityConstraints' )
68
+			$statsFactory->withComponent('WikibaseQualityConstraints')
69 69
 		);
70 70
 	}
71 71
 
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
 		StatementGuidParser $statementGuidParser,
80 80
 		StatsFactory $statsFactory
81 81
 	) {
82
-		parent::__construct( $main, $name );
82
+		parent::__construct($main, $name);
83 83
 
84
-		$this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this );
84
+		$this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this);
85 85
 		$this->languageFallbackChainFactory = $languageFallbackChainFactory;
86 86
 		$this->delegatingConstraintChecker = $delegatingConstraintChecker;
87 87
 		$this->violationMessageRendererFactory = $violationMessageRendererFactory;
@@ -90,47 +90,47 @@  discard block
 block discarded – undo
90 90
 	}
91 91
 
92 92
 	public function execute() {
93
-		$this->statsFactory->getCounter( 'check_constraint_parameters_execute_total' )
93
+		$this->statsFactory->getCounter('check_constraint_parameters_execute_total')
94 94
 			->increment();
95 95
 
96
-		$this->checkUserRightsAny( 'wbqc-check-constraints' );
96
+		$this->checkUserRightsAny('wbqc-check-constraints');
97 97
 
98 98
 		$params = $this->extractRequestParams();
99 99
 		$result = $this->getResult();
100 100
 
101
-		$propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] );
102
-		$constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] );
101
+		$propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]);
102
+		$constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]);
103 103
 
104
-		$this->checkPropertyIds( $propertyIds, $result );
105
-		$this->checkConstraintIds( $constraintIds, $result );
104
+		$this->checkPropertyIds($propertyIds, $result);
105
+		$this->checkConstraintIds($constraintIds, $result);
106 106
 
107
-		$result->addValue( null, 'success', 1 );
107
+		$result->addValue(null, 'success', 1);
108 108
 	}
109 109
 
110 110
 	/**
111 111
 	 * @param array|null $propertyIdSerializations
112 112
 	 * @return NumericPropertyId[]
113 113
 	 */
114
-	private function parsePropertyIds( ?array $propertyIdSerializations ): array {
115
-		if ( $propertyIdSerializations === null ) {
114
+	private function parsePropertyIds(?array $propertyIdSerializations): array {
115
+		if ($propertyIdSerializations === null) {
116 116
 			return [];
117
-		} elseif ( $propertyIdSerializations === [] ) {
117
+		} elseif ($propertyIdSerializations === []) {
118 118
 			$this->apiErrorReporter->dieError(
119
-				'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.',
119
+				'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.',
120 120
 				'no-data'
121 121
 			);
122 122
 		}
123 123
 
124 124
 		return array_map(
125
-			function ( $propertyIdSerialization ) {
125
+			function($propertyIdSerialization) {
126 126
 				try {
127
-					return new NumericPropertyId( $propertyIdSerialization );
128
-				} catch ( InvalidArgumentException ) {
127
+					return new NumericPropertyId($propertyIdSerialization);
128
+				} catch (InvalidArgumentException) {
129 129
 					$this->apiErrorReporter->dieError(
130 130
 						"Invalid id: $propertyIdSerialization",
131 131
 						'invalid-property-id',
132 132
 						0, // default argument
133
-						[ self::PARAM_PROPERTY_ID => $propertyIdSerialization ]
133
+						[self::PARAM_PROPERTY_ID => $propertyIdSerialization]
134 134
 					);
135 135
 				}
136 136
 			},
@@ -142,35 +142,35 @@  discard block
 block discarded – undo
142 142
 	 * @param array|null $constraintIds
143 143
 	 * @return string[]
144 144
 	 */
145
-	private function parseConstraintIds( ?array $constraintIds ): array {
146
-		if ( $constraintIds === null ) {
145
+	private function parseConstraintIds(?array $constraintIds): array {
146
+		if ($constraintIds === null) {
147 147
 			return [];
148
-		} elseif ( $constraintIds === [] ) {
148
+		} elseif ($constraintIds === []) {
149 149
 			$this->apiErrorReporter->dieError(
150
-				'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.',
150
+				'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.',
151 151
 				'no-data'
152 152
 			);
153 153
 		}
154 154
 
155 155
 		return array_map(
156
-			function ( $constraintId ) {
156
+			function($constraintId) {
157 157
 				try {
158
-					$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
159
-					if ( !$propertyId instanceof NumericPropertyId ) {
158
+					$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
159
+					if (!$propertyId instanceof NumericPropertyId) {
160 160
 						$this->apiErrorReporter->dieError(
161 161
 							"Invalid property ID: {$propertyId->getSerialization()}",
162 162
 							'invalid-property-id',
163 163
 							0, // default argument
164
-							[ self::PARAM_CONSTRAINT_ID => $constraintId ]
164
+							[self::PARAM_CONSTRAINT_ID => $constraintId]
165 165
 						);
166 166
 					}
167 167
 					return $constraintId;
168
-				} catch ( StatementGuidParsingException ) {
168
+				} catch (StatementGuidParsingException) {
169 169
 					$this->apiErrorReporter->dieError(
170 170
 						"Invalid statement GUID: $constraintId",
171 171
 						'invalid-guid',
172 172
 						0, // default argument
173
-						[ self::PARAM_CONSTRAINT_ID => $constraintId ]
173
+						[self::PARAM_CONSTRAINT_ID => $constraintId]
174 174
 					);
175 175
 				}
176 176
 			},
@@ -182,12 +182,12 @@  discard block
 block discarded – undo
182 182
 	 * @param NumericPropertyId[] $propertyIds
183 183
 	 * @param ApiResult $result
184 184
 	 */
185
-	private function checkPropertyIds( array $propertyIds, ApiResult $result ): void {
186
-		foreach ( $propertyIds as $propertyId ) {
187
-			$result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' );
185
+	private function checkPropertyIds(array $propertyIds, ApiResult $result): void {
186
+		foreach ($propertyIds as $propertyId) {
187
+			$result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc');
188 188
 			$allConstraintExceptions = $this->delegatingConstraintChecker
189
-				->checkConstraintParametersOnPropertyId( $propertyId );
190
-			foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) {
189
+				->checkConstraintParametersOnPropertyId($propertyId);
190
+			foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) {
191 191
 				$this->addConstraintParameterExceptionsToResult(
192 192
 					$constraintId,
193 193
 					$constraintParameterExceptions,
@@ -201,15 +201,15 @@  discard block
 block discarded – undo
201 201
 	 * @param string[] $constraintIds
202 202
 	 * @param ApiResult $result
203 203
 	 */
204
-	private function checkConstraintIds( array $constraintIds, ApiResult $result ): void {
205
-		foreach ( $constraintIds as $constraintId ) {
206
-			if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) {
204
+	private function checkConstraintIds(array $constraintIds, ApiResult $result): void {
205
+		foreach ($constraintIds as $constraintId) {
206
+			if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) {
207 207
 				// already checked as part of checkPropertyIds()
208 208
 				continue;
209 209
 			}
210 210
 			$constraintParameterExceptions = $this->delegatingConstraintChecker
211
-				->checkConstraintParametersOnConstraintId( $constraintId );
212
-			$this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result );
211
+				->checkConstraintParametersOnConstraintId($constraintId);
212
+			$this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result);
213 213
 		}
214 214
 	}
215 215
 
@@ -217,18 +217,18 @@  discard block
 block discarded – undo
217 217
 	 * @param NumericPropertyId $propertyId
218 218
 	 * @return string[]
219 219
 	 */
220
-	private function getResultPathForPropertyId( NumericPropertyId $propertyId ): array {
221
-		return [ $this->getModuleName(), $propertyId->getSerialization() ];
220
+	private function getResultPathForPropertyId(NumericPropertyId $propertyId): array {
221
+		return [$this->getModuleName(), $propertyId->getSerialization()];
222 222
 	}
223 223
 
224 224
 	/**
225 225
 	 * @param string $constraintId
226 226
 	 * @return string[]
227 227
 	 */
228
-	private function getResultPathForConstraintId( string $constraintId ): array {
229
-		$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
228
+	private function getResultPathForConstraintId(string $constraintId): array {
229
+		$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
230 230
 		'@phan-var NumericPropertyId $propertyId';
231
-		return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] );
231
+		return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]);
232 232
 	}
233 233
 
234 234
 	/**
@@ -243,8 +243,8 @@  discard block
 block discarded – undo
243 243
 		?array $constraintParameterExceptions,
244 244
 		ApiResult $result
245 245
 	): void {
246
-		$path = $this->getResultPathForConstraintId( $constraintId );
247
-		if ( $constraintParameterExceptions === null ) {
246
+		$path = $this->getResultPathForConstraintId($constraintId);
247
+		if ($constraintParameterExceptions === null) {
248 248
 			$result->addValue(
249 249
 				$path,
250 250
 				self::KEY_STATUS,
@@ -261,11 +261,11 @@  discard block
 block discarded – undo
261 261
 			$violationMessageRenderer = $this->violationMessageRendererFactory
262 262
 				->getViolationMessageRenderer(
263 263
 					$language,
264
-					$this->languageFallbackChainFactory->newFromLanguage( $language ),
264
+					$this->languageFallbackChainFactory->newFromLanguage($language),
265 265
 					$this
266 266
 				);
267 267
 			$problems = [];
268
-			foreach ( $constraintParameterExceptions as $constraintParameterException ) {
268
+			foreach ($constraintParameterExceptions as $constraintParameterException) {
269 269
 				$problems[] = [
270 270
 					self::KEY_MESSAGE_HTML => $violationMessageRenderer->render(
271 271
 						$constraintParameterException->getViolationMessage() ),
@@ -304,8 +304,8 @@  discard block
 block discarded – undo
304 304
 		return [
305 305
 			'action=wbcheckconstraintparameters&propertyid=P247'
306 306
 				=> 'apihelp-wbcheckconstraintparameters-example-propertyid-1',
307
-			'action=wbcheckconstraintparameters&' .
308
-			'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|' .
307
+			'action=wbcheckconstraintparameters&'.
308
+			'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|'.
309 309
 			'P225$cdc71e4a-47a0-12c5-dfb3-3f6fc0b6613f'
310 310
 				=> 'apihelp-wbcheckconstraintparameters-example-constraintid-2',
311 311
 		];
Please login to merge, or discard this patch.
src/WikibaseQualityConstraintsHooks.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -20,46 +20,46 @@
 block discarded – undo
20 20
 {
21 21
 
22 22
 	/** @inheritDoc */
23
-	public function onArticlePurge( $wikiPage ) {
23
+	public function onArticlePurge($wikiPage) {
24 24
 		$entityContentFactory = WikibaseRepo::getEntityContentFactory();
25
-		if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) {
25
+		if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) {
26 26
 			$entityIdLookup = WikibaseRepo::getEntityIdLookup();
27
-			$entityId = $entityIdLookup->getEntityIdForTitle( $wikiPage->getTitle() );
28
-			if ( $entityId !== null ) {
27
+			$entityId = $entityIdLookup->getEntityIdForTitle($wikiPage->getTitle());
28
+			if ($entityId !== null) {
29 29
 				$resultsCache = ResultsCache::getDefaultInstance();
30
-				$resultsCache->delete( $entityId );
30
+				$resultsCache->delete($entityId);
31 31
 			}
32 32
 		}
33 33
 	}
34 34
 
35 35
 	/** @inheritDoc */
36
-	public function onBeforePageDisplay( $out, $skin ): void {
36
+	public function onBeforePageDisplay($out, $skin): void {
37 37
 		$lookup = WikibaseRepo::getEntityNamespaceLookup();
38 38
 		$title = $out->getTitle();
39
-		if ( $title === null ) {
39
+		if ($title === null) {
40 40
 			return;
41 41
 		}
42 42
 
43
-		if ( !$lookup->isNamespaceWithEntities( $title->getNamespace() ) ) {
43
+		if (!$lookup->isNamespaceWithEntities($title->getNamespace())) {
44 44
 			return;
45 45
 		}
46
-		if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) {
46
+		if (empty($out->getJsConfigVars()['wbIsEditView'])) {
47 47
 			return;
48 48
 		}
49 49
 
50 50
 		$services = MediaWikiServices::getInstance();
51 51
 		$config = $services->getMainConfig();
52 52
 
53
-		$isMobileView = ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) &&
54
-			$services->getService( 'MobileFrontend.Context' )->shouldDisplayMobileView();
55
-		if ( $isMobileView ) {
53
+		$isMobileView = ExtensionRegistry::getInstance()->isLoaded('MobileFrontend') &&
54
+			$services->getService('MobileFrontend.Context')->shouldDisplayMobileView();
55
+		if ($isMobileView) {
56 56
 			return;
57 57
 		}
58 58
 
59
-		$out->addModules( 'wikibase.quality.constraints.suggestions' );
59
+		$out->addModules('wikibase.quality.constraints.suggestions');
60 60
 
61
-		if ( $out->getUser()->isAllowed( 'wbqc-check-constraints' ) ) {
62
-			$out->addModules( 'wikibase.quality.constraints.gadget' );
61
+		if ($out->getUser()->isAllowed('wbqc-check-constraints')) {
62
+			$out->addModules('wikibase.quality.constraints.gadget');
63 63
 		}
64 64
 	}
65 65
 
Please login to merge, or discard this patch.