Completed
Push — master ( 47e7a3...c6464d )
by
unknown
25s
created
src/Api/CheckConstraintParameters.php 1 patch
Spacing   +49 added lines, -49 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,45 +90,45 @@  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 96
 		$params = $this->extractRequestParams();
97 97
 		$result = $this->getResult();
98 98
 
99
-		$propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] );
100
-		$constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] );
99
+		$propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]);
100
+		$constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]);
101 101
 
102
-		$this->checkPropertyIds( $propertyIds, $result );
103
-		$this->checkConstraintIds( $constraintIds, $result );
102
+		$this->checkPropertyIds($propertyIds, $result);
103
+		$this->checkConstraintIds($constraintIds, $result);
104 104
 
105
-		$result->addValue( null, 'success', 1 );
105
+		$result->addValue(null, 'success', 1);
106 106
 	}
107 107
 
108 108
 	/**
109 109
 	 * @param array|null $propertyIdSerializations
110 110
 	 * @return NumericPropertyId[]
111 111
 	 */
112
-	private function parsePropertyIds( ?array $propertyIdSerializations ): array {
113
-		if ( $propertyIdSerializations === null ) {
112
+	private function parsePropertyIds(?array $propertyIdSerializations): array {
113
+		if ($propertyIdSerializations === null) {
114 114
 			return [];
115
-		} elseif ( $propertyIdSerializations === [] ) {
115
+		} elseif ($propertyIdSerializations === []) {
116 116
 			$this->apiErrorReporter->dieError(
117
-				'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.',
117
+				'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.',
118 118
 				'no-data'
119 119
 			);
120 120
 		}
121 121
 
122 122
 		return array_map(
123
-			function ( $propertyIdSerialization ) {
123
+			function($propertyIdSerialization) {
124 124
 				try {
125
-					return new NumericPropertyId( $propertyIdSerialization );
126
-				} catch ( InvalidArgumentException ) {
125
+					return new NumericPropertyId($propertyIdSerialization);
126
+				} catch (InvalidArgumentException) {
127 127
 					$this->apiErrorReporter->dieError(
128 128
 						"Invalid id: $propertyIdSerialization",
129 129
 						'invalid-property-id',
130 130
 						0, // default argument
131
-						[ self::PARAM_PROPERTY_ID => $propertyIdSerialization ]
131
+						[self::PARAM_PROPERTY_ID => $propertyIdSerialization]
132 132
 					);
133 133
 				}
134 134
 			},
@@ -140,35 +140,35 @@  discard block
 block discarded – undo
140 140
 	 * @param array|null $constraintIds
141 141
 	 * @return string[]
142 142
 	 */
143
-	private function parseConstraintIds( ?array $constraintIds ): array {
144
-		if ( $constraintIds === null ) {
143
+	private function parseConstraintIds(?array $constraintIds): array {
144
+		if ($constraintIds === null) {
145 145
 			return [];
146
-		} elseif ( $constraintIds === [] ) {
146
+		} elseif ($constraintIds === []) {
147 147
 			$this->apiErrorReporter->dieError(
148
-				'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.',
148
+				'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.',
149 149
 				'no-data'
150 150
 			);
151 151
 		}
152 152
 
153 153
 		return array_map(
154
-			function ( $constraintId ) {
154
+			function($constraintId) {
155 155
 				try {
156
-					$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
157
-					if ( !$propertyId instanceof NumericPropertyId ) {
156
+					$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
157
+					if (!$propertyId instanceof NumericPropertyId) {
158 158
 						$this->apiErrorReporter->dieError(
159 159
 							"Invalid property ID: {$propertyId->getSerialization()}",
160 160
 							'invalid-property-id',
161 161
 							0, // default argument
162
-							[ self::PARAM_CONSTRAINT_ID => $constraintId ]
162
+							[self::PARAM_CONSTRAINT_ID => $constraintId]
163 163
 						);
164 164
 					}
165 165
 					return $constraintId;
166
-				} catch ( StatementGuidParsingException ) {
166
+				} catch (StatementGuidParsingException) {
167 167
 					$this->apiErrorReporter->dieError(
168 168
 						"Invalid statement GUID: $constraintId",
169 169
 						'invalid-guid',
170 170
 						0, // default argument
171
-						[ self::PARAM_CONSTRAINT_ID => $constraintId ]
171
+						[self::PARAM_CONSTRAINT_ID => $constraintId]
172 172
 					);
173 173
 				}
174 174
 			},
@@ -180,12 +180,12 @@  discard block
 block discarded – undo
180 180
 	 * @param NumericPropertyId[] $propertyIds
181 181
 	 * @param ApiResult $result
182 182
 	 */
183
-	private function checkPropertyIds( array $propertyIds, ApiResult $result ): void {
184
-		foreach ( $propertyIds as $propertyId ) {
185
-			$result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' );
183
+	private function checkPropertyIds(array $propertyIds, ApiResult $result): void {
184
+		foreach ($propertyIds as $propertyId) {
185
+			$result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc');
186 186
 			$allConstraintExceptions = $this->delegatingConstraintChecker
187
-				->checkConstraintParametersOnPropertyId( $propertyId );
188
-			foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) {
187
+				->checkConstraintParametersOnPropertyId($propertyId);
188
+			foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) {
189 189
 				$this->addConstraintParameterExceptionsToResult(
190 190
 					$constraintId,
191 191
 					$constraintParameterExceptions,
@@ -199,15 +199,15 @@  discard block
 block discarded – undo
199 199
 	 * @param string[] $constraintIds
200 200
 	 * @param ApiResult $result
201 201
 	 */
202
-	private function checkConstraintIds( array $constraintIds, ApiResult $result ): void {
203
-		foreach ( $constraintIds as $constraintId ) {
204
-			if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) {
202
+	private function checkConstraintIds(array $constraintIds, ApiResult $result): void {
203
+		foreach ($constraintIds as $constraintId) {
204
+			if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) {
205 205
 				// already checked as part of checkPropertyIds()
206 206
 				continue;
207 207
 			}
208 208
 			$constraintParameterExceptions = $this->delegatingConstraintChecker
209
-				->checkConstraintParametersOnConstraintId( $constraintId );
210
-			$this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result );
209
+				->checkConstraintParametersOnConstraintId($constraintId);
210
+			$this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result);
211 211
 		}
212 212
 	}
213 213
 
@@ -215,18 +215,18 @@  discard block
 block discarded – undo
215 215
 	 * @param NumericPropertyId $propertyId
216 216
 	 * @return string[]
217 217
 	 */
218
-	private function getResultPathForPropertyId( NumericPropertyId $propertyId ): array {
219
-		return [ $this->getModuleName(), $propertyId->getSerialization() ];
218
+	private function getResultPathForPropertyId(NumericPropertyId $propertyId): array {
219
+		return [$this->getModuleName(), $propertyId->getSerialization()];
220 220
 	}
221 221
 
222 222
 	/**
223 223
 	 * @param string $constraintId
224 224
 	 * @return string[]
225 225
 	 */
226
-	private function getResultPathForConstraintId( string $constraintId ): array {
227
-		$propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId();
226
+	private function getResultPathForConstraintId(string $constraintId): array {
227
+		$propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId();
228 228
 		'@phan-var NumericPropertyId $propertyId';
229
-		return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] );
229
+		return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]);
230 230
 	}
231 231
 
232 232
 	/**
@@ -241,8 +241,8 @@  discard block
 block discarded – undo
241 241
 		?array $constraintParameterExceptions,
242 242
 		ApiResult $result
243 243
 	): void {
244
-		$path = $this->getResultPathForConstraintId( $constraintId );
245
-		if ( $constraintParameterExceptions === null ) {
244
+		$path = $this->getResultPathForConstraintId($constraintId);
245
+		if ($constraintParameterExceptions === null) {
246 246
 			$result->addValue(
247 247
 				$path,
248 248
 				self::KEY_STATUS,
@@ -259,11 +259,11 @@  discard block
 block discarded – undo
259 259
 			$violationMessageRenderer = $this->violationMessageRendererFactory
260 260
 				->getViolationMessageRenderer(
261 261
 					$language,
262
-					$this->languageFallbackChainFactory->newFromLanguage( $language ),
262
+					$this->languageFallbackChainFactory->newFromLanguage($language),
263 263
 					$this
264 264
 				);
265 265
 			$problems = [];
266
-			foreach ( $constraintParameterExceptions as $constraintParameterException ) {
266
+			foreach ($constraintParameterExceptions as $constraintParameterException) {
267 267
 				$problems[] = [
268 268
 					self::KEY_MESSAGE_HTML => $violationMessageRenderer->render(
269 269
 						$constraintParameterException->getViolationMessage() ),
@@ -302,8 +302,8 @@  discard block
 block discarded – undo
302 302
 		return [
303 303
 			'action=wbcheckconstraintparameters&propertyid=P247'
304 304
 				=> 'apihelp-wbcheckconstraintparameters-example-propertyid-1',
305
-			'action=wbcheckconstraintparameters&' .
306
-			'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|' .
305
+			'action=wbcheckconstraintparameters&'.
306
+			'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|'.
307 307
 			'P225$cdc71e4a-47a0-12c5-dfb3-3f6fc0b6613f'
308 308
 				=> 'apihelp-wbcheckconstraintparameters-example-constraintid-2',
309 309
 		];
Please login to merge, or discard this patch.