Completed
Push — master ( 7b7d2e...94ab99 )
by
unknown
04:28 queued 01:53
created
src/ConstraintParameterRenderer.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -71,20 +71,20 @@  discard block
 block discarded – undo
71 71
 	 *
72 72
 	 * @return string HTML
73 73
 	 */
74
-	public function formatValue( $value ) {
75
-		if ( is_string( $value ) ) {
74
+	public function formatValue($value) {
75
+		if (is_string($value)) {
76 76
 			// Cases like 'Format' 'pattern' or 'minimum'/'maximum' values, which we have stored as
77 77
 			// strings
78
-			return htmlspecialchars( $value );
79
-		} elseif ( $value instanceof EntityId ) {
78
+			return htmlspecialchars($value);
79
+		} elseif ($value instanceof EntityId) {
80 80
 			// Cases like 'Conflicts with' 'property', to which we can link
81
-			return $this->formatEntityId( $value );
82
-		} elseif ( $value instanceof ItemIdSnakValue ) {
81
+			return $this->formatEntityId($value);
82
+		} elseif ($value instanceof ItemIdSnakValue) {
83 83
 			// Cases like EntityId but can also be somevalue or novalue
84
-			return $this->formatItemIdSnakValue( $value );
84
+			return $this->formatItemIdSnakValue($value);
85 85
 		} else {
86 86
 			// Cases where we format a DataValue
87
-			return $this->formatDataValue( $value );
87
+			return $this->formatDataValue($value);
88 88
 		}
89 89
 	}
90 90
 
@@ -95,23 +95,23 @@  discard block
 block discarded – undo
95 95
 	 *
96 96
 	 * @return string HTML
97 97
 	 */
98
-	public function formatParameters( $parameters ) {
99
-		if ( $parameters === null || $parameters === [] ) {
98
+	public function formatParameters($parameters) {
99
+		if ($parameters === null || $parameters === []) {
100 100
 			return null;
101 101
 		}
102 102
 
103
-		$valueFormatter = function ( $value ) {
104
-			return $this->formatValue( $value );
103
+		$valueFormatter = function($value) {
104
+			return $this->formatValue($value);
105 105
 		};
106 106
 
107 107
 		$formattedParameters = [];
108
-		foreach ( $parameters as $parameterName => $parameterValue ) {
109
-			$formattedParameterValues = implode( ', ',
110
-				$this->limitArrayLength( array_map( $valueFormatter, $parameterValue ) ) );
111
-			$formattedParameters[] = sprintf( '%s: %s', $parameterName, $formattedParameterValues );
108
+		foreach ($parameters as $parameterName => $parameterValue) {
109
+			$formattedParameterValues = implode(', ',
110
+				$this->limitArrayLength(array_map($valueFormatter, $parameterValue)));
111
+			$formattedParameters[] = sprintf('%s: %s', $parameterName, $formattedParameterValues);
112 112
 		}
113 113
 
114
-		return implode( '; ', $formattedParameters );
114
+		return implode('; ', $formattedParameters);
115 115
 	}
116 116
 
117 117
 	/**
@@ -121,10 +121,10 @@  discard block
 block discarded – undo
121 121
 	 *
122 122
 	 * @return string[]
123 123
 	 */
124
-	private function limitArrayLength( array $array ) {
125
-		if ( count( $array ) > self::MAX_PARAMETER_ARRAY_LENGTH ) {
126
-			$array = array_slice( $array, 0, self::MAX_PARAMETER_ARRAY_LENGTH );
127
-			array_push( $array, '...' );
124
+	private function limitArrayLength(array $array) {
125
+		if (count($array) > self::MAX_PARAMETER_ARRAY_LENGTH) {
126
+			$array = array_slice($array, 0, self::MAX_PARAMETER_ARRAY_LENGTH);
127
+			array_push($array, '...');
128 128
 		}
129 129
 
130 130
 		return $array;
@@ -134,16 +134,16 @@  discard block
 block discarded – undo
134 134
 	 * @param DataValue $value
135 135
 	 * @return string HTML
136 136
 	 */
137
-	public function formatDataValue( DataValue $value ) {
138
-		return $this->dataValueFormatter->format( $value );
137
+	public function formatDataValue(DataValue $value) {
138
+		return $this->dataValueFormatter->format($value);
139 139
 	}
140 140
 
141 141
 	/**
142 142
 	 * @param EntityId $entityId
143 143
 	 * @return string HTML
144 144
 	 */
145
-	public function formatEntityId( EntityId $entityId ) {
146
-		return $this->entityIdLabelFormatter->formatEntityId( $entityId );
145
+	public function formatEntityId(EntityId $entityId) {
146
+		return $this->entityIdLabelFormatter->formatEntityId($entityId);
147 147
 	}
148 148
 
149 149
 	/**
@@ -152,17 +152,17 @@  discard block
 block discarded – undo
152 152
 	 * @param ItemIdSnakValue $value
153 153
 	 * @return string HTML
154 154
 	 */
155
-	public function formatItemIdSnakValue( ItemIdSnakValue $value ) {
156
-		switch ( true ) {
155
+	public function formatItemIdSnakValue(ItemIdSnakValue $value) {
156
+		switch (true) {
157 157
 			case $value->isValue():
158
-				return $this->formatEntityId( $value->getItemId() );
158
+				return $this->formatEntityId($value->getItemId());
159 159
 			case $value->isSomeValue():
160 160
 				return $this->messageLocalizer
161
-					->msg( 'wikibase-snakview-snaktypeselector-somevalue' )
161
+					->msg('wikibase-snakview-snaktypeselector-somevalue')
162 162
 					->escaped();
163 163
 			case $value->isNoValue():
164 164
 				return $this->messageLocalizer
165
-					->msg( 'wikibase-snakview-snaktypeselector-novalue' )
165
+					->msg('wikibase-snakview-snaktypeselector-novalue')
166 166
 					->escaped();
167 167
 		}
168 168
 	}
Please login to merge, or discard this patch.
src/Api/CheckConstraintParameters.php 1 patch
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -74,20 +74,20 @@  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
 		$constraintReportFactory = ConstraintReportFactory::getDefaultInstance();
79 79
 		$repo = WikibaseRepo::getDefaultInstance();
80
-		$helperFactory = $repo->getApiHelperFactory( RequestContext::getMain() );
80
+		$helperFactory = $repo->getApiHelperFactory(RequestContext::getMain());
81 81
 		$language = $repo->getUserLanguage();
82 82
 
83 83
 		$languageFallbackLabelDescriptionLookupFactory = $repo->getLanguageFallbackLabelDescriptionLookupFactory();
84
-		$labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup( $language );
84
+		$labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup($language);
85 85
 		$entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory();
86
-		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup );
86
+		$entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($labelDescriptionLookup);
87 87
 		$formatterOptions = new FormatterOptions();
88
-		$formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() );
88
+		$formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode());
89 89
 		$valueFormatterFactory = $repo->getValueFormatterFactory();
90
-		$dataValueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions );
90
+		$dataValueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions);
91 91
 		$config = MediaWikiServices::getInstance()->getMainConfig();
92 92
 		$violationMessageRenderer = new MultilingualTextViolationMessageRenderer(
93 93
 			$entityIdHtmlLinkFormatter,
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
 		StatementGuidParser $statementGuidParser,
128 128
 		IBufferingStatsdDataFactory $dataFactory
129 129
 	) {
130
-		parent::__construct( $main, $name, $prefix );
130
+		parent::__construct($main, $name, $prefix);
131 131
 
132
-		$this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this );
132
+		$this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this);
133 133
 		$this->delegatingConstraintChecker = $delegatingConstraintChecker;
134 134
 		$this->violationMessageRenderer = $violationMessageRenderer;
135 135
 		$this->statementGuidParser = $statementGuidParser;
@@ -144,39 +144,39 @@  discard block
 block discarded – undo
144 144
 		$params = $this->extractRequestParams();
145 145
 		$result = $this->getResult();
146 146
 
147
-		$propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] );
148
-		$constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] );
147
+		$propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]);
148
+		$constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]);
149 149
 
