@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * @throws ConstraintParameterException |
| 98 | 98 | * @return CheckResult |
| 99 | 99 | */ |
| 100 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
| 100 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
| 101 | 101 | $parameters = []; |
| 102 | 102 | $constraintParameters = $constraint->getConstraintParameters(); |
| 103 | 103 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | $constraintParameters, |
| 107 | 107 | $constraintTypeItemId |
| 108 | 108 | ); |
| 109 | - $parameters['pattern'] = [ $format ]; |
|
| 109 | + $parameters['pattern'] = [$format]; |
|
| 110 | 110 | |
| 111 | 111 | $syntaxClarifications = $this->constraintParameterParser->parseSyntaxClarificationParameter( |
| 112 | 112 | $constraintParameters |
@@ -114,9 +114,9 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | $snak = $context->getSnak(); |
| 116 | 116 | |
| 117 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
| 117 | + if (!$snak instanceof PropertyValueSnak) { |
|
| 118 | 118 | // nothing to check |
| 119 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
| 119 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | $dataValue = $snak->getDataValue(); |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * error handling: |
| 126 | 126 | * type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext' |
| 127 | 127 | */ |
| 128 | - switch ( $dataValue->getType() ) { |
|
| 128 | + switch ($dataValue->getType()) { |
|
| 129 | 129 | case 'string': |
| 130 | 130 | $text = $dataValue->getValue(); |
| 131 | 131 | break; |
@@ -135,13 +135,13 @@ discard block |
||
| 135 | 135 | $text = $dataValue->getText(); |
| 136 | 136 | break; |
| 137 | 137 | default: |
| 138 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-types-2' ) ) |
|
| 139 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
| 140 | - ->withDataValueType( 'string' ) |
|
| 141 | - ->withDataValueType( 'monolingualtext' ); |
|
| 142 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
| 138 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-types-2')) |
|
| 139 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
| 140 | + ->withDataValueType('string') |
|
| 141 | + ->withDataValueType('monolingualtext'); |
|
| 142 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
| 143 | 143 | } |
| 144 | - $status = $this->runRegexCheck( $text, $format ); |
|
| 144 | + $status = $this->runRegexCheck($text, $format); |
|
| 145 | 145 | $message = $this->formatMessage( |
| 146 | 146 | $status, |
| 147 | 147 | $text, |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | $syntaxClarifications, |
| 151 | 151 | $constraintTypeItemId |
| 152 | 152 | ); |
| 153 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
| 153 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | private function formatMessage( |
@@ -162,74 +162,74 @@ discard block |
||
| 162 | 162 | string $constraintTypeItemId |
| 163 | 163 | ): ?ViolationMessage { |
| 164 | 164 | $message = null; |
| 165 | - if ( $status === CheckResult::STATUS_VIOLATION ) { |
|
| 166 | - $message = ( new ViolationMessage( 'wbqc-violation-message-format-clarification' ) ) |
|
| 167 | - ->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ) |
|
| 168 | - ->withDataValue( new StringValue( $text ), Role::OBJECT ) |
|
| 169 | - ->withInlineCode( $format, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
| 170 | - ->withMultilingualText( $syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE ); |
|
| 171 | - } elseif ( $status === CheckResult::STATUS_TODO ) { |
|
| 172 | - $message = ( new ViolationMessage( 'wbqc-violation-message-security-reason' ) ) |
|
| 173 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ); |
|
| 165 | + if ($status === CheckResult::STATUS_VIOLATION) { |
|
| 166 | + $message = (new ViolationMessage('wbqc-violation-message-format-clarification')) |
|
| 167 | + ->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY) |
|
| 168 | + ->withDataValue(new StringValue($text), Role::OBJECT) |
|
| 169 | + ->withInlineCode($format, Role::CONSTRAINT_PARAMETER_VALUE) |
|
| 170 | + ->withMultilingualText($syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE); |
|
| 171 | + } elseif ($status === CheckResult::STATUS_TODO) { |
|
| 172 | + $message = (new ViolationMessage('wbqc-violation-message-security-reason')) |
|
| 173 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | return $message; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - private function runRegexCheck( string $text, string $format ): string { |
|
| 180 | - if ( !$this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) ) { |
|
| 179 | + private function runRegexCheck(string $text, string $format): string { |
|
| 180 | + if (!$this->config->get('WBQualityConstraintsCheckFormatConstraint')) { |
|
| 181 | 181 | return CheckResult::STATUS_TODO; |
| 182 | 182 | } |
| 183 | 183 | if ( |
| 184 | - $this->config->get( 'WBQualityConstraintsFormatCheckerShellboxRatio' ) > (float)wfRandom() |
|
| 184 | + $this->config->get('WBQualityConstraintsFormatCheckerShellboxRatio') > (float) wfRandom() |
|
| 185 | 185 | ) { |
| 186 | - return $this->runRegexCheckUsingShellbox( $text, $format ); |
|
| 186 | + return $this->runRegexCheckUsingShellbox($text, $format); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - return $this->runRegexCheckUsingSparql( $text, $format ); |
|
| 189 | + return $this->runRegexCheckUsingSparql($text, $format); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - private function runRegexCheckUsingShellbox( string $text, string $format ): string { |
|
| 193 | - if ( !$this->shellboxClientFactory->isEnabled() ) { |
|
| 192 | + private function runRegexCheckUsingShellbox(string $text, string $format): string { |
|
| 193 | + if (!$this->shellboxClientFactory->isEnabled()) { |
|
| 194 | 194 | return CheckResult::STATUS_TODO; |
| 195 | 195 | } |
| 196 | 196 | try { |
| 197 | - $pattern = '/^' . str_replace( '/', '\/', $format ) . '$/'; |
|
| 198 | - $shellboxResponse = $this->shellboxClientFactory->getClient( [ |
|
| 199 | - 'timeout' => $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' ) / 1000, |
|
| 197 | + $pattern = '/^'.str_replace('/', '\/', $format).'$/'; |
|
| 198 | + $shellboxResponse = $this->shellboxClientFactory->getClient([ |
|
| 199 | + 'timeout' => $this->config->get('WBQualityConstraintsSparqlMaxMillis') / 1000, |
|
| 200 | 200 | 'service' => 'constraint-regex-checker', |
| 201 | - ] )->call( |
|
| 201 | + ])->call( |
|
| 202 | 202 | 'constraint-regex-checker', |
| 203 | 203 | 'preg_match', |
| 204 | - [ $pattern, $text ] |
|
| 204 | + [$pattern, $text] |
|
| 205 | 205 | ); |
| 206 | - } catch ( ShellboxError $exception ) { |
|
| 206 | + } catch (ShellboxError $exception) { |
|
| 207 | 207 | throw new ConstraintParameterException( |
| 208 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
| 209 | - ->withInlineCode( $pattern, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
| 208 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
| 209 | + ->withInlineCode($pattern, Role::CONSTRAINT_PARAMETER_VALUE) |
|
| 210 | 210 | ); |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - if ( $shellboxResponse ) { |
|
| 213 | + if ($shellboxResponse) { |
|
| 214 | 214 | return CheckResult::STATUS_COMPLIANCE; |
| 215 | 215 | } else { |
| 216 | 216 | return CheckResult::STATUS_VIOLATION; |
| 217 | 217 | } |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - private function runRegexCheckUsingSparql( string $text, string $format ): string { |
|
| 221 | - if ( $this->sparqlHelper instanceof DummySparqlHelper ) { |
|
| 220 | + private function runRegexCheckUsingSparql(string $text, string $format): string { |
|
| 221 | + if ($this->sparqlHelper instanceof DummySparqlHelper) { |
|
| 222 | 222 | return CheckResult::STATUS_TODO; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) { |
|
| 225 | + if ($this->sparqlHelper->matchesRegularExpression($text, $format)) { |
|
| 226 | 226 | return CheckResult::STATUS_COMPLIANCE; |
| 227 | 227 | } else { |
| 228 | 228 | return CheckResult::STATUS_VIOLATION; |
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
| 232 | + public function checkConstraintParameters(Constraint $constraint) { |
|
| 233 | 233 | $constraintParameters = $constraint->getConstraintParameters(); |
| 234 | 234 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
| 235 | 235 | $exceptions = []; |
@@ -238,14 +238,14 @@ discard block |
||
| 238 | 238 | $constraintParameters, |
| 239 | 239 | $constraintTypeItemId |
| 240 | 240 | ); |
| 241 | - } catch ( ConstraintParameterException $e ) { |
|
| 241 | + } catch (ConstraintParameterException $e) { |
|
| 242 | 242 | $exceptions[] = $e; |
| 243 | 243 | } |
| 244 | 244 | try { |
| 245 | 245 | $this->constraintParameterParser->parseSyntaxClarificationParameter( |
| 246 | 246 | $constraintParameters |
| 247 | 247 | ); |
| 248 | - } catch ( ConstraintParameterException $e ) { |
|
| 248 | + } catch (ConstraintParameterException $e) { |
|
| 249 | 249 | $exceptions[] = $e; |
| 250 | 250 | } |
| 251 | 251 | return $exceptions; |