@@ -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,42 +157,42 @@ 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 | - if ( in_array( $format, $this->config->get( 'WBQualityConstraintsFormatCheckerKnownGoodRegexPatterns' ) ) ) { |
|
| 179 | - $checkResult = FormatCheckerHelper::runRegexCheck( $format, $text ); |
|
| 178 | + if (in_array($format, $this->config->get('WBQualityConstraintsFormatCheckerKnownGoodRegexPatterns'))) { |
|
| 179 | + $checkResult = FormatCheckerHelper::runRegexCheck($format, $text); |
|
| 180 | 180 | } elseif ( |
| 181 | - $this->config->get( 'WBQualityConstraintsFormatCheckerShellboxRatio' ) > (float)wfRandom() |
|
| 181 | + $this->config->get('WBQualityConstraintsFormatCheckerShellboxRatio') > (float) wfRandom() |
|
| 182 | 182 | ) { |
| 183 | - $checkResult = $this->runRegexCheckUsingShellbox( $text, $format ); |
|
| 183 | + $checkResult = $this->runRegexCheckUsingShellbox($text, $format); |
|
| 184 | 184 | } else { |
| 185 | - return $this->runRegexCheckUsingSparql( $text, $format ); |
|
| 185 | + return $this->runRegexCheckUsingSparql($text, $format); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - if ( $checkResult === 1 ) { |
|
| 188 | + if ($checkResult === 1) { |
|
| 189 | 189 | return CheckResult::STATUS_COMPLIANCE; |
| 190 | - } elseif ( $checkResult === 0 ) { |
|
| 190 | + } elseif ($checkResult === 0) { |
|
| 191 | 191 | return CheckResult::STATUS_VIOLATION; |
| 192 | - } elseif ( $checkResult === false ) { |
|
| 192 | + } elseif ($checkResult === false) { |
|
| 193 | 193 | throw new ConstraintParameterException( |
| 194 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
| 195 | - ->withInlineCode( $format, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
| 194 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
| 195 | + ->withInlineCode($format, Role::CONSTRAINT_PARAMETER_VALUE) |
|
| 196 | 196 | ); |
| 197 | 197 | } else { |
| 198 | 198 | return $checkResult; |
@@ -206,35 +206,35 @@ discard block |
||
| 206 | 206 | * - FALSE if $format is invalid regex |
| 207 | 207 | * - CheckResult::STATUS_TODO if Shellbox is not enabled |
| 208 | 208 | */ |
| 209 | - private function runRegexCheckUsingShellbox( string $text, string $format ) { |
|
| 210 | - if ( !$this->shellboxClientFactory->isEnabled( 'constraint-regex-checker' ) ) { |
|
| 209 | + private function runRegexCheckUsingShellbox(string $text, string $format) { |
|
| 210 | + if (!$this->shellboxClientFactory->isEnabled('constraint-regex-checker')) { |
|
| 211 | 211 | return CheckResult::STATUS_TODO; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - return $this->shellboxClientFactory->getClient( [ |
|
| 215 | - 'timeout' => $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' ) / 1000, |
|
| 214 | + return $this->shellboxClientFactory->getClient([ |
|
| 215 | + 'timeout' => $this->config->get('WBQualityConstraintsSparqlMaxMillis') / 1000, |
|
| 216 | 216 | 'service' => 'constraint-regex-checker', |
| 217 | - ] )->call( |
|
| 217 | + ])->call( |
|
| 218 | 218 | 'constraint-regex-checker', |
| 219 | - [ FormatCheckerHelper::class, 'runRegexCheck' ], |
|
| 220 | - [ $format, $text ], |
|
| 221 | - [ 'classes' => [ FormatCheckerHelper::class ] ], |
|
| 219 | + [FormatCheckerHelper::class, 'runRegexCheck'], |
|
| 220 | + [$format, $text], |
|
| 221 | + ['classes' => [FormatCheckerHelper::class]], |
|
| 222 | 222 | ); |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - private function runRegexCheckUsingSparql( string $text, string $format ): string { |
|
| 226 | - if ( $this->sparqlHelper instanceof DummySparqlHelper ) { |
|
| 225 | + private function runRegexCheckUsingSparql(string $text, string $format): string { |
|
| 226 | + if ($this->sparqlHelper instanceof DummySparqlHelper) { |
|
| 227 | 227 | return CheckResult::STATUS_TODO; |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) { |
|
| 230 | + if ($this->sparqlHelper->matchesRegularExpression($text, $format)) { |
|
| 231 | 231 | return CheckResult::STATUS_COMPLIANCE; |
| 232 | 232 | } else { |
| 233 | 233 | return CheckResult::STATUS_VIOLATION; |
| 234 | 234 | } |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 237 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 238 | 238 | $constraintParameters = $constraint->getConstraintParameters(); |
| 239 | 239 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
| 240 | 240 | $exceptions = []; |
@@ -243,14 +243,14 @@ discard block |
||
| 243 | 243 | $constraintParameters, |
| 244 | 244 | $constraintTypeItemId |
| 245 | 245 | ); |
| 246 | - } catch ( ConstraintParameterException $e ) { |
|
| 246 | + } catch (ConstraintParameterException $e) { |
|
| 247 | 247 | $exceptions[] = $e; |
| 248 | 248 | } |
| 249 | 249 | try { |
| 250 | 250 | $this->constraintParameterParser->parseSyntaxClarificationParameter( |
| 251 | 251 | $constraintParameters |
| 252 | 252 | ); |
| 253 | - } catch ( ConstraintParameterException $e ) { |
|
| 253 | + } catch (ConstraintParameterException $e) { |
|
| 254 | 254 | $exceptions[] = $e; |
| 255 | 255 | } |
| 256 | 256 | return $exceptions; |