Completed
Push — master ( a80462...d4beaa )
by
unknown
18s
created
src/ConstraintCheck/Checker/FormatChecker.php 1 patch
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 		$this->sparqlHelper = $sparqlHelper;
68 68
 		$this->shellboxClientFactory = $shellboxClientFactory;
69 69
 		$this->knownGoodPatternsAsKeys = array_fill_keys(
70
-			$this->config->get( 'WBQualityConstraintsFormatCheckerKnownGoodRegexPatterns' ),
70
+			$this->config->get('WBQualityConstraintsFormatCheckerKnownGoodRegexPatterns'),
71 71
 			null
72 72
 		);
73 73
 	}
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 	 * @throws ConstraintParameterException
101 101
 	 * @return CheckResult
102 102
 	 */
103
-	public function checkConstraint( Context $context, Constraint $constraint ) {
103
+	public function checkConstraint(Context $context, Constraint $constraint) {
104 104
 		$constraintParameters = $constraint->getConstraintParameters();
105 105
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
106 106
 
@@ -115,9 +115,9 @@  discard block
 block discarded – undo
115 115
 
116 116
 		$snak = $context->getSnak();
117 117
 
118
-		if ( !$snak instanceof PropertyValueSnak ) {
118
+		if (!$snak instanceof PropertyValueSnak) {
119 119
 			// nothing to check
120
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE );
120
+			return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE);
121 121
 		}
122 122
 
123 123
 		$dataValue = $snak->getDataValue();
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 		 * error handling:
127 127
 		 *   type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext'
128 128
 		 */
129
-		switch ( $dataValue->getType() ) {
129
+		switch ($dataValue->getType()) {
130 130
 			case 'string':
131 131
 				$text = $dataValue->getValue();
132 132
 				break;
@@ -136,13 +136,13 @@  discard block
 block discarded – undo
136 136
 				$text = $dataValue->getText();
137 137
 				break;
138 138
 			default:
139
-				$message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-types-2' ) )
140
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
141
-					->withDataValueType( 'string' )
142
-					->withDataValueType( 'monolingualtext' );
143
-				return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message );
139
+				$message = (new ViolationMessage('wbqc-violation-message-value-needed-of-types-2'))
140
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
141
+					->withDataValueType('string')
142
+					->withDataValueType('monolingualtext');
143
+				return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message);
144 144
 		}
145
-		$status = $this->runRegexCheck( $text, $format );
145
+		$status = $this->runRegexCheck($text, $format);
146 146
 		$message = $this->formatMessage(
147 147
 			$status,
148 148
 			$text,
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 			$syntaxClarifications,
152 152
 			$constraintTypeItemId
153 153
 		);
154
-		return new CheckResult( $context, $constraint, $status, $message );
154
+		return new CheckResult($context, $constraint, $status, $message);
155 155
 	}
156 156
 
157 157
 	private function formatMessage(
@@ -163,42 +163,42 @@  discard block
 block discarded – undo
163 163
 		string $constraintTypeItemId
164 164
 	): ?ViolationMessage {
165 165
 		$message = null;
166
-		if ( $status === CheckResult::STATUS_VIOLATION ) {
167
-			$message = ( new ViolationMessage( 'wbqc-violation-message-format-clarification' ) )
168
-				->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY )
169
-				->withDataValue( new StringValue( $text ), Role::OBJECT )
170
-				->withInlineCode( $format, Role::CONSTRAINT_PARAMETER_VALUE )
171
-				->withMultilingualText( $syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE );
172
-		} elseif ( $status === CheckResult::STATUS_TODO ) {
173
-			$message = ( new ViolationMessage( 'wbqc-violation-message-security-reason' ) )
174
-				->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM );
166
+		if ($status === CheckResult::STATUS_VIOLATION) {
167
+			$message = (new ViolationMessage('wbqc-violation-message-format-clarification'))
168
+				->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY)
169
+				->withDataValue(new StringValue($text), Role::OBJECT)
170
+				->withInlineCode($format, Role::CONSTRAINT_PARAMETER_VALUE)
171
+				->withMultilingualText($syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE);
172
+		} elseif ($status === CheckResult::STATUS_TODO) {
173
+			$message = (new ViolationMessage('wbqc-violation-message-security-reason'))
174
+				->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM);
175 175
 		}
176 176
 
177 177
 		return $message;
178 178
 	}
179 179
 
