@@ -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( 'constraint-regex-checker' ) ) { |
|
192 | + private function runRegexCheckUsingShellbox(string $text, string $format): string { |
|
193 | + if (!$this->shellboxClientFactory->isEnabled('constraint-regex-checker')) { |
|
194 | 194 | return CheckResult::STATUS_TODO; |
195 | 195 | } |
196 | 196 | try { |
197 | - $pattern = '/^(?:' . str_replace( '/', '\/', $format ) . ')$/u'; |
|
198 | - $shellboxResponse = $this->shellboxClientFactory->getClient( [ |
|
199 | - 'timeout' => $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' ) / 1000, |
|
197 | + $pattern = '/^(?:'.str_replace('/', '\/', $format).')$/u'; |
|
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; |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | * @throws ConstraintParameterException |
85 | 85 | * @return CheckResult |
86 | 86 | */ |
87 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
88 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
89 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
87 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
88 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
89 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | $parameters = []; |
@@ -100,50 +100,50 @@ discard block |
||
100 | 100 | ); |
101 | 101 | $parameters['languages'] = $languages; |
102 | 102 | |
103 | - $message = ( new ViolationMessage( 'wbqc-violation-message-language' ) ) |
|
104 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ) |
|
105 | - ->withItemIdSnakValueList( $languages, Role::OBJECT ); |
|
103 | + $message = (new ViolationMessage('wbqc-violation-message-language')) |
|
104 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE) |
|
105 | + ->withItemIdSnakValueList($languages, Role::OBJECT); |
|
106 | 106 | $status = CheckResult::STATUS_VIOLATION; |
107 | 107 | |
108 | - $lexeme = $this->getLexeme( $context ); |
|
109 | - if ( !$lexeme ) { |
|
108 | + $lexeme = $this->getLexeme($context); |
|
109 | + if (!$lexeme) { |
|
110 | 110 | // Lexeme doesn't exist, let's not bother |
111 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE ); |
|
111 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** @var Lexeme $lexeme */ |
115 | 115 | '@phan-var Lexeme $lexeme'; |
116 | 116 | |
117 | - foreach ( $languages as $language ) { |
|
118 | - if ( $language->isNoValue() || $language->isSomeValue() ) { |
|
117 | + foreach ($languages as $language) { |
|
118 | + if ($language->isNoValue() || $language->isSomeValue()) { |
|
119 | 119 | continue; |
120 | 120 | } |
121 | - if ( $lexeme->getLanguage()->equals( $language->getItemId() ) ) { |
|
121 | + if ($lexeme->getLanguage()->equals($language->getItemId())) { |
|
122 | 122 | $message = null; |
123 | 123 | $status = CheckResult::STATUS_COMPLIANCE; |
124 | 124 | break; |
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
128 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
128 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
129 | 129 | } |
130 | 130 | |
131 | - private function getLexeme( Context $context ): ?EntityDocument { |
|
131 | + private function getLexeme(Context $context): ?EntityDocument { |
|
132 | 132 | $entityType = $context->getEntity()->getType(); |
133 | 133 | |
134 | - if ( $entityType === Lexeme::ENTITY_TYPE ) { |
|
134 | + if ($entityType === Lexeme::ENTITY_TYPE) { |
|
135 | 135 | return $context->getEntity(); |
136 | 136 | } |
137 | 137 | |
138 | - if ( in_array( $entityType, [ Form::ENTITY_TYPE, Sense::ENTITY_TYPE ] ) ) { |
|
138 | + if (in_array($entityType, [Form::ENTITY_TYPE, Sense::ENTITY_TYPE])) { |
|
139 | 139 | /** @var LexemeSubEntityId $id */ |
140 | 140 | $id = $context->getEntity()->getId(); |
141 | 141 | '@phan-var LexemeSubEntityId $id'; |
142 | - return $this->entityLookup->getEntity( $id->getLexemeId() ); |
|
142 | + return $this->entityLookup->getEntity($id->getLexemeId()); |
|
143 | 143 | } |
144 | 144 | } |
145 | 145 | |
146 | - public function checkConstraintParameters( Constraint $constraint ): array { |
|
146 | + public function checkConstraintParameters(Constraint $constraint): array { |
|
147 | 147 | $constraintParameters = $constraint->getConstraintParameters(); |
148 | 148 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
149 | 149 | $exceptions = []; |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | $constraintTypeItemId, |
154 | 154 | true |
155 | 155 | ); |
156 | - } catch ( ConstraintParameterException $e ) { |
|
156 | + } catch (ConstraintParameterException $e) { |
|
157 | 157 | $exceptions[] = $e; |
158 | 158 | } |
159 | 159 | return $exceptions; |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | return self::ALL_ENTITY_TYPES_SUPPORTED; |
55 | 55 | } |
56 | 56 | |
57 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
57 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
58 | 58 | $constraintParameters = $constraint->getConstraintParameters(); |
59 | 59 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
60 | 60 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | $constraintTypeItemId |
64 | 64 | ); |
65 | 65 | |
66 | - if ( in_array( $context->getType(), $allowedContextTypes ) ) { |
|
66 | + if (in_array($context->getType(), $allowedContextTypes)) { |
|
67 | 67 | return new CheckResult( |
68 | 68 | $context->getCursor(), |
69 | 69 | $constraint, |
@@ -76,15 +76,15 @@ discard block |
||
76 | 76 | $constraint, |
77 | 77 | [], |
78 | 78 | CheckResult::STATUS_VIOLATION, |
79 | - ( new ViolationMessage( 'wbqc-violation-message-property-scope' ) ) |
|
80 | - ->withEntityId( $context->getSnak()->getPropertyId() ) |
|
81 | - ->withPropertyScope( $context->getType() ) |
|
82 | - ->withPropertyScopeList( $allowedContextTypes ) |
|
79 | + (new ViolationMessage('wbqc-violation-message-property-scope')) |
|
80 | + ->withEntityId($context->getSnak()->getPropertyId()) |
|
81 | + ->withPropertyScope($context->getType()) |
|
82 | + ->withPropertyScopeList($allowedContextTypes) |
|
83 | 83 | ); |
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
87 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
87 | + public function checkConstraintParameters(Constraint $constraint) { |
|
88 | 88 | $constraintParameters = $constraint->getConstraintParameters(); |
89 | 89 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
90 | 90 | $exceptions = []; |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | $constraintParameters, |
94 | 94 | $constraintTypeItemId |
95 | 95 | ); |
96 | - } catch ( ConstraintParameterException $e ) { |
|
96 | + } catch (ConstraintParameterException $e) { |
|
97 | 97 | $exceptions[] = $e; |
98 | 98 | } |
99 | 99 | return $exceptions; |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @codeCoverageIgnore This method is purely declarative. |
80 | 80 | */ |
81 | 81 | public function getDefaultContextTypes() { |
82 | - return [ Context::TYPE_STATEMENT ]; |
|
82 | + return [Context::TYPE_STATEMENT]; |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** @codeCoverageIgnore This method is purely declarative. */ |
@@ -96,31 +96,31 @@ discard block |
||
96 | 96 | * @return CheckResult |
97 | 97 | * @throws \ConfigException |
98 | 98 | */ |
99 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
100 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
101 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
99 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
100 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
101 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
102 | 102 | } |
103 | 103 | $snak = $context->getSnak(); |
104 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
104 | + if (!$snak instanceof PropertyValueSnak) { |
|
105 | 105 | // nothing to check |
106 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
106 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | $dataValue = $snak->getDataValue(); |
110 | - if ( !$dataValue instanceof EntityIdValue ) { |
|
110 | + if (!$dataValue instanceof EntityIdValue) { |
|
111 | 111 | // wrong data type |
112 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
113 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ) |
|
114 | - ->withDataValueType( 'wikibase-entityid' ); |
|
115 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
112 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
113 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM) |
|
114 | + ->withDataValueType('wikibase-entityid'); |
|
115 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | $objectId = $dataValue->getEntityId(); |
119 | - $objectItem = $this->entityLookup->getEntity( $objectId ); |
|
120 | - if ( !( $objectItem instanceof StatementListProvider ) ) { |
|
119 | + $objectItem = $this->entityLookup->getEntity($objectId); |
|
120 | + if (!($objectItem instanceof StatementListProvider)) { |
|
121 | 121 | // object was deleted/doesn't exist |
122 | - $message = new ViolationMessage( 'wbqc-violation-message-value-entity-must-exist' ); |
|
123 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
122 | + $message = new ViolationMessage('wbqc-violation-message-value-entity-must-exist'); |
|
123 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
124 | 124 | } |
125 | 125 | /** @var Statement[] $objectStatements */ |
126 | 126 | $objectStatements = $objectItem->getStatements()->toArray(); |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | $subjectId = $context->getEntity()->getId(); |
129 | 129 | $subjectStatements = $context->getEntity()->getStatements()->toArray(); |
130 | 130 | /** @var String[] $startPropertyIds */ |
131 | - $startPropertyIds = $this->config->get( self::CONFIG_VARIABLE_START_PROPERTY_IDS ); |
|
131 | + $startPropertyIds = $this->config->get(self::CONFIG_VARIABLE_START_PROPERTY_IDS); |
|
132 | 132 | /** @var String[] $endPropertyIds */ |
133 | - $endPropertyIds = $this->config->get( self::CONFIG_VARIABLE_END_PROPERTY_IDS ); |
|
133 | + $endPropertyIds = $this->config->get(self::CONFIG_VARIABLE_END_PROPERTY_IDS); |
|
134 | 134 | $subjectStartValue = $this->getExtremeValue( |
135 | 135 | $startPropertyIds, |
136 | 136 | $subjectStatements, |
@@ -152,15 +152,15 @@ discard block |
||
152 | 152 | 'end' |
153 | 153 | ); |
154 | 154 | if ( |
155 | - $this->rangeCheckerHelper->getComparison( $subjectStartValue, $subjectEndValue ) <= 0 && |
|
156 | - $this->rangeCheckerHelper->getComparison( $objectStartValue, $objectEndValue ) <= 0 && ( |
|
157 | - $this->rangeCheckerHelper->getComparison( $subjectEndValue, $objectStartValue ) < 0 || |
|
158 | - $this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectStartValue ) < 0 |
|
155 | + $this->rangeCheckerHelper->getComparison($subjectStartValue, $subjectEndValue) <= 0 && |
|
156 | + $this->rangeCheckerHelper->getComparison($objectStartValue, $objectEndValue) <= 0 && ( |
|
157 | + $this->rangeCheckerHelper->getComparison($subjectEndValue, $objectStartValue) < 0 || |
|
158 | + $this->rangeCheckerHelper->getComparison($objectEndValue, $subjectStartValue) < 0 |
|
159 | 159 | ) |
160 | 160 | ) { |
161 | 161 | if ( |
162 | 162 | $subjectEndValue == null || |
163 | - $this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectEndValue ) < 0 |
|
163 | + $this->rangeCheckerHelper->getComparison($objectEndValue, $subjectEndValue) < 0 |
|
164 | 164 | ) { |
165 | 165 | $earlierEntityId = $objectId; |
166 | 166 | $minEndValue = $objectEndValue; |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | $message = null; |
184 | 184 | $status = CheckResult::STATUS_COMPLIANCE; |
185 | 185 | } |
186 | - return new CheckResult( $context, $constraint, [], $status, $message ); |
|
186 | + return new CheckResult($context, $constraint, [], $status, $message); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -193,19 +193,19 @@ discard block |
||
193 | 193 | * |
194 | 194 | * @return DataValue|null |
195 | 195 | */ |
196 | - private function getExtremeValue( $extremePropertyIds, $statements, $startOrEnd ) { |
|
197 | - if ( $startOrEnd !== 'start' && $startOrEnd !== 'end' ) { |
|
198 | - throw new \InvalidArgumentException( '$startOrEnd must be \'start\' or \'end\'.' ); |
|
196 | + private function getExtremeValue($extremePropertyIds, $statements, $startOrEnd) { |
|
197 | + if ($startOrEnd !== 'start' && $startOrEnd !== 'end') { |
|
198 | + throw new \InvalidArgumentException('$startOrEnd must be \'start\' or \'end\'.'); |
|
199 | 199 | } |
200 | 200 | $extremeValue = null; |
201 | - foreach ( $extremePropertyIds as $extremePropertyId ) { |
|
202 | - $statementList = new StatementList( ...$statements ); |
|
203 | - $extremeStatements = $statementList->getByPropertyId( new PropertyId( $extremePropertyId ) ); |
|
201 | + foreach ($extremePropertyIds as $extremePropertyId) { |
|
202 | + $statementList = new StatementList(...$statements); |
|
203 | + $extremeStatements = $statementList->getByPropertyId(new PropertyId($extremePropertyId)); |
|
204 | 204 | /** @var Statement $extremeStatement */ |
205 | - foreach ( $extremeStatements as $extremeStatement ) { |
|
206 | - if ( $extremeStatement->getRank() !== Statement::RANK_DEPRECATED ) { |
|
205 | + foreach ($extremeStatements as $extremeStatement) { |
|
206 | + if ($extremeStatement->getRank() !== Statement::RANK_DEPRECATED) { |
|
207 | 207 | $snak = $extremeStatement->getMainSnak(); |
208 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
208 | + if (!$snak instanceof PropertyValueSnak) { |
|
209 | 209 | return null; |
210 | 210 | } else { |
211 | 211 | $comparison = $this->rangeCheckerHelper->getComparison( |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | ); |
215 | 215 | if ( |
216 | 216 | $extremeValue === null || |
217 | - ( $startOrEnd === 'start' && $comparison < 0 ) || |
|
218 | - ( $startOrEnd === 'end' && $comparison > 0 ) |
|
217 | + ($startOrEnd === 'start' && $comparison < 0) || |
|
218 | + ($startOrEnd === 'end' && $comparison > 0) |
|
219 | 219 | ) { |
220 | 220 | $extremeValue = $snak->getDataValue(); |
221 | 221 | } |
@@ -245,17 +245,16 @@ discard block |
||
245 | 245 | DataValue $maxStartValue |
246 | 246 | ) { |
247 | 247 | $messageKey = $earlierEntityId === $subjectId ? |
248 | - 'wbqc-violation-message-contemporary-subject-earlier' : |
|
249 | - 'wbqc-violation-message-contemporary-value-earlier'; |
|
250 | - return ( new ViolationMessage( $messageKey ) ) |
|
251 | - ->withEntityId( $subjectId, Role::SUBJECT ) |
|
252 | - ->withEntityId( $propertyId, Role::PREDICATE ) |
|
253 | - ->withEntityId( $objectId, Role::OBJECT ) |
|
254 | - ->withDataValue( $minEndValue, Role::OBJECT ) |
|
255 | - ->withDataValue( $maxStartValue, Role::OBJECT ); |
|
248 | + 'wbqc-violation-message-contemporary-subject-earlier' : 'wbqc-violation-message-contemporary-value-earlier'; |
|
249 | + return (new ViolationMessage($messageKey)) |
|
250 | + ->withEntityId($subjectId, Role::SUBJECT) |
|
251 | + ->withEntityId($propertyId, Role::PREDICATE) |
|
252 | + ->withEntityId($objectId, Role::OBJECT) |
|
253 | + ->withDataValue($minEndValue, Role::OBJECT) |
|
254 | + ->withDataValue($maxStartValue, Role::OBJECT); |
|
256 | 255 | } |
257 | 256 | |
258 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
257 | + public function checkConstraintParameters(Constraint $constraint) { |
|
259 | 258 | // no parameters |
260 | 259 | return []; |
261 | 260 | } |
@@ -46,23 +46,22 @@ discard block |
||
46 | 46 | return self::ALL_ENTITY_TYPES_SUPPORTED; |
47 | 47 | } |
48 | 48 | |
49 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
49 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
50 | 50 | $snak = $context->getSnak(); |
51 | 51 | |
52 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
52 | + if (!$snak instanceof PropertyValueSnak) { |
|
53 | 53 | // nothing to check |
54 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
54 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
55 | 55 | } |
56 | 56 | |
57 | - $violationMessage = $this->checkSnak( $snak ); |
|
57 | + $violationMessage = $this->checkSnak($snak); |
|
58 | 58 | |
59 | 59 | return new CheckResult( |
60 | 60 | $context, |
61 | 61 | $constraint, |
62 | 62 | [], |
63 | 63 | $violationMessage === null ? |
64 | - CheckResult::STATUS_COMPLIANCE : |
|
65 | - CheckResult::STATUS_VIOLATION, |
|
64 | + CheckResult::STATUS_COMPLIANCE : CheckResult::STATUS_VIOLATION, |
|
66 | 65 | $violationMessage |
67 | 66 | ); |
68 | 67 | } |
@@ -71,23 +70,23 @@ discard block |
||
71 | 70 | * @param PropertyValueSnak $snak |
72 | 71 | * @return ViolationMessage|null |
73 | 72 | */ |
74 | - public function checkSnak( PropertyValueSnak $snak ) { |
|
73 | + public function checkSnak(PropertyValueSnak $snak) { |
|
75 | 74 | $dataValue = $snak->getDataValue(); |
76 | 75 | |
77 | - if ( $dataValue instanceof DecimalValue ) { |
|
78 | - if ( !$this->isInteger( $dataValue ) ) { |
|
79 | - return $this->getViolationMessage( 'wbqc-violation-message-integer', $snak ); |
|
76 | + if ($dataValue instanceof DecimalValue) { |
|
77 | + if (!$this->isInteger($dataValue)) { |
|
78 | + return $this->getViolationMessage('wbqc-violation-message-integer', $snak); |
|
80 | 79 | } |
81 | - } elseif ( $dataValue instanceof UnboundedQuantityValue ) { |
|
82 | - if ( !$this->isInteger( $dataValue->getAmount() ) ) { |
|
83 | - return $this->getViolationMessage( 'wbqc-violation-message-integer', $snak ); |
|
80 | + } elseif ($dataValue instanceof UnboundedQuantityValue) { |
|
81 | + if (!$this->isInteger($dataValue->getAmount())) { |
|
82 | + return $this->getViolationMessage('wbqc-violation-message-integer', $snak); |
|
84 | 83 | } elseif ( |
85 | 84 | $dataValue instanceof QuantityValue && ( |
86 | - !$this->isInteger( $dataValue->getLowerBound() ) || |
|
87 | - !$this->isInteger( $dataValue->getUpperBound() ) |
|
85 | + !$this->isInteger($dataValue->getLowerBound()) || |
|
86 | + !$this->isInteger($dataValue->getUpperBound()) |
|
88 | 87 | ) |
89 | 88 | ) { |
90 | - return $this->getViolationMessage( 'wbqc-violation-message-integer-bounds', $snak ); |
|
89 | + return $this->getViolationMessage('wbqc-violation-message-integer-bounds', $snak); |
|
91 | 90 | } |
92 | 91 | } |
93 | 92 | |
@@ -98,7 +97,7 @@ discard block |
||
98 | 97 | * @param DecimalValue $decimalValue |
99 | 98 | * @return bool |
100 | 99 | */ |
101 | - private function isInteger( DecimalValue $decimalValue ) { |
|
100 | + private function isInteger(DecimalValue $decimalValue) { |
|
102 | 101 | return $decimalValue->getTrimmed()->getFractionalPart() === ''; |
103 | 102 | } |
104 | 103 | |
@@ -107,13 +106,13 @@ discard block |
||
107 | 106 | * @param PropertyValueSnak $snak |
108 | 107 | * @return ViolationMessage |
109 | 108 | */ |
110 | - private function getViolationMessage( $messageKey, PropertyValueSnak $snak ) { |
|
111 | - return ( new ViolationMessage( $messageKey ) ) |
|
112 | - ->withEntityId( $snak->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
113 | - ->withDataValue( $snak->getDataValue() ); |
|
109 | + private function getViolationMessage($messageKey, PropertyValueSnak $snak) { |
|
110 | + return (new ViolationMessage($messageKey)) |
|
111 | + ->withEntityId($snak->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
112 | + ->withDataValue($snak->getDataValue()); |
|
114 | 113 | } |
115 | 114 | |
116 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
115 | + public function checkConstraintParameters(Constraint $constraint) { |
|
117 | 116 | // no parameters |
118 | 117 | return []; |
119 | 118 | } |
@@ -41,16 +41,16 @@ |
||
41 | 41 | return self::ALL_ENTITY_TYPES_SUPPORTED; |
42 | 42 | } |
43 | 43 | |
44 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
45 | - if ( $context->getType() === Context::TYPE_REFERENCE ) { |
|
46 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
44 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
45 | + if ($context->getType() === Context::TYPE_REFERENCE) { |
|
46 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
47 | 47 | } else { |
48 | - $message = new ViolationMessage( 'wbqc-violation-message-reference' ); |
|
49 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
48 | + $message = new ViolationMessage('wbqc-violation-message-reference'); |
|
49 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
53 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
53 | + public function checkConstraintParameters(Constraint $constraint) { |
|
54 | 54 | // no parameters |
55 | 55 | return []; |
56 | 56 | } |
@@ -44,17 +44,17 @@ discard block |
||
44 | 44 | return self::ALL_ENTITY_TYPES_SUPPORTED; |
45 | 45 | } |
46 | 46 | |
47 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
47 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
48 | 48 | $snak = $context->getSnak(); |
49 | 49 | |
50 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
50 | + if (!$snak instanceof PropertyValueSnak) { |
|
51 | 51 | // nothing to check |
52 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
52 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
53 | 53 | } |
54 | 54 | |
55 | - if ( $snak->getDataValue() instanceof QuantityValue ) { |
|
56 | - $message = ( new ViolationMessage( 'wbqc-violation-message-noBounds' ) ) |
|
57 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ); |
|
55 | + if ($snak->getDataValue() instanceof QuantityValue) { |
|
56 | + $message = (new ViolationMessage('wbqc-violation-message-noBounds')) |
|
57 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY); |
|
58 | 58 | return new CheckResult( |
59 | 59 | $context, |
60 | 60 | $constraint, |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | ); |
65 | 65 | } |
66 | 66 | |
67 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
67 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
68 | 68 | } |
69 | 69 | |
70 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
70 | + public function checkConstraintParameters(Constraint $constraint) { |
|
71 | 71 | // no parameters |
72 | 72 | return []; |
73 | 73 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @codeCoverageIgnore This method is purely declarative. |
31 | 31 | */ |
32 | 32 | public function getDefaultContextTypes() { |
33 | - return [ Context::TYPE_STATEMENT ]; |
|
33 | + return [Context::TYPE_STATEMENT]; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** @codeCoverageIgnore This method is purely declarative. */ |
@@ -38,12 +38,12 @@ discard block |
||
38 | 38 | return self::ALL_ENTITY_TYPES_SUPPORTED; |
39 | 39 | } |
40 | 40 | |
41 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
41 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
42 | 42 | $referenceList = $context->getSnakStatement()->getReferences(); |
43 | 43 | |
44 | - if ( $referenceList->isEmpty() ) { |
|
45 | - $message = ( new ViolationMessage( 'wbqc-violation-message-citationNeeded' ) ) |
|
46 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ); |
|
44 | + if ($referenceList->isEmpty()) { |
|
45 | + $message = (new ViolationMessage('wbqc-violation-message-citationNeeded')) |
|
46 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY); |
|
47 | 47 | return new CheckResult( |
48 | 48 | $context, |
49 | 49 | $constraint, |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | ); |
54 | 54 | } |
55 | 55 | |
56 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
56 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
57 | 57 | } |
58 | 58 | |
59 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
59 | + public function checkConstraintParameters(Constraint $constraint) { |
|
60 | 60 | // no parameters |
61 | 61 | return []; |
62 | 62 | } |
@@ -41,16 +41,16 @@ |
||
41 | 41 | return self::ALL_ENTITY_TYPES_SUPPORTED; |
42 | 42 | } |
43 | 43 | |
44 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
45 | - if ( $context->getType() === Context::TYPE_STATEMENT ) { |
|
46 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
44 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
45 | + if ($context->getType() === Context::TYPE_STATEMENT) { |
|
46 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
47 | 47 | } else { |
48 | - $message = new ViolationMessage( 'wbqc-violation-message-valueOnly' ); |
|
49 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
48 | + $message = new ViolationMessage('wbqc-violation-message-valueOnly'); |
|
49 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
53 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
53 | + public function checkConstraintParameters(Constraint $constraint) { |
|
54 | 54 | // no parameters |
55 | 55 | return []; |
56 | 56 | } |