@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @throws ConstraintParameterException |
95 | 95 | * @return CheckResult |
96 | 96 | */ |
97 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
97 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
98 | 98 | $constraintParameters = $constraint->getConstraintParameters(); |
99 | 99 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
100 | 100 | |
@@ -109,9 +109,9 @@ discard block |
||
109 | 109 | |
110 | 110 | $snak = $context->getSnak(); |
111 | 111 | |
112 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
112 | + if (!$snak instanceof PropertyValueSnak) { |
|
113 | 113 | // nothing to check |
114 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE ); |
|
114 | + return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | $dataValue = $snak->getDataValue(); |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * error handling: |
121 | 121 | * type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext' |
122 | 122 | */ |
123 | - switch ( $dataValue->getType() ) { |
|
123 | + switch ($dataValue->getType()) { |
|
124 | 124 | case 'string': |
125 | 125 | $text = $dataValue->getValue(); |
126 | 126 | break; |
@@ -130,13 +130,13 @@ discard block |
||
130 | 130 | $text = $dataValue->getText(); |
131 | 131 | break; |
132 | 132 | default: |
133 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-types-2' ) ) |
|
134 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
135 | - ->withDataValueType( 'string' ) |
|
136 | - ->withDataValueType( 'monolingualtext' ); |
|
137 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message ); |
|
133 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-types-2')) |
|
134 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
135 | + ->withDataValueType('string') |
|
136 | + ->withDataValueType('monolingualtext'); |
|
137 | + return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message); |
|
138 | 138 | } |
139 | - $status = $this->runRegexCheck( $text, $format ); |
|
139 | + $status = $this->runRegexCheck($text, $format); |
|
140 | 140 | $message = $this->formatMessage( |
141 | 141 | $status, |
142 | 142 | $text, |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $syntaxClarifications, |
146 | 146 | $constraintTypeItemId |
147 | 147 | ); |
148 | - return new CheckResult( $context, $constraint, $status, $message ); |
|
148 | + return new CheckResult($context, $constraint, $status, $message); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | private function formatMessage( |
@@ -157,43 +157,43 @@ discard block |
||
157 | 157 | string $constraintTypeItemId |
158 | 158 | ): ?ViolationMessage { |
159 | 159 | $message = null; |
160 | - if ( $status === CheckResult::STATUS_VIOLATION ) { |
|
161 | - $message = ( new ViolationMessage( 'wbqc-violation-message-format-clarification' ) ) |
|
162 | - ->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ) |
|
163 | - ->withDataValue( new StringValue( $text ), Role::OBJECT ) |
|
164 | - ->withInlineCode( $format, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
165 | - ->withMultilingualText( $syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE ); |
|
166 | - } elseif ( $status === CheckResult::STATUS_TODO ) { |
|
167 | - $message = ( new ViolationMessage( 'wbqc-violation-message-security-reason' ) ) |
|
168 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ); |
|
160 | + if ($status === CheckResult::STATUS_VIOLATION) { |
|
161 | + $message = (new ViolationMessage('wbqc-violation-message-format-clarification')) |
|
162 | + ->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY) |
|
163 | + ->withDataValue(new StringValue($text), Role::OBJECT) |
|
164 | + ->withInlineCode($format, Role::CONSTRAINT_PARAMETER_VALUE) |
|
165 | + ->withMultilingualText($syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE); |
|
166 | + } elseif ($status === CheckResult::STATUS_TODO) { |
|
167 | + $message = (new ViolationMessage('wbqc-violation-message-security-reason')) |
|
168 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | return $message; |
172 | 172 | } |
173 | 173 | |
174 | - private function runRegexCheck( string $text, string $format ): string { |
|
175 | - if ( !$this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) ) { |
|
174 | + private function runRegexCheck(string $text, string $format): string { |
|
175 | + if (!$this->config->get('WBQualityConstraintsCheckFormatConstraint')) { |
|
176 | 176 | return CheckResult::STATUS_TODO; |
177 | 177 | } |
178 | - $knownGoodFormats = $this->config->get( 'WBQualityConstraintsFormatCheckerKnownGoodRegexPatterns' ); |
|
179 | - if ( in_array( $format, $knownGoodFormats, true ) ) { |
|
180 | - $checkResult = FormatCheckerHelper::runRegexCheck( $format, $text ); |
|
178 | + $knownGoodFormats = $this->config->get('WBQualityConstraintsFormatCheckerKnownGoodRegexPatterns'); |
|
179 | + if (in_array($format, $knownGoodFormats, true)) { |
|
180 | + $checkResult = FormatCheckerHelper::runRegexCheck($format, $text); |
|
181 | 181 | } elseif ( |
182 | - $this->config->get( 'WBQualityConstraintsFormatCheckerShellboxRatio' ) > (float)wfRandom() |
|
182 | + $this->config->get('WBQualityConstraintsFormatCheckerShellboxRatio') > (float) wfRandom() |
|
183 | 183 | ) { |
184 | - $checkResult = $this->runRegexCheckUsingShellbox( $text, $format ); |
|
184 | + $checkResult = $this->runRegexCheckUsingShellbox($text, $format); |
|
185 | 185 | } else { |
186 | - return $this->runRegexCheckUsingSparql( $text, $format ); |
|
186 | + return $this->runRegexCheckUsingSparql($text, $format); |
|
187 | 187 | } |
188 | 188 | |
189 | - if ( $checkResult === 1 ) { |
|
189 | + if ($checkResult === 1) { |
|
190 | 190 | return CheckResult::STATUS_COMPLIANCE; |
191 | - } elseif ( $checkResult === 0 ) { |
|
191 | + } elseif ($checkResult === 0) { |
|
192 | 192 | return CheckResult::STATUS_VIOLATION; |
193 | - } elseif ( $checkResult === false ) { |
|
193 | + } elseif ($checkResult === false) { |
|
194 | 194 | throw new ConstraintParameterException( |
195 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
196 | - ->withInlineCode( $format, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
195 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
196 | + ->withInlineCode($format, Role::CONSTRAINT_PARAMETER_VALUE) |
|
197 | 197 | ); |
198 | 198 | } else { |
199 | 199 | return $checkResult; |
@@ -207,35 +207,35 @@ discard block |
||
207 | 207 | * - FALSE if $format is invalid regex |
208 | 208 | * - CheckResult::STATUS_TODO if Shellbox is not enabled |
209 | 209 | */ |
210 | - private function runRegexCheckUsingShellbox( string $text, string $format ) { |
|
211 | - if ( !$this->shellboxClientFactory->isEnabled( 'constraint-regex-checker' ) ) { |
|
210 | + private function runRegexCheckUsingShellbox(string $text, string $format) { |
|
211 | + if (!$this->shellboxClientFactory->isEnabled('constraint-regex-checker')) { |
|
212 | 212 | return CheckResult::STATUS_TODO; |
213 | 213 | } |
214 | 214 | |
215 | - return $this->shellboxClientFactory->getClient( [ |
|
216 | - 'timeout' => $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' ) / 1000, |
|
215 | + return $this->shellboxClientFactory->getClient([ |
|
216 | + 'timeout' => $this->config->get('WBQualityConstraintsSparqlMaxMillis') / 1000, |
|
217 | 217 | 'service' => 'constraint-regex-checker', |
218 | - ] )->call( |
|
218 | + ])->call( |
|
219 | 219 | 'constraint-regex-checker', |
220 | - [ FormatCheckerHelper::class, 'runRegexCheck' ], |
|
221 | - [ $format, $text ], |
|
222 | - [ 'classes' => [ FormatCheckerHelper::class ] ], |
|
220 | + [FormatCheckerHelper::class, 'runRegexCheck'], |
|
221 | + [$format, $text], |
|
222 | + ['classes' => [FormatCheckerHelper::class]], |
|
223 | 223 | ); |
224 | 224 | } |
225 | 225 | |
226 | - private function runRegexCheckUsingSparql( string $text, string $format ): string { |
|
227 | - if ( $this->sparqlHelper instanceof DummySparqlHelper ) { |
|
226 | + private function runRegexCheckUsingSparql(string $text, string $format): string { |
|
227 | + if ($this->sparqlHelper instanceof DummySparqlHelper) { |
|
228 | 228 | return CheckResult::STATUS_TODO; |
229 | 229 | } |
230 | 230 | |
231 | - if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) { |
|
231 | + if ($this->sparqlHelper->matchesRegularExpression($text, $format)) { |
|
232 | 232 | return CheckResult::STATUS_COMPLIANCE; |
233 | 233 | } else { |
234 | 234 | return CheckResult::STATUS_VIOLATION; |
235 | 235 | } |
236 | 236 | } |
237 | 237 | |
238 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
238 | + public function checkConstraintParameters(Constraint $constraint) { |
|
239 | 239 | $constraintParameters = $constraint->getConstraintParameters(); |
240 | 240 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
241 | 241 | $exceptions = []; |
@@ -244,14 +244,14 @@ discard block |
||
244 | 244 | $constraintParameters, |
245 | 245 | $constraintTypeItemId |
246 | 246 | ); |
247 | - } catch ( ConstraintParameterException $e ) { |
|
247 | + } catch (ConstraintParameterException $e) { |
|
248 | 248 | $exceptions[] = $e; |
249 | 249 | } |
250 | 250 | try { |
251 | 251 | $this->constraintParameterParser->parseSyntaxClarificationParameter( |
252 | 252 | $constraintParameters |
253 | 253 | ); |
254 | - } catch ( ConstraintParameterException $e ) { |
|
254 | + } catch (ConstraintParameterException $e) { |
|
255 | 255 | $exceptions[] = $e; |
256 | 256 | } |
257 | 257 | return $exceptions; |