@@ -8,20 +8,20 @@ |
||
8 | 8 | use Wikibase\Repo\WikibaseRepo; |
9 | 9 | |
10 | 10 | return [ |
11 | - WikibaseServices::ENTITY_LOOKUP => static function ( MediaWikiServices $services ) { |
|
11 | + WikibaseServices::ENTITY_LOOKUP => static function(MediaWikiServices $services) { |
|
12 | 12 | return new ExceptionIgnoringEntityLookup( |
13 | - WikibaseRepo::getEntityLookup( $services ) |
|
13 | + WikibaseRepo::getEntityLookup($services) |
|
14 | 14 | ); |
15 | 15 | }, |
16 | 16 | |
17 | - WikibaseServices::ENTITY_LOOKUP_WITHOUT_CACHE => static function ( MediaWikiServices $services ) { |
|
17 | + WikibaseServices::ENTITY_LOOKUP_WITHOUT_CACHE => static function(MediaWikiServices $services) { |
|
18 | 18 | return new ExceptionIgnoringEntityLookup( |
19 | - WikibaseRepo::getStore( $services ) |
|
20 | - ->getEntityLookup( Store::LOOKUP_CACHING_RETRIEVE_ONLY ) |
|
19 | + WikibaseRepo::getStore($services) |
|
20 | + ->getEntityLookup(Store::LOOKUP_CACHING_RETRIEVE_ONLY) |
|
21 | 21 | ); |
22 | 22 | }, |
23 | 23 | |
24 | - WikibaseServices::PROPERTY_DATA_TYPE_LOOKUP => static function ( MediaWikiServices $services ) { |
|
25 | - return WikibaseRepo::getPropertyDataTypeLookup( $services ); |
|
24 | + WikibaseServices::PROPERTY_DATA_TYPE_LOOKUP => static function(MediaWikiServices $services) { |
|
25 | + return WikibaseRepo::getPropertyDataTypeLookup($services); |
|
26 | 26 | }, |
27 | 27 | ]; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Checker; |
6 | 6 | |
@@ -77,26 +77,26 @@ discard block |
||
77 | 77 | * @return array first element is the namespace number (default namespace for TitleParser), |
78 | 78 | * second element is a string to prepend to the title before giving it to the TitleParser |
79 | 79 | */ |
80 | - private function getCommonsNamespace( string $namespace ): array { |
|
81 | - switch ( $namespace ) { |
|
80 | + private function getCommonsNamespace(string $namespace): array { |
|
81 | + switch ($namespace) { |
|
82 | 82 | case '': |
83 | - return [ NS_MAIN, '' ]; |
|
83 | + return [NS_MAIN, '']; |
|
84 | 84 | // extra namespaces, see operations/mediawiki-config.git, |
85 | 85 | // wmf-config/InitialiseSettings.php, 'wgExtraNamespaces' key, 'commonswiki' subkey |
86 | 86 | case 'Creator': |
87 | - return [ 100, '' ]; |
|
87 | + return [100, '']; |
|
88 | 88 | case 'TimedText': |
89 | - return [ 102, '' ]; |
|
89 | + return [102, '']; |
|
90 | 90 | case 'Sequence': |
91 | - return [ 104, '' ]; |
|
91 | + return [104, '']; |
|
92 | 92 | case 'Institution': |
93 | - return [ 106, '' ]; |
|
93 | + return [106, '']; |
|
94 | 94 | // extension namespace, see mediawiki/extensions/JsonConfig.git, |
95 | 95 | // extension.json, 'namespaces' key, third element |
96 | 96 | case 'Data': |
97 | - return [ 486, '' ]; |
|
97 | + return [486, '']; |
|
98 | 98 | default: |
99 | - return [ NS_MAIN, $namespace . ':' ]; |
|
99 | + return [NS_MAIN, $namespace.':']; |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @throws ConstraintParameterException |
107 | 107 | */ |
108 | - public function checkConstraint( Context $context, Constraint $constraint ): CheckResult { |
|
108 | + public function checkConstraint(Context $context, Constraint $constraint): CheckResult { |
|
109 | 109 | $parameters = []; |
110 | 110 | $constraintParameters = $constraint->getConstraintParameters(); |
111 | 111 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
@@ -114,13 +114,13 @@ discard block |
||
114 | 114 | $constraintParameters, |
115 | 115 | $constraintTypeItemId |
116 | 116 | ); |
117 | - $parameters['namespace'] = [ $namespace ]; |
|
117 | + $parameters['namespace'] = [$namespace]; |
|
118 | 118 | |
119 | 119 | $snak = $context->getSnak(); |
120 | 120 | |
121 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
121 | + if (!$snak instanceof PropertyValueSnak) { |
|
122 | 122 | // nothing to check |
123 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
123 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | $dataValue = $snak->getDataValue(); |
@@ -130,52 +130,52 @@ discard block |
||
130 | 130 | * type of $dataValue for properties with 'Commons link' constraint has to be 'string' |
131 | 131 | * parameter $namespace can be null, works for commons galleries |
132 | 132 | */ |
133 | - if ( $dataValue->getType() !== 'string' ) { |
|
134 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
135 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
136 | - ->withDataValueType( 'string' ); |
|
137 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
133 | + if ($dataValue->getType() !== 'string') { |
|
134 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
135 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
136 | + ->withDataValueType('string'); |
|
137 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | $commonsLink = $dataValue->getValue(); |
141 | - if ( !$this->commonsLinkIsWellFormed( $commonsLink ) ) { |
|
142 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
143 | - new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ) ); |
|
141 | + if (!$this->commonsLinkIsWellFormed($commonsLink)) { |
|
142 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
143 | + new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed')); |
|
144 | 144 | } |
145 | 145 | |
146 | - $dataType = $this->propertyDatatypeLookup->getDataTypeIdForProperty( $snak->getPropertyId() ); |
|
147 | - switch ( $dataType ) { |
|
146 | + $dataType = $this->propertyDatatypeLookup->getDataTypeIdForProperty($snak->getPropertyId()); |
|
147 | + switch ($dataType) { |
|
148 | 148 | case 'geo-shape': |
149 | 149 | case 'tabular-data': |
150 | - if ( strpos( $commonsLink, $namespace . ':' ) !== 0 ) { |
|
151 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
152 | - new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ) ); |
|
150 | + if (strpos($commonsLink, $namespace.':') !== 0) { |
|
151 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
152 | + new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed')); |
|
153 | 153 | } |
154 | 154 | $pageName = $commonsLink; |
155 | 155 | break; |
156 | 156 | default: |
157 | - $pageName = $namespace ? $namespace . ':' . $commonsLink : $commonsLink; |
|
157 | + $pageName = $namespace ? $namespace.':'.$commonsLink : $commonsLink; |
|
158 | 158 | break; |
159 | 159 | } |
160 | 160 | |
161 | - $prefix = $this->getCommonsNamespace( $namespace )[1]; |
|
161 | + $prefix = $this->getCommonsNamespace($namespace)[1]; |
|
162 | 162 | $normalizedTitle = $this->pageNameNormalizer->normalizePageName( |
163 | 163 | $pageName, |
164 | 164 | 'https://commons.wikimedia.org/w/api.php' |
165 | 165 | ); |
166 | - if ( $normalizedTitle === false ) { |
|
167 | - if ( $this->valueIncludesNamespace( $commonsLink, $namespace ) ) { |
|
168 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
169 | - new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ) ); |
|
166 | + if ($normalizedTitle === false) { |
|
167 | + if ($this->valueIncludesNamespace($commonsLink, $namespace)) { |
|
168 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
169 | + new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed')); |
|
170 | 170 | } |
171 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
172 | - new ViolationMessage( 'wbqc-violation-message-commons-link-no-existent' ) ); |
|
171 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
172 | + new ViolationMessage('wbqc-violation-message-commons-link-no-existent')); |
|
173 | 173 | } |
174 | 174 | |
175 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, null ); |
|
175 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, null); |
|
176 | 176 | } |
177 | 177 | |
178 | - public function checkConstraintParameters( Constraint $constraint ): array { |
|
178 | + public function checkConstraintParameters(Constraint $constraint): array { |
|
179 | 179 | $constraintParameters = $constraint->getConstraintParameters(); |
180 | 180 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
181 | 181 | $exceptions = []; |
@@ -184,15 +184,15 @@ discard block |
||
184 | 184 | $constraintParameters, |
185 | 185 | $constraintTypeItemId |
186 | 186 | ); |
187 | - } catch ( ConstraintParameterException $e ) { |
|
187 | + } catch (ConstraintParameterException $e) { |
|
188 | 188 | $exceptions[] = $e; |
189 | 189 | } |
190 | 190 | return $exceptions; |
191 | 191 | } |
192 | 192 | |
193 | - private function commonsLinkIsWellFormed( string $commonsLink ): bool { |
|
194 | - $toReplace = [ "_", "%20" ]; |
|
195 | - $compareString = trim( str_replace( $toReplace, '', $commonsLink ) ); |
|
193 | + private function commonsLinkIsWellFormed(string $commonsLink): bool { |
|
194 | + $toReplace = ["_", "%20"]; |
|
195 | + $compareString = trim(str_replace($toReplace, '', $commonsLink)); |
|
196 | 196 | |
197 | 197 | return $commonsLink === $compareString; |
198 | 198 | } |
@@ -201,9 +201,9 @@ discard block |
||
201 | 201 | * Checks whether the value of the statement already includes the namespace. |
202 | 202 | * This special case should be reported as “malformed title” instead of “title does not exist”. |
203 | 203 | */ |
204 | - private function valueIncludesNamespace( string $value, string $namespace ): bool { |
|
204 | + private function valueIncludesNamespace(string $value, string $namespace): bool { |
|
205 | 205 | return $namespace !== '' && |
206 | - strncasecmp( $value, $namespace . ':', strlen( $namespace ) + 1 ) === 0; |
|
206 | + strncasecmp($value, $namespace.':', strlen($namespace) + 1) === 0; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | } |
@@ -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; |
@@ -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 | } |