150
-		$this->checkPropertyIds( $propertyIds, $result );
151
-		$this->checkConstraintIds( $constraintIds, $result );
150
+		$this->checkPropertyIds($propertyIds, $result);
151
+		$this->checkConstraintIds($constraintIds, $result);
152 152
 
153
-		$result->addValue( null, 'success', 1 );
153
+		$result->addValue(null, 'success', 1);
154 154
 	}
155 155
 
156 156
 	/**
157 157
 	 * @param array|null $propertyIdSerializations
158 158
 	 * @return PropertyId[]
159 159
 	 */
160
-	private function parsePropertyIds( $propertyIdSerializations ) {
161
-		if ( $propertyIdSerializations === null ) {
160
+	private function parsePropertyIds($propertyIdSerializations) {
161
+		if ($propertyIdSerializations === null) {
162 162
 			return [];
163
-		} elseif ( empty( $propertyIdSerializations ) ) {
163
+		} elseif (empty($propertyIdSerializations)) {
164 164
 			$this->apiErrorReporter->dieError(
165
-				'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.',
165
+				'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.',
166 166
 				'no-data'
167 167
 			);
168 168
 		}
169 169
 
170 170
 		return array_map(
171
-			function( $propertyIdSerialization ) {
171
+			function($propertyIdSerialization) {
172 172
 				try {
173
-					return new PropertyId( $propertyIdSerialization );
174
-				} catch ( InvalidArgumentException $e ) {
173
+					return new PropertyId($propertyIdSerialization);
174
+				} catch (InvalidArgumentException $e) {
175 175
 					$this->apiErrorReporter->dieError(
176 176
 						"Invalid id: $propertyIdSerialization",
177 177
 						'invalid-property-id',
178 178
 						0, // default argument
179
-						[ self::PARAM_PROPERTY_ID => $propertyIdSerialization ]
179
+						[self::PARAM_PROPERTY_ID => $propertyIdSerialization]
180 180
 					);
181 181
 				}
182 182
 			},
@@ -188,35 +188,35 @@  discard block
 block discarded – undo
188 188
 	 * @param array|null $constraintIds
189 189
 	 * @return string[]
190 190
 	 */
191
-	private function parseConstraintIds( $constraintIds ) {
192
-		if ( $constraintIds === null ) {
191
+	private function parseConstraintIds($constraintIds) {
192
+		if ($constraintIds === null) {
193 193
 			return [];
194
-		} elseif ( empty( $constraintIds ) ) {
194
+		} elseif (empty($constraintIds)) {
195 195
 			$this->apiErrorReporter->dieError(
196
-				'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.',
196
+				'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.',
197 197
 				'no-data'
198 198
 			);
199 199
 		}
200 200
 
201 201
 		return array_map(
202
-			function( $constraintId ) {
202
+			function($constraintId) {
203 203
 				try {
204
-					$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
205
-					if ( !$propertyId instanceof PropertyId ) {
204
+					$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
205
+					if (!$propertyId instanceof PropertyId) {
206 206
 						$this->apiErrorReporter->dieError(
207 207
 							"Invalid property ID: {$propertyId->getSerialization()}",
208 208
 							'invalid-property-id',
209 209
 							0, // default argument
210
-							[ self::PARAM_CONSTRAINT_ID => $constraintId ]
210
+							[self::PARAM_CONSTRAINT_ID => $constraintId]
211 211
 						);
212 212
 					}
213 213
 					return $constraintId;
214
-				} catch ( StatementGuidParsingException $e ) {
214
+				} catch (StatementGuidParsingException $e) {
215 215
 					$this->apiErrorReporter->dieError(
216 216
 						"Invalid statement GUID: $constraintId",
217 217
 						'invalid-guid',
218 218
 						0, // default argument
219
-						[ self::PARAM_CONSTRAINT_ID => $constraintId ]
219
+						[self::PARAM_CONSTRAINT_ID => $constraintId]
220 220
 					);
221 221
 				}
222 222
 			},
@@ -228,12 +228,12 @@  discard block
 block discarded – undo
228 228
 	 * @param PropertyId[] $propertyIds
229 229
 	 * @param ApiResult $result
230 230
 	 */
231
-	private function checkPropertyIds( array $propertyIds, ApiResult $result ) {
232
-		foreach ( $propertyIds as $propertyId ) {
233
-			$result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' );
234
-			$allConstraintExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnPropertyId( $propertyId );
235
-			foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) {
236
-				$this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result );
231
+	private function checkPropertyIds(array $propertyIds, ApiResult $result) {
232
+		foreach ($propertyIds as $propertyId) {
233
+			$result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc');
234
+			$allConstraintExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnPropertyId($propertyId);
235
+			foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) {
236
+				$this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result);
237 237
 			}
238 238
 		}
239 239
 	}
@@ -242,14 +242,14 @@  discard block
 block discarded – undo
242 242
 	 * @param string[] $constraintIds
243 243
 	 * @param ApiResult $result
244 244
 	 */
245
-	private function checkConstraintIds( array $constraintIds, ApiResult $result ) {
246
-		foreach ( $constraintIds as $constraintId ) {
247
-			if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) {
245
+	private function checkConstraintIds(array $constraintIds, ApiResult $result) {
246
+		foreach ($constraintIds as $constraintId) {
247
+			if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) {
248 248
 				// already checked as part of checkPropertyIds()
249 249
 				continue;
250 250
 			}
251
-			$constraintParameterExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnConstraintId( $constraintId );
252
-			$this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result );
251
+			$constraintParameterExceptions = $this->delegatingConstraintChecker->checkConstraintParametersOnConstraintId($constraintId);
252
+			$this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result);
253 253
 		}
254 254
 	}
255 255
 
@@ -257,17 +257,17 @@  discard block
 block discarded – undo
257 257
 	 * @param PropertyId $propertyId
258 258
 	 * @return string[]
259 259
 	 */
260
-	private function getResultPathForPropertyId( PropertyId $propertyId ) {
261
-		return [ $this->getModuleName(), $propertyId->getSerialization() ];
260
+	private function getResultPathForPropertyId(PropertyId $propertyId) {
261
+		return [$this->getModuleName(), $propertyId->getSerialization()];
262 262
 	}
263 263
 
264 264
 	/**
265 265
 	 * @param string $constraintId
266 266
 	 * @return string[]
267 267
 	 */
268
-	private function getResultPathForConstraintId( $constraintId ) {
269
-		$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
270
-		return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] );
268
+	private function getResultPathForConstraintId($constraintId) {
269
+		$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
270
+		return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]);
271 271
 	}
272 272
 
273 273
 	/**
@@ -277,9 +277,9 @@  discard block
 block discarded – undo
277 277
 	 * @param ConstraintParameterException[]|null $constraintParameterExceptions
278 278
 	 * @param ApiResult $result
279 279
 	 */
280
-	private function addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, ApiResult $result ) {
281
-		$path = $this->getResultPathForConstraintId( $constraintId );
282
-		if ( $constraintParameterExceptions === null ) {
280
+	private function addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, ApiResult $result) {
281
+		$path = $this->getResultPathForConstraintId($constraintId);
282
+		if ($constraintParameterExceptions === null) {
283 283
 			$result->addValue(
284 284
 				$path,
285 285
 				self::KEY_STATUS,
@@ -289,12 +289,12 @@  discard block
 block discarded – undo
289 289
 			$result->addValue(
290 290
 				$path,
291 291
 				self::KEY_STATUS,
292
-				empty( $constraintParameterExceptions ) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY
292
+				empty($constraintParameterExceptions) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY
293 293
 			);
294 294
 			$result->addValue(
295 295
 				$path,
296 296
 				self::KEY_PROBLEMS,
297
-				array_map( [ $this, 'formatConstraintParameterException' ], $constraintParameterExceptions )
297
+				array_map([$this, 'formatConstraintParameterException'], $constraintParameterExceptions)
298 298
 			);
299 299
 		}
300 300
 	}
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
 	 * @param ConstraintParameterException $e
306 306
 	 * @return string[]
307 307
 	 */
308
-	private function formatConstraintParameterException( ConstraintParameterException $e ) {
308
+	private function formatConstraintParameterException(ConstraintParameterException $e) {
309 309
 		return [
310 310
 			self::KEY_MESSAGE_HTML => $this->violationMessageRenderer->render(
311 311
 				$e->getViolationMessage()
Please login to merge, or discard this patch.