180
-	private function runRegexCheck( string $text, string $format ): string {
181
-		if ( !$this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) ) {
180
+	private function runRegexCheck(string $text, string $format): string {
181
+		if (!$this->config->get('WBQualityConstraintsCheckFormatConstraint')) {
182 182
 			return CheckResult::STATUS_TODO;
183 183
 		}
184
-		if ( \array_key_exists( $format, $this->knownGoodPatternsAsKeys ) ) {
185
-			$checkResult = FormatCheckerHelper::runRegexCheck( $format, $text );
184
+		if (\array_key_exists($format, $this->knownGoodPatternsAsKeys)) {
185
+			$checkResult = FormatCheckerHelper::runRegexCheck($format, $text);
186 186
 		} elseif (
187
-			$this->config->get( 'WBQualityConstraintsFormatCheckerShellboxRatio' ) > (float)wfRandom()
187
+			$this->config->get('WBQualityConstraintsFormatCheckerShellboxRatio') > (float) wfRandom()
188 188
 		) {
189
-			$checkResult = $this->runRegexCheckUsingShellbox( $text, $format );
189
+			$checkResult = $this->runRegexCheckUsingShellbox($text, $format);
190 190
 		} else {
191
-			return $this->runRegexCheckUsingSparql( $text, $format );
191
+			return $this->runRegexCheckUsingSparql($text, $format);
192 192
 		}
193 193
 
194
-		if ( $checkResult === 1 ) {
194
+		if ($checkResult === 1) {
195 195
 			return CheckResult::STATUS_COMPLIANCE;
196
-		} elseif ( $checkResult === 0 ) {
196
+		} elseif ($checkResult === 0) {
197 197
 			return CheckResult::STATUS_VIOLATION;
198
-		} elseif ( $checkResult === false ) {
198
+		} elseif ($checkResult === false) {
199 199
 			throw new ConstraintParameterException(
200
-				( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) )
201
-					->withInlineCode( $format, Role::CONSTRAINT_PARAMETER_VALUE )
200
+				(new ViolationMessage('wbqc-violation-message-parameter-regex'))
201
+					->withInlineCode($format, Role::CONSTRAINT_PARAMETER_VALUE)
202 202
 			);
203 203
 		} else {
204 204
 			return $checkResult;
@@ -212,35 +212,35 @@  discard block
 block discarded – undo
212 212
 	 *   - FALSE if $format is invalid regex
213 213
 	 *   - CheckResult::STATUS_TODO if Shellbox is not enabled
214 214
 	 */
215
-	private function runRegexCheckUsingShellbox( string $text, string $format ) {
216
-		if ( !$this->shellboxClientFactory->isEnabled( 'constraint-regex-checker' ) ) {
215
+	private function runRegexCheckUsingShellbox(string $text, string $format) {
216
+		if (!$this->shellboxClientFactory->isEnabled('constraint-regex-checker')) {
217 217
 			return CheckResult::STATUS_TODO;
218 218
 		}
219 219
 
220
-		return $this->shellboxClientFactory->getClient( [
221
-			'timeout' => $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' ) / 1000,
220
+		return $this->shellboxClientFactory->getClient([
221
+			'timeout' => $this->config->get('WBQualityConstraintsSparqlMaxMillis') / 1000,
222 222
 			'service' => 'constraint-regex-checker',
223
-		] )->call(
223
+		])->call(
224 224
 			'constraint-regex-checker',
225
-			[ FormatCheckerHelper::class, 'runRegexCheck' ],
226
-			[ $format, $text ],
227
-			[ 'classes' => [ FormatCheckerHelper::class ] ],
225
+			[FormatCheckerHelper::class, 'runRegexCheck'],
226
+			[$format, $text],
227
+			['classes' => [FormatCheckerHelper::class]],
228 228
 		);
229 229
 	}
230 230
 
231
-	private function runRegexCheckUsingSparql( string $text, string $format ): string {
232
-		if ( $this->sparqlHelper instanceof DummySparqlHelper ) {
231
+	private function runRegexCheckUsingSparql(string $text, string $format): string {
232
+		if ($this->sparqlHelper instanceof DummySparqlHelper) {
233 233
 			return CheckResult::STATUS_TODO;
234 234
 		}
235 235
 
236
-		if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) {
236
+		if ($this->sparqlHelper->matchesRegularExpression($text, $format)) {
237 237
 			return CheckResult::STATUS_COMPLIANCE;
238 238
 		} else {
239 239
 			return CheckResult::STATUS_VIOLATION;
240 240
 		}
241 241
 	}
242 242
 
243
-	public function checkConstraintParameters( Constraint $constraint ) {
243
+	public function checkConstraintParameters(Constraint $constraint) {
244 244
 		$constraintParameters = $constraint->getConstraintParameters();
245 245
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
246 246
 		$exceptions = [];
@@ -249,14 +249,14 @@  discard block
 block discarded – undo
249 249
 				$constraintParameters,
250 250
 				$constraintTypeItemId
251 251
 			);
252
-		} catch ( ConstraintParameterException $e ) {
252
+		} catch (ConstraintParameterException $e) {
253 253
 			$exceptions[] = $e;
254 254
 		}
255 255
 		try {
256 256
 			$this->constraintParameterParser->parseSyntaxClarificationParameter(
257 257
 				$constraintParameters
258 258
 			);
259
-		} catch ( ConstraintParameterException $e ) {
259
+		} catch (ConstraintParameterException $e) {
260 260
 			$exceptions[] = $e;
261 261
 		}
262 262
 		return $exceptions;
Please login to merge, or discard this patch.