@@ -78,22 +78,22 @@ discard block |
||
78 | 78 | * @return array first element is the namespace number (default namespace for TitleParser), |
79 | 79 | * second element is a string to prepend to the title before giving it to the TitleParser |
80 | 80 | */ |
81 | - private function getCommonsNamespace( $namespace ) { |
|
81 | + private function getCommonsNamespace($namespace) { |
|
82 | 82 | // for namespace numbers see mediawiki-config repo, wmf-config/InitialiseSettings.php, |
83 | 83 | // 'wgExtraNamespaces' key, 'commonswiki' subkey |
84 | - switch ( $namespace ) { |
|
84 | + switch ($namespace) { |
|
85 | 85 | case '': |
86 | - return [ NS_MAIN, '' ]; |
|
86 | + return [NS_MAIN, '']; |
|
87 | 87 | case 'Creator': |
88 | - return [ 100, '' ]; |
|
88 | + return [100, '']; |
|
89 | 89 | case 'TimedText': |
90 | - return [ 102, '' ]; |
|
90 | + return [102, '']; |
|
91 | 91 | case 'Sequence': |
92 | - return [ 104, '' ]; |
|
92 | + return [104, '']; |
|
93 | 93 | case 'Institution': |
94 | - return [ 106, '' ]; |
|
94 | + return [106, '']; |
|
95 | 95 | default: |
96 | - return [ NS_MAIN, $namespace . ':' ]; |
|
96 | + return [NS_MAIN, $namespace.':']; |
|
97 | 97 | } |
98 | 98 | } |
99 | 99 | |
@@ -106,17 +106,17 @@ discard block |
||
106 | 106 | * @throws ConstraintParameterException |
107 | 107 | * @return CheckResult |
108 | 108 | */ |
109 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
109 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
110 | 110 | $parameters = []; |
111 | 111 | $constraintParameters = $constraint->getConstraintParameters(); |
112 | - $namespace = $this->constraintParameterParser->parseNamespaceParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
113 | - $parameters['namespace'] = [ $namespace ]; |
|
112 | + $namespace = $this->constraintParameterParser->parseNamespaceParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
113 | + $parameters['namespace'] = [$namespace]; |
|
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(); |
@@ -126,49 +126,49 @@ discard block |
||
126 | 126 | * type of $dataValue for properties with 'Commons link' constraint has to be 'string' |
127 | 127 | * parameter $namespace can be null, works for commons galleries |
128 | 128 | */ |
129 | - if ( $dataValue->getType() !== 'string' ) { |
|
130 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
129 | + if ($dataValue->getType() !== 'string') { |
|
130 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
131 | 131 | ->rawParams( |
132 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
133 | - wfMessage( 'datatypes-type-string' )->escaped() |
|
132 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
133 | + wfMessage('datatypes-type-string')->escaped() |
|
134 | 134 | ) |
135 | 135 | ->escaped(); |
136 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
136 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | $commonsLink = $dataValue->getValue(); |
140 | 140 | |
141 | 141 | try { |
142 | - if ( !$this->commonsLinkIsWellFormed( $commonsLink ) ) { |
|
143 | - throw new MalformedTitleException( 'wbqc-violation-message-commons-link-not-well-formed', $commonsLink ); // caught below |
|
142 | + if (!$this->commonsLinkIsWellFormed($commonsLink)) { |
|
143 | + throw new MalformedTitleException('wbqc-violation-message-commons-link-not-well-formed', $commonsLink); // caught below |
|
144 | 144 | } |
145 | - list( $defaultNamespace, $prefix ) = $this->getCommonsNamespace( $namespace ); |
|
146 | - $title = $this->titleParser->parseTitle( $prefix . $commonsLink, $defaultNamespace ); |
|
147 | - if ( $this->pageExists( $title ) ) { |
|
145 | + list($defaultNamespace, $prefix) = $this->getCommonsNamespace($namespace); |
|
146 | + $title = $this->titleParser->parseTitle($prefix.$commonsLink, $defaultNamespace); |
|
147 | + if ($this->pageExists($title)) { |
|
148 | 148 | $message = null; |
149 | 149 | $status = CheckResult::STATUS_COMPLIANCE; |
150 | 150 | } else { |
151 | - if ( $this->valueIncludesNamespace( $commonsLink, $namespace ) ) { |
|
152 | - throw new MalformedTitleException( 'wbqc-violation-message-commons-link-not-well-formed', $commonsLink ); // caught below |
|
151 | + if ($this->valueIncludesNamespace($commonsLink, $namespace)) { |
|
152 | + throw new MalformedTitleException('wbqc-violation-message-commons-link-not-well-formed', $commonsLink); // caught below |
|
153 | 153 | } else { |
154 | - $message = new ViolationMessage( 'wbqc-violation-message-commons-link-no-existent' ); |
|
154 | + $message = new ViolationMessage('wbqc-violation-message-commons-link-no-existent'); |
|
155 | 155 | $status = CheckResult::STATUS_VIOLATION; |
156 | 156 | } |
157 | 157 | } |
158 | - } catch ( MalformedTitleException $e ) { |
|
159 | - $message = new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ); |
|
158 | + } catch (MalformedTitleException $e) { |
|
159 | + $message = new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed'); |
|
160 | 160 | $status = CheckResult::STATUS_VIOLATION; |
161 | 161 | } |
162 | 162 | |
163 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
163 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
164 | 164 | } |
165 | 165 | |
166 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
166 | + public function checkConstraintParameters(Constraint $constraint) { |
|
167 | 167 | $constraintParameters = $constraint->getConstraintParameters(); |
168 | 168 | $exceptions = []; |
169 | 169 | try { |
170 | - $this->constraintParameterParser->parseNamespaceParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
171 | - } catch ( ConstraintParameterException $e ) { |
|
170 | + $this->constraintParameterParser->parseNamespaceParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
171 | + } catch (ConstraintParameterException $e) { |
|
172 | 172 | $exceptions[] = $e; |
173 | 173 | } |
174 | 174 | return $exceptions; |
@@ -179,19 +179,19 @@ discard block |
||
179 | 179 | * |
180 | 180 | * @return bool |
181 | 181 | */ |
182 | - private function pageExists( TitleValue $title ) { |
|
182 | + private function pageExists(TitleValue $title) { |
|
183 | 183 | $commonsWikiId = 'commonswiki'; |
184 | - if ( defined( 'MW_PHPUNIT_TEST' ) ) { |
|
184 | + if (defined('MW_PHPUNIT_TEST')) { |
|
185 | 185 | $commonsWikiId = false; |
186 | 186 | } |
187 | 187 | |
188 | - $dbLoadBalancer = wfGetLB( $commonsWikiId ); |
|
188 | + $dbLoadBalancer = wfGetLB($commonsWikiId); |
|
189 | 189 | $dbConnection = $dbLoadBalancer->getConnection( |
190 | 190 | DB_REPLICA, false, $commonsWikiId ); |
191 | - $row = $dbConnection->selectRow( 'page', '*', [ |
|
191 | + $row = $dbConnection->selectRow('page', '*', [ |
|
192 | 192 | 'page_title' => $title->getDBkey(), |
193 | 193 | 'page_namespace' => $title->getNamespace() |
194 | - ] ); |
|
194 | + ]); |
|
195 | 195 | |
196 | 196 | return $row !== false; |
197 | 197 | } |
@@ -201,9 +201,9 @@ discard block |
||
201 | 201 | * |
202 | 202 | * @return bool |
203 | 203 | */ |
204 | - private function commonsLinkIsWellFormed( $commonsLink ) { |
|
205 | - $toReplace = [ "_", "%20" ]; |
|
206 | - $compareString = trim( str_replace( $toReplace, '', $commonsLink ) ); |
|
204 | + private function commonsLinkIsWellFormed($commonsLink) { |
|
205 | + $toReplace = ["_", "%20"]; |
|
206 | + $compareString = trim(str_replace($toReplace, '', $commonsLink)); |
|
207 | 207 | return $commonsLink === $compareString; |
208 | 208 | } |
209 | 209 | |
@@ -216,9 +216,9 @@ discard block |
||
216 | 216 | * |
217 | 217 | * @return bool |
218 | 218 | */ |
219 | - private function valueIncludesNamespace( $value, $namespace ) { |
|
219 | + private function valueIncludesNamespace($value, $namespace) { |
|
220 | 220 | return $namespace !== '' && |
221 | - strncasecmp( $value, $namespace . ':', strlen( $namespace ) + 1 ) === 0; |
|
221 | + strncasecmp($value, $namespace.':', strlen($namespace) + 1) === 0; |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | } |
@@ -77,15 +77,15 @@ discard block |
||
77 | 77 | * @param array $parameters |
78 | 78 | * @throws ConstraintParameterException |
79 | 79 | */ |
80 | - public function checkError( array $parameters ) { |
|
81 | - if ( array_key_exists( '@error', $parameters ) ) { |
|
80 | + public function checkError(array $parameters) { |
|
81 | + if (array_key_exists('@error', $parameters)) { |
|
82 | 82 | $error = $parameters['@error']; |
83 | - if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) { |
|
83 | + if (array_key_exists('toolong', $error) && $error['toolong']) { |
|
84 | 84 | $msg = 'wbqc-violation-message-parameters-error-toolong'; |
85 | 85 | } else { |
86 | 86 | $msg = 'wbqc-violation-message-parameters-error-unknown'; |
87 | 87 | } |
88 | - throw new ConstraintParameterException( wfMessage( $msg )->escaped() ); |
|
88 | + throw new ConstraintParameterException(wfMessage($msg)->escaped()); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
@@ -95,11 +95,11 @@ discard block |
||
95 | 95 | * @param string $parameterId |
96 | 96 | * @throws ConstraintParameterException |
97 | 97 | */ |
98 | - private function requireSingleParameter( array $parameters, $parameterId ) { |
|
99 | - if ( count( $parameters[$parameterId] ) !== 1 ) { |
|
98 | + private function requireSingleParameter(array $parameters, $parameterId) { |
|
99 | + if (count($parameters[$parameterId]) !== 1) { |
|
100 | 100 | throw new ConstraintParameterException( |
101 | - wfMessage( 'wbqc-violation-message-parameter-single' ) |
|
102 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
101 | + wfMessage('wbqc-violation-message-parameter-single') |
|
102 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
103 | 103 | ->escaped() |
104 | 104 | ); |
105 | 105 | } |
@@ -112,11 +112,11 @@ discard block |
||
112 | 112 | * @return void |
113 | 113 | * @throws ConstraintParameterException |
114 | 114 | */ |
115 | - private function requireValueParameter( Snak $snak, $parameterId ) { |
|
116 | - if ( !( $snak instanceof PropertyValueSnak ) ) { |
|
115 | + private function requireValueParameter(Snak $snak, $parameterId) { |
|
116 | + if (!($snak instanceof PropertyValueSnak)) { |
|
117 | 117 | throw new ConstraintParameterException( |
118 | - wfMessage( 'wbqc-violation-message-parameter-value' ) |
|
119 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
118 | + wfMessage('wbqc-violation-message-parameter-value') |
|
119 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
120 | 120 | ->escaped() |
121 | 121 | ); |
122 | 122 | } |
@@ -129,18 +129,18 @@ discard block |
||
129 | 129 | * @throws ConstraintParameterException |
130 | 130 | * @return EntityId |
131 | 131 | */ |
132 | - private function parseEntityIdParameter( array $snakSerialization, $parameterId ) { |
|
133 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
134 | - $this->requireValueParameter( $snak, $parameterId ); |
|
132 | + private function parseEntityIdParameter(array $snakSerialization, $parameterId) { |
|
133 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
134 | + $this->requireValueParameter($snak, $parameterId); |
|
135 | 135 | $value = $snak->getDataValue(); |
136 | - if ( $value instanceof EntityIdValue ) { |
|
136 | + if ($value instanceof EntityIdValue) { |
|
137 | 137 | return $value->getEntityId(); |
138 | 138 | } else { |
139 | 139 | throw new ConstraintParameterException( |
140 | - wfMessage( 'wbqc-violation-message-parameter-entity' ) |
|
140 | + wfMessage('wbqc-violation-message-parameter-entity') |
|
141 | 141 | ->rawParams( |
142 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
143 | - $this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
142 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
143 | + $this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
144 | 144 | ) |
145 | 145 | ->escaped() |
146 | 146 | ); |
@@ -153,21 +153,21 @@ discard block |
||
153 | 153 | * @throws ConstraintParameterException if the parameter is invalid or missing |
154 | 154 | * @return string[] class entity ID serializations |
155 | 155 | */ |
156 | - public function parseClassParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
157 | - $this->checkError( $constraintParameters ); |
|
158 | - $classId = $this->config->get( 'WBQualityConstraintsClassId' ); |
|
159 | - if ( !array_key_exists( $classId, $constraintParameters ) ) { |
|
156 | + public function parseClassParameter(array $constraintParameters, $constraintTypeItemId) { |
|
157 | + $this->checkError($constraintParameters); |
|
158 | + $classId = $this->config->get('WBQualityConstraintsClassId'); |
|
159 | + if (!array_key_exists($classId, $constraintParameters)) { |
|
160 | 160 | throw new ConstraintParameterException( |
161 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
162 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
163 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $classId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
161 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
162 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
163 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($classId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
164 | 164 | ->escaped() |
165 | 165 | ); |
166 | 166 | } |
167 | 167 | |
168 | 168 | $classes = []; |
169 | - foreach ( $constraintParameters[$classId] as $class ) { |
|
170 | - $classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization(); |
|
169 | + foreach ($constraintParameters[$classId] as $class) { |
|
170 | + $classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization(); |
|
171 | 171 | } |
172 | 172 | return $classes; |
173 | 173 | } |
@@ -178,24 +178,24 @@ discard block |
||
178 | 178 | * @throws ConstraintParameterException if the parameter is invalid or missing |
179 | 179 | * @return string 'instance', 'subclass', or 'instanceOrSubclass' |
180 | 180 | */ |
181 | - public function parseRelationParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
182 | - $this->checkError( $constraintParameters ); |
|
183 | - $relationId = $this->config->get( 'WBQualityConstraintsRelationId' ); |
|
184 | - if ( !array_key_exists( $relationId, $constraintParameters ) ) { |
|
181 | + public function parseRelationParameter(array $constraintParameters, $constraintTypeItemId) { |
|
182 | + $this->checkError($constraintParameters); |
|
183 | + $relationId = $this->config->get('WBQualityConstraintsRelationId'); |
|
184 | + if (!array_key_exists($relationId, $constraintParameters)) { |
|
185 | 185 | throw new ConstraintParameterException( |
186 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
187 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
188 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $relationId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
186 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
187 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
188 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($relationId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
189 | 189 | ->escaped() |
190 | 190 | ); |
191 | 191 | } |
192 | 192 | |
193 | - $this->requireSingleParameter( $constraintParameters, $relationId ); |
|
194 | - $relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId ); |
|
195 | - $instanceId = $this->config->get( 'WBQualityConstraintsInstanceOfRelationId' ); |
|
196 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfRelationId' ); |
|
197 | - $instanceOrSubclassId = $this->config->get( 'WBQualityConstraintsInstanceOrSubclassOfRelationId' ); |
|
198 | - switch ( $relationEntityId ) { |
|
193 | + $this->requireSingleParameter($constraintParameters, $relationId); |
|
194 | + $relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId); |
|
195 | + $instanceId = $this->config->get('WBQualityConstraintsInstanceOfRelationId'); |
|
196 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfRelationId'); |
|
197 | + $instanceOrSubclassId = $this->config->get('WBQualityConstraintsInstanceOrSubclassOfRelationId'); |
|
198 | + switch ($relationEntityId) { |
|
199 | 199 | case $instanceId: |
200 | 200 | return 'instance'; |
201 | 201 | case $subclassId: |
@@ -204,13 +204,13 @@ discard block |
||
204 | 204 | return 'instanceOrSubclass'; |
205 | 205 | default: |
206 | 206 | throw new ConstraintParameterException( |
207 | - wfMessage( 'wbqc-violation-message-parameter-oneof' ) |
|
208 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $relationId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
209 | - ->numParams( 3 ) |
|
210 | - ->rawParams( $this->constraintParameterRenderer->formatItemIdList( |
|
211 | - [ $instanceId, $subclassId, $instanceOrSubclassId ], |
|
207 | + wfMessage('wbqc-violation-message-parameter-oneof') |
|
208 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($relationId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
209 | + ->numParams(3) |
|
210 | + ->rawParams($this->constraintParameterRenderer->formatItemIdList( |
|
211 | + [$instanceId, $subclassId, $instanceOrSubclassId], |
|
212 | 212 | Role::CONSTRAINT_PARAMETER_VALUE |
213 | - ) ) |
|
213 | + )) |
|
214 | 214 | ->escaped() |
215 | 215 | ); |
216 | 216 | } |
@@ -223,21 +223,21 @@ discard block |
||
223 | 223 | * @throws ConstraintParameterException |
224 | 224 | * @return PropertyId |
225 | 225 | */ |
226 | - private function parsePropertyIdParameter( array $snakSerialization, $parameterId ) { |
|
227 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
228 | - $this->requireValueParameter( $snak, $parameterId ); |
|
226 | + private function parsePropertyIdParameter(array $snakSerialization, $parameterId) { |
|
227 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
228 | + $this->requireValueParameter($snak, $parameterId); |
|
229 | 229 | $value = $snak->getDataValue(); |
230 | - if ( $value instanceof EntityIdValue ) { |
|
230 | + if ($value instanceof EntityIdValue) { |
|
231 | 231 | $id = $value->getEntityId(); |
232 | - if ( $id instanceof PropertyId ) { |
|
232 | + if ($id instanceof PropertyId) { |
|
233 | 233 | return $id; |
234 | 234 | } |
235 | 235 | } |
236 | 236 | throw new ConstraintParameterException( |
237 | - wfMessage( 'wbqc-violation-message-parameter-property' ) |
|
237 | + wfMessage('wbqc-violation-message-parameter-property') |
|
238 | 238 | ->rawParams( |
239 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
240 | - $this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
239 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
240 | + $this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
241 | 241 | ) |
242 | 242 | ->escaped() |
243 | 243 | ); |
@@ -250,34 +250,34 @@ discard block |
||
250 | 250 | * @throws ConstraintParameterException if the parameter is invalid or missing |
251 | 251 | * @return PropertyId |
252 | 252 | */ |
253 | - public function parsePropertyParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
254 | - $this->checkError( $constraintParameters ); |
|
255 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
256 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
253 | + public function parsePropertyParameter(array $constraintParameters, $constraintTypeItemId) { |
|
254 | + $this->checkError($constraintParameters); |
|
255 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
256 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
257 | 257 | throw new ConstraintParameterException( |
258 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
259 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
260 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
258 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
259 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
260 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
261 | 261 | ->escaped() |
262 | 262 | ); |
263 | 263 | } |
264 | 264 | |
265 | - $this->requireSingleParameter( $constraintParameters, $propertyId ); |
|
266 | - return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId ); |
|
265 | + $this->requireSingleParameter($constraintParameters, $propertyId); |
|
266 | + return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId); |
|
267 | 267 | } |
268 | 268 | |
269 | - private function parseItemIdParameter( PropertyValueSnak $snak, $parameterId ) { |
|
269 | + private function parseItemIdParameter(PropertyValueSnak $snak, $parameterId) { |
|
270 | 270 | $dataValue = $snak->getDataValue(); |
271 | - if ( $dataValue instanceof EntityIdValue && |
|
271 | + if ($dataValue instanceof EntityIdValue && |
|
272 | 272 | $dataValue->getEntityId() instanceof ItemId |
273 | 273 | ) { |
274 | - return ItemIdSnakValue::fromItemId( $dataValue->getEntityId() ); |
|
274 | + return ItemIdSnakValue::fromItemId($dataValue->getEntityId()); |
|
275 | 275 | } else { |
276 | 276 | throw new ConstraintParameterException( |
277 | - wfMessage( 'wbqc-violation-message-parameter-item' ) |
|
277 | + wfMessage('wbqc-violation-message-parameter-item') |
|
278 | 278 | ->rawParams( |
279 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
280 | - $this->constraintParameterRenderer->formatDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
279 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
280 | + $this->constraintParameterRenderer->formatDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
281 | 281 | ) |
282 | 282 | ->escaped() |
283 | 283 | ); |
@@ -291,15 +291,15 @@ discard block |
||
291 | 291 | * @throws ConstraintParameterException if the parameter is invalid or missing |
292 | 292 | * @return ItemIdSnakValue[] array of values |
293 | 293 | */ |
294 | - public function parseItemsParameter( array $constraintParameters, $constraintTypeItemId, $required ) { |
|
295 | - $this->checkError( $constraintParameters ); |
|
296 | - $qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
297 | - if ( !array_key_exists( $qualifierId, $constraintParameters ) ) { |
|
298 | - if ( $required ) { |
|
294 | + public function parseItemsParameter(array $constraintParameters, $constraintTypeItemId, $required) { |
|
295 | + $this->checkError($constraintParameters); |
|
296 | + $qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
297 | + if (!array_key_exists($qualifierId, $constraintParameters)) { |
|
298 | + if ($required) { |
|
299 | 299 | throw new ConstraintParameterException( |
300 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
301 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
302 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $qualifierId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
300 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
301 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
302 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($qualifierId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
303 | 303 | ->escaped() |
304 | 304 | ); |
305 | 305 | } else { |
@@ -308,11 +308,11 @@ discard block |
||
308 | 308 | } |
309 | 309 | |
310 | 310 | $values = []; |
311 | - foreach ( $constraintParameters[$qualifierId] as $parameter ) { |
|
312 | - $snak = $this->snakDeserializer->deserialize( $parameter ); |
|
313 | - switch ( true ) { |
|
311 | + foreach ($constraintParameters[$qualifierId] as $parameter) { |
|
312 | + $snak = $this->snakDeserializer->deserialize($parameter); |
|
313 | + switch (true) { |
|
314 | 314 | case $snak instanceof PropertyValueSnak: |
315 | - $values[] = $this->parseItemIdParameter( $snak, $qualifierId ); |
|
315 | + $values[] = $this->parseItemIdParameter($snak, $qualifierId); |
|
316 | 316 | break; |
317 | 317 | case $snak instanceof PropertySomeValueSnak: |
318 | 318 | $values[] = ItemIdSnakValue::someValue(); |
@@ -331,28 +331,28 @@ discard block |
||
331 | 331 | * @throws ConstraintParameterException if the parameter is invalid or missing |
332 | 332 | * @return PropertyId[] |
333 | 333 | */ |
334 | - public function parsePropertiesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
335 | - $this->checkError( $constraintParameters ); |
|
336 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
337 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
334 | + public function parsePropertiesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
335 | + $this->checkError($constraintParameters); |
|
336 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
337 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
338 | 338 | throw new ConstraintParameterException( |
339 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
340 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
341 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
339 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
340 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
341 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
342 | 342 | ->escaped() |
343 | 343 | ); |
344 | 344 | } |
345 | 345 | |
346 | 346 | $parameters = $constraintParameters[$propertyId]; |
347 | - if ( count( $parameters ) === 1 && |
|
348 | - $this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak |
|
347 | + if (count($parameters) === 1 && |
|
348 | + $this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak |
|
349 | 349 | ) { |
350 | 350 | return []; |
351 | 351 | } |
352 | 352 | |
353 | 353 | $properties = []; |
354 | - foreach ( $parameters as $parameter ) { |
|
355 | - $properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId ); |
|
354 | + foreach ($parameters as $parameter) { |
|
355 | + $properties[] = $this->parsePropertyIdParameter($parameter, $propertyId); |
|
356 | 356 | } |
357 | 357 | return $properties; |
358 | 358 | } |
@@ -363,16 +363,16 @@ discard block |
||
363 | 363 | * @throws ConstraintParameterException |
364 | 364 | * @return DataValue|null |
365 | 365 | */ |
366 | - private function parseValueOrNoValueParameter( array $snakSerialization, $parameterId ) { |
|
367 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
368 | - if ( $snak instanceof PropertyValueSnak ) { |
|
366 | + private function parseValueOrNoValueParameter(array $snakSerialization, $parameterId) { |
|
367 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
368 | + if ($snak instanceof PropertyValueSnak) { |
|
369 | 369 | return $snak->getDataValue(); |
370 | - } elseif ( $snak instanceof PropertyNoValueSnak ) { |
|
370 | + } elseif ($snak instanceof PropertyNoValueSnak) { |
|
371 | 371 | return null; |
372 | 372 | } else { |
373 | 373 | throw new ConstraintParameterException( |
374 | - wfMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) |
|
375 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
374 | + wfMessage('wbqc-violation-message-parameter-value-or-novalue') |
|
375 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
376 | 376 | ->escaped() |
377 | 377 | ); |
378 | 378 | } |
@@ -383,13 +383,13 @@ discard block |
||
383 | 383 | * @param string $parameterId |
384 | 384 | * @return DataValue|null |
385 | 385 | */ |
386 | - private function parseValueOrNoValueOrNowParameter( array $snakSerialization, $parameterId ) { |
|
386 | + private function parseValueOrNoValueOrNowParameter(array $snakSerialization, $parameterId) { |
|
387 | 387 | try { |
388 | - return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId ); |
|
389 | - } catch ( ConstraintParameterException $e ) { |
|
388 | + return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId); |
|
389 | + } catch (ConstraintParameterException $e) { |
|
390 | 390 | // unknown value means “now” |
391 | - $timeParser = ( new TimeParserFactory() )->getTimeParser(); |
|
392 | - return $timeParser->parse( gmdate( '+Y-m-d\T00:00:00\Z' ) ); |
|
391 | + $timeParser = (new TimeParserFactory())->getTimeParser(); |
|
392 | + return $timeParser->parse(gmdate('+Y-m-d\T00:00:00\Z')); |
|
393 | 393 | } |
394 | 394 | } |
395 | 395 | |
@@ -400,14 +400,14 @@ discard block |
||
400 | 400 | * @param string $unit |
401 | 401 | * @return bool |
402 | 402 | */ |
403 | - private function exactlyOneQuantityWithUnit( DataValue $min = null, DataValue $max = null, $unit ) { |
|
404 | - if ( !( $min instanceof UnboundedQuantityValue ) || |
|
405 | - !( $max instanceof UnboundedQuantityValue ) |
|
403 | + private function exactlyOneQuantityWithUnit(DataValue $min = null, DataValue $max = null, $unit) { |
|
404 | + if (!($min instanceof UnboundedQuantityValue) || |
|
405 | + !($max instanceof UnboundedQuantityValue) |
|
406 | 406 | ) { |
407 | 407 | return false; |
408 | 408 | } |
409 | 409 | |
410 | - return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit ); |
|
410 | + return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit); |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | /** |
@@ -418,9 +418,9 @@ discard block |
||
418 | 418 | * @throws ConstraintParameterException if the parameter is invalid or missing |
419 | 419 | * @return DataValue[] a pair of two quantity-type data values, either of which may be null to signify an open range |
420 | 420 | */ |
421 | - public function parseRangeParameter( array $constraintParameters, $constraintTypeItemId, $type ) { |
|
422 | - $this->checkError( $constraintParameters ); |
|
423 | - switch ( $type ) { |
|
421 | + public function parseRangeParameter(array $constraintParameters, $constraintTypeItemId, $type) { |
|
422 | + $this->checkError($constraintParameters); |
|
423 | + switch ($type) { |
|
424 | 424 | case 'quantity': |
425 | 425 | $configKey = 'Quantity'; |
426 | 426 | break; |
@@ -429,47 +429,47 @@ discard block |
||
429 | 429 | break; |
430 | 430 | default: |
431 | 431 | throw new ConstraintParameterException( |
432 | - wfMessage( 'wbqc-violation-message-value-needed-of-types-2' ) |
|
432 | + wfMessage('wbqc-violation-message-value-needed-of-types-2') |
|
433 | 433 | ->rawParams( |
434 | - $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ), |
|
435 | - wfMessage( 'datatypes-type-quantity' )->escaped(), |
|
436 | - wfMessage( 'datatypes-type-time' )->escaped() |
|
434 | + $this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM), |
|
435 | + wfMessage('datatypes-type-quantity')->escaped(), |
|
436 | + wfMessage('datatypes-type-time')->escaped() |
|
437 | 437 | ) |
438 | 438 | ->escaped() |
439 | 439 | ); |
440 | 440 | } |
441 | - $minimumId = $this->config->get( 'WBQualityConstraintsMinimum' . $configKey . 'Id' ); |
|
442 | - $maximumId = $this->config->get( 'WBQualityConstraintsMaximum' . $configKey . 'Id' ); |
|
443 | - if ( !array_key_exists( $minimumId, $constraintParameters ) || |
|
444 | - !array_key_exists( $maximumId, $constraintParameters ) |
|
441 | + $minimumId = $this->config->get('WBQualityConstraintsMinimum'.$configKey.'Id'); |
|
442 | + $maximumId = $this->config->get('WBQualityConstraintsMaximum'.$configKey.'Id'); |
|
443 | + if (!array_key_exists($minimumId, $constraintParameters) || |
|
444 | + !array_key_exists($maximumId, $constraintParameters) |
|
445 | 445 | ) { |
446 | 446 | throw new ConstraintParameterException( |
447 | - wfMessage( 'wbqc-violation-message-range-parameters-needed' ) |
|
447 | + wfMessage('wbqc-violation-message-range-parameters-needed') |
|
448 | 448 | ->rawParams( |
449 | - wfMessage( 'datatypes-type-' . $type )->escaped(), |
|
450 | - $this->constraintParameterRenderer->formatPropertyId( $minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
451 | - $this->constraintParameterRenderer->formatPropertyId( $maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
449 | + wfMessage('datatypes-type-'.$type)->escaped(), |
|
450 | + $this->constraintParameterRenderer->formatPropertyId($minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
451 | + $this->constraintParameterRenderer->formatPropertyId($maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
452 | 452 | ) |
453 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
453 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
454 | 454 | ->escaped() |
455 | 455 | ); |
456 | 456 | } |
457 | 457 | |
458 | - $this->requireSingleParameter( $constraintParameters, $minimumId ); |
|
459 | - $this->requireSingleParameter( $constraintParameters, $maximumId ); |
|
458 | + $this->requireSingleParameter($constraintParameters, $minimumId); |
|
459 | + $this->requireSingleParameter($constraintParameters, $maximumId); |
|
460 | 460 | $parseFunction = $configKey === 'Date' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter'; |
461 | - $min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId ); |
|
462 | - $max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId ); |
|
461 | + $min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId); |
|
462 | + $max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId); |
|
463 | 463 | |
464 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
465 | - if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) { |
|
464 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
465 | + if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) { |
|
466 | 466 | throw new ConstraintParameterException( |
467 | - wfMessage( 'wbqc-violation-message-range-parameters-one-year' ) |
|
467 | + wfMessage('wbqc-violation-message-range-parameters-one-year') |
|
468 | 468 | ->escaped() |
469 | 469 | ); |
470 | 470 | } |
471 | 471 | |
472 | - return [ $min, $max ]; |
|
472 | + return [$min, $max]; |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | /** |
@@ -479,18 +479,18 @@ discard block |
||
479 | 479 | * @throws ConstraintParameterException |
480 | 480 | * @return string |
481 | 481 | */ |
482 | - private function parseStringParameter( array $snakSerialization, $parameterId ) { |
|
483 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
484 | - $this->requireValueParameter( $snak, $parameterId ); |
|
482 | + private function parseStringParameter(array $snakSerialization, $parameterId) { |
|
483 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
484 | + $this->requireValueParameter($snak, $parameterId); |
|
485 | 485 | $value = $snak->getDataValue(); |
486 | - if ( $value instanceof StringValue ) { |
|
486 | + if ($value instanceof StringValue) { |
|
487 | 487 | return $value->getValue(); |
488 | 488 | } else { |
489 | 489 | throw new ConstraintParameterException( |
490 | - wfMessage( 'wbqc-violation-message-parameter-string' ) |
|
490 | + wfMessage('wbqc-violation-message-parameter-string') |
|
491 | 491 | ->rawParams( |
492 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
493 | - $this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
492 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
493 | + $this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
494 | 494 | ) |
495 | 495 | ->escaped() |
496 | 496 | ); |
@@ -503,15 +503,15 @@ discard block |
||
503 | 503 | * @throws ConstraintParameterException if the parameter is invalid or missing |
504 | 504 | * @return string |
505 | 505 | */ |
506 | - public function parseNamespaceParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
507 | - $this->checkError( $constraintParameters ); |
|
508 | - $namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' ); |
|
509 | - if ( !array_key_exists( $namespaceId, $constraintParameters ) ) { |
|
506 | + public function parseNamespaceParameter(array $constraintParameters, $constraintTypeItemId) { |
|
507 | + $this->checkError($constraintParameters); |
|
508 | + $namespaceId = $this->config->get('WBQualityConstraintsNamespaceId'); |
|
509 | + if (!array_key_exists($namespaceId, $constraintParameters)) { |
|
510 | 510 | return ''; |
511 | 511 | } |
512 | 512 | |
513 | - $this->requireSingleParameter( $constraintParameters, $namespaceId ); |
|
514 | - return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId ); |
|
513 | + $this->requireSingleParameter($constraintParameters, $namespaceId); |
|
514 | + return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId); |
|
515 | 515 | } |
516 | 516 | |
517 | 517 | /** |
@@ -520,20 +520,20 @@ discard block |
||
520 | 520 | * @throws ConstraintParameterException if the parameter is invalid or missing |
521 | 521 | * @return string |
522 | 522 | */ |
523 | - public function parseFormatParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
524 | - $this->checkError( $constraintParameters ); |
|
525 | - $formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' ); |
|
526 | - if ( !array_key_exists( $formatId, $constraintParameters ) ) { |
|
523 | + public function parseFormatParameter(array $constraintParameters, $constraintTypeItemId) { |
|
524 | + $this->checkError($constraintParameters); |
|
525 | + $formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId'); |
|
526 | + if (!array_key_exists($formatId, $constraintParameters)) { |
|
527 | 527 | throw new ConstraintParameterException( |
528 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
529 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
530 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $formatId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
528 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
529 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
530 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($formatId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
531 | 531 | ->escaped() |
532 | 532 | ); |
533 | 533 | } |
534 | 534 | |
535 | - $this->requireSingleParameter( $constraintParameters, $formatId ); |
|
536 | - return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId ); |
|
535 | + $this->requireSingleParameter($constraintParameters, $formatId); |
|
536 | + return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId); |
|
537 | 537 | } |
538 | 538 | |
539 | 539 | /** |
@@ -541,16 +541,16 @@ discard block |
||
541 | 541 | * @throws ConstraintParameterException if the parameter is invalid |
542 | 542 | * @return EntityId[] |
543 | 543 | */ |
544 | - public function parseExceptionParameter( array $constraintParameters ) { |
|
545 | - $this->checkError( $constraintParameters ); |
|
546 | - $exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' ); |
|
547 | - if ( !array_key_exists( $exceptionId, $constraintParameters ) ) { |
|
544 | + public function parseExceptionParameter(array $constraintParameters) { |
|
545 | + $this->checkError($constraintParameters); |
|
546 | + $exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId'); |
|
547 | + if (!array_key_exists($exceptionId, $constraintParameters)) { |
|
548 | 548 | return []; |
549 | 549 | } |
550 | 550 | |
551 | 551 | return array_map( |
552 | - function( $snakSerialization ) use ( $exceptionId ) { |
|
553 | - return $this->parseEntityIdParameter( $snakSerialization, $exceptionId ); |
|
552 | + function($snakSerialization) use ($exceptionId) { |
|
553 | + return $this->parseEntityIdParameter($snakSerialization, $exceptionId); |
|
554 | 554 | }, |
555 | 555 | $constraintParameters[$exceptionId] |
556 | 556 | ); |
@@ -561,27 +561,27 @@ discard block |
||
561 | 561 | * @throws ConstraintParameterException if the parameter is invalid |
562 | 562 | * @return string|null 'mandatory' or null |
563 | 563 | */ |
564 | - public function parseConstraintStatusParameter( array $constraintParameters ) { |
|
565 | - $this->checkError( $constraintParameters ); |
|
566 | - $constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' ); |
|
567 | - if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) { |
|
564 | + public function parseConstraintStatusParameter(array $constraintParameters) { |
|
565 | + $this->checkError($constraintParameters); |
|
566 | + $constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId'); |
|
567 | + if (!array_key_exists($constraintStatusId, $constraintParameters)) { |
|
568 | 568 | return null; |
569 | 569 | } |
570 | 570 | |
571 | - $mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' ); |
|
572 | - $this->requireSingleParameter( $constraintParameters, $constraintStatusId ); |
|
573 | - $snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] ); |
|
574 | - $this->requireValueParameter( $snak, $constraintStatusId ); |
|
571 | + $mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId'); |
|
572 | + $this->requireSingleParameter($constraintParameters, $constraintStatusId); |
|
573 | + $snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]); |
|
574 | + $this->requireValueParameter($snak, $constraintStatusId); |
|
575 | 575 | $statusId = $snak->getDataValue()->getEntityId()->getSerialization(); |
576 | 576 | |
577 | - if ( $statusId === $mandatoryId ) { |
|
577 | + if ($statusId === $mandatoryId) { |
|
578 | 578 | return 'mandatory'; |
579 | 579 | } else { |
580 | 580 | throw new ConstraintParameterException( |
581 | - wfMessage( 'wbqc-violation-message-parameter-oneof' ) |
|
582 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $constraintStatusId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
583 | - ->numParams( 1 ) |
|
584 | - ->rawParams( $this->constraintParameterRenderer->formatItemIdList( [ $mandatoryId ], Role::CONSTRAINT_PARAMETER_VALUE ) ) |
|
581 | + wfMessage('wbqc-violation-message-parameter-oneof') |
|
582 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($constraintStatusId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
583 | + ->numParams(1) |
|
584 | + ->rawParams($this->constraintParameterRenderer->formatItemIdList([$mandatoryId], Role::CONSTRAINT_PARAMETER_VALUE)) |
|
585 | 585 | ->escaped() |
586 | 586 | ); |
587 | 587 | } |
@@ -594,13 +594,13 @@ discard block |
||
594 | 594 | * @return void |
595 | 595 | * @throws ConstraintParameterException |
596 | 596 | */ |
597 | - private function requireMonolingualTextParameter( DataValue $dataValue, $parameterId ) { |
|
598 | - if ( !( $dataValue instanceof MonolingualTextValue ) ) { |
|
597 | + private function requireMonolingualTextParameter(DataValue $dataValue, $parameterId) { |
|
598 | + if (!($dataValue instanceof MonolingualTextValue)) { |
|
599 | 599 | throw new ConstraintParameterException( |
600 | - wfMessage( 'wbqc-violation-message-parameter-monolingualtext' ) |
|
600 | + wfMessage('wbqc-violation-message-parameter-monolingualtext') |
|
601 | 601 | ->rawParams( |
602 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
603 | - $this->constraintParameterRenderer->formatDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
602 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
603 | + $this->constraintParameterRenderer->formatDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
604 | 604 | ) |
605 | 605 | ->escaped() |
606 | 606 | ); |
@@ -615,26 +615,26 @@ discard block |
||
615 | 615 | * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts |
616 | 616 | * @return string[] |
617 | 617 | */ |
618 | - private function parseMultilingualTextParameter( array $snakSerializations, $parameterId ) { |
|
618 | + private function parseMultilingualTextParameter(array $snakSerializations, $parameterId) { |
|
619 | 619 | $result = []; |
620 | 620 | |
621 | - foreach ( $snakSerializations as $snakSerialization ) { |
|
622 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
623 | - $this->requireValueParameter( $snak, $parameterId ); |
|
621 | + foreach ($snakSerializations as $snakSerialization) { |
|
622 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
623 | + $this->requireValueParameter($snak, $parameterId); |
|
624 | 624 | |
625 | 625 | $value = $snak->getDataValue(); |
626 | - $this->requireMonolingualTextParameter( $value, $parameterId ); |
|
626 | + $this->requireMonolingualTextParameter($value, $parameterId); |
|
627 | 627 | /** @var MonolingualTextValue $value */ |
628 | 628 | |
629 | 629 | $code = $value->getLanguageCode(); |
630 | - if ( array_key_exists( $code, $result ) ) { |
|
630 | + if (array_key_exists($code, $result)) { |
|
631 | 631 | throw new ConstraintParameterException( |
632 | - wfMessage( 'wbqc-violation-message-parameter-single-per-language' ) |
|
632 | + wfMessage('wbqc-violation-message-parameter-single-per-language') |
|
633 | 633 | ->rawParams( |
634 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
634 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
635 | 635 | ) |
636 | 636 | ->plaintextParams( |
637 | - Language::fetchLanguageName( $code ), |
|
637 | + Language::fetchLanguageName($code), |
|
638 | 638 | $code |
639 | 639 | ) |
640 | 640 | ->escaped() |
@@ -653,23 +653,23 @@ discard block |
||
653 | 653 | * @throws ConstraintParameterException if the parameter is invalid |
654 | 654 | * @return string|null |
655 | 655 | */ |
656 | - public function parseSyntaxClarificationParameter( array $constraintParameters, Language $language ) { |
|
657 | - $syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' ); |
|
656 | + public function parseSyntaxClarificationParameter(array $constraintParameters, Language $language) { |
|
657 | + $syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId'); |
|
658 | 658 | |
659 | - if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) { |
|
659 | + if (!array_key_exists($syntaxClarificationId, $constraintParameters)) { |
|
660 | 660 | return null; |
661 | 661 | } |
662 | 662 | |
663 | 663 | $languageCodes = $language->getFallbackLanguages(); |
664 | - array_unshift( $languageCodes, $language->getCode() ); |
|
664 | + array_unshift($languageCodes, $language->getCode()); |
|
665 | 665 | |
666 | 666 | $syntaxClarifications = $this->parseMultilingualTextParameter( |
667 | 667 | $constraintParameters[$syntaxClarificationId], |
668 | 668 | $syntaxClarificationId |
669 | 669 | ); |
670 | 670 | |
671 | - foreach ( $languageCodes as $languageCode ) { |
|
672 | - if ( array_key_exists( $languageCode, $syntaxClarifications ) ) { |
|
671 | + foreach ($languageCodes as $languageCode) { |
|
672 | + if (array_key_exists($languageCode, $syntaxClarifications)) { |
|
673 | 673 | return $syntaxClarifications[$languageCode]; |
674 | 674 | } |
675 | 675 | } |
@@ -685,20 +685,20 @@ discard block |
||
685 | 685 | * @throws ConstraintParameterException if the parameter is invalid |
686 | 686 | * @return string[]|null Context::TYPE_* constants |
687 | 687 | */ |
688 | - public function parseConstraintScopeParameter( array $constraintParameters, $constraintTypeItemId, array $validScopes = null ) { |
|
689 | - $constraintScopeId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' ); |
|
690 | - $mainSnakId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' ); |
|
691 | - $qualifiersId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' ); |
|
692 | - $referencesId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' ); |
|
688 | + public function parseConstraintScopeParameter(array $constraintParameters, $constraintTypeItemId, array $validScopes = null) { |
|
689 | + $constraintScopeId = $this->config->get('WBQualityConstraintsConstraintScopeId'); |
|
690 | + $mainSnakId = $this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId'); |
|
691 | + $qualifiersId = $this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId'); |
|
692 | + $referencesId = $this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId'); |
|
693 | 693 | |
694 | - if ( !array_key_exists( $constraintScopeId, $constraintParameters ) ) { |
|
694 | + if (!array_key_exists($constraintScopeId, $constraintParameters)) { |
|
695 | 695 | return null; |
696 | 696 | } |
697 | 697 | |
698 | 698 | $contextTypes = []; |
699 | - foreach ( $constraintParameters[$constraintScopeId] as $snakSerialization ) { |
|
700 | - $scopeEntityId = $this->parseEntityIdParameter( $snakSerialization, $constraintScopeId ); |
|
701 | - switch ( $scopeEntityId->getSerialization() ) { |
|
699 | + foreach ($constraintParameters[$constraintScopeId] as $snakSerialization) { |
|
700 | + $scopeEntityId = $this->parseEntityIdParameter($snakSerialization, $constraintScopeId); |
|
701 | + switch ($scopeEntityId->getSerialization()) { |
|
702 | 702 | case $mainSnakId: |
703 | 703 | $contextTypes[] = Context::TYPE_STATEMENT; |
704 | 704 | break; |
@@ -710,14 +710,14 @@ discard block |
||
710 | 710 | break; |
711 | 711 | default: |
712 | 712 | throw new ConstraintParameterException( |
713 | - wfMessage( 'wbqc-violation-message-parameter-oneof' ) |
|
713 | + wfMessage('wbqc-violation-message-parameter-oneof') |
|
714 | 714 | ->rawParams( |
715 | 715 | $this->constraintParameterRenderer->formatPropertyId( |
716 | 716 | $constraintScopeId, |
717 | 717 | Role::CONSTRAINT_PARAMETER_PROPERTY |
718 | 718 | ) |
719 | 719 | ) |
720 | - ->numParams( 3 ) |
|
720 | + ->numParams(3) |
|
721 | 721 | ->rawParams( |
722 | 722 | $this->constraintParameterRenderer->formatItemIdList( |
723 | 723 | [ |
@@ -733,12 +733,12 @@ discard block |
||
733 | 733 | } |
734 | 734 | } |
735 | 735 | |
736 | - if ( $validScopes !== null ) { |
|
737 | - $invalidScopes = array_diff( $contextTypes, $validScopes ); |
|
738 | - if ( $invalidScopes !== [] ) { |
|
739 | - $invalidScope = array_pop( $invalidScopes ); |
|
736 | + if ($validScopes !== null) { |
|
737 | + $invalidScopes = array_diff($contextTypes, $validScopes); |
|
738 | + if ($invalidScopes !== []) { |
|
739 | + $invalidScope = array_pop($invalidScopes); |
|
740 | 740 | throw new ConstraintParameterException( |
741 | - wfMessage( 'wbqc-violation-message-invalid-scope' ) |
|
741 | + wfMessage('wbqc-violation-message-invalid-scope') |
|
742 | 742 | ->rawParams( |
743 | 743 | $this->constraintParameterRenderer->formatConstraintScope( |
744 | 744 | $invalidScope, |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | Role::CONSTRAINT_TYPE_ITEM |
750 | 750 | ) |
751 | 751 | ) |
752 | - ->numParams( count( $validScopes ) ) |
|
752 | + ->numParams(count($validScopes)) |
|
753 | 753 | ->rawParams( |
754 | 754 | $this->constraintParameterRenderer->formatConstraintScopeList( |
755 | 755 | $validScopes, |
@@ -77,21 +77,21 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @return self |
79 | 79 | */ |
80 | - public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) { |
|
80 | + public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') { |
|
81 | 81 | $repo = WikibaseRepo::getDefaultInstance(); |
82 | 82 | |
83 | 83 | $language = $repo->getUserLanguage(); |
84 | 84 | $formatterOptions = new FormatterOptions(); |
85 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
85 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
86 | 86 | $valueFormatterFactory = $repo->getValueFormatterFactory(); |
87 | - $valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
87 | + $valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions); |
|
88 | 88 | |
89 | 89 | $languageFallbackLabelDescriptionLookupFactory = $repo->getLanguageFallbackLabelDescriptionLookupFactory(); |
90 | - $labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup( $language ); |
|
90 | + $labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup($language); |
|
91 | 91 | $entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory(); |
92 | - $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup ); |
|
92 | + $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($labelDescriptionLookup); |
|
93 | 93 | $entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory(); |
94 | - $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup ); |
|
94 | + $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($labelDescriptionLookup); |
|
95 | 95 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
96 | 96 | $titleParser = MediaWikiServices::getInstance()->getTitleParser(); |
97 | 97 | $unitConverter = $repo->getUnitConverter(); |
@@ -124,10 +124,10 @@ discard block |
||
124 | 124 | $repo->getEntityTitleLookup(), |
125 | 125 | $entityIdLabelFormatter, |
126 | 126 | $constraintParameterRenderer, |
127 | - new ViolationMessageRenderer( $entityIdHtmlLinkFormatter ), |
|
127 | + new ViolationMessageRenderer($entityIdHtmlLinkFormatter), |
|
128 | 128 | $config |
129 | 129 | ); |
130 | - if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) { |
|
130 | + if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) { |
|
131 | 131 | $wikiPageEntityMetaDataAccessor = new WikiPageEntityMetaDataLookup( |
132 | 132 | $repo->getEntityNamespaceLookup() |
133 | 133 | ); |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | ResultsCache::getDefaultInstance(), |
139 | 139 | $wikiPageEntityMetaDataAccessor, |
140 | 140 | $entityIdParser, |
141 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ), |
|
141 | + $config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'), |
|
142 | 142 | [ |
143 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ), |
|
144 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ), |
|
145 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ), |
|
146 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ), |
|
143 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId'), |
|
144 | + $config->get('WBQualityConstraintsTypeConstraintId'), |
|
145 | + $config->get('WBQualityConstraintsValueTypeConstraintId'), |
|
146 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId'), |
|
147 | 147 | ], |
148 | 148 | $dataFactory |
149 | 149 | ); |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $prefix, |
156 | 156 | $repo->getEntityIdParser(), |
157 | 157 | $repo->getStatementGuidValidator(), |
158 | - $repo->getApiHelperFactory( RequestContext::getMain() ), |
|
158 | + $repo->getApiHelperFactory(RequestContext::getMain()), |
|
159 | 159 | $resultsBuilder, |
160 | 160 | $dataFactory |
161 | 161 | ); |
@@ -181,11 +181,11 @@ discard block |
||
181 | 181 | ResultsBuilder $resultsBuilder, |
182 | 182 | IBufferingStatsdDataFactory $dataFactory |
183 | 183 | ) { |
184 | - parent::__construct( $main, $name, $prefix ); |
|
184 | + parent::__construct($main, $name, $prefix); |
|
185 | 185 | $this->entityIdParser = $entityIdParser; |
186 | 186 | $this->statementGuidValidator = $statementGuidValidator; |
187 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
188 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
187 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
188 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
189 | 189 | $this->resultsBuilder = $resultsBuilder; |
190 | 190 | $this->dataFactory = $dataFactory; |
191 | 191 | } |
@@ -200,9 +200,9 @@ discard block |
||
200 | 200 | |
201 | 201 | $params = $this->extractRequestParams(); |
202 | 202 | |
203 | - $this->validateParameters( $params ); |
|
204 | - $entityIds = $this->parseEntityIds( $params ); |
|
205 | - $claimIds = $this->parseClaimIds( $params ); |
|
203 | + $this->validateParameters($params); |
|
204 | + $entityIds = $this->parseEntityIds($params); |
|
205 | + $claimIds = $this->parseClaimIds($params); |
|
206 | 206 | $constraintIDs = $params[self::PARAM_CONSTRAINT_ID]; |
207 | 207 | $statuses = $params[self::PARAM_STATUS]; |
208 | 208 | |
@@ -217,13 +217,13 @@ discard block |
||
217 | 217 | )->getArray() |
218 | 218 | ); |
219 | 219 | // ensure that result contains the given entity IDs even if they have no statements |
220 | - foreach ( $entityIds as $entityId ) { |
|
220 | + foreach ($entityIds as $entityId) { |
|
221 | 221 | $this->getResult()->addArrayType( |
222 | - [ $this->getModuleName(), $entityId->getSerialization() ], |
|
222 | + [$this->getModuleName(), $entityId->getSerialization()], |
|
223 | 223 | 'assoc' |
224 | 224 | ); |
225 | 225 | } |
226 | - $this->resultBuilder->markSuccess( 1 ); |
|
226 | + $this->resultBuilder->markSuccess(1); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -231,24 +231,24 @@ discard block |
||
231 | 231 | * |
232 | 232 | * @return EntityId[] |
233 | 233 | */ |
234 | - private function parseEntityIds( array $params ) { |
|
234 | + private function parseEntityIds(array $params) { |
|
235 | 235 | $ids = $params[self::PARAM_ID]; |
236 | 236 | |
237 | - if ( $ids === null ) { |
|
237 | + if ($ids === null) { |
|
238 | 238 | return []; |
239 | - } elseif ( $ids === [] ) { |
|
239 | + } elseif ($ids === []) { |
|
240 | 240 | $this->errorReporter->dieError( |
241 | - 'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
241 | + 'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
242 | 242 | } |
243 | 243 | |
244 | - return array_map( function ( $id ) { |
|
244 | + return array_map(function($id) { |
|
245 | 245 | try { |
246 | - return $this->entityIdParser->parse( $id ); |
|
247 | - } catch ( EntityIdParsingException $e ) { |
|
246 | + return $this->entityIdParser->parse($id); |
|
247 | + } catch (EntityIdParsingException $e) { |
|
248 | 248 | $this->errorReporter->dieError( |
249 | - "Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] ); |
|
249 | + "Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] ); |
|
250 | 250 | } |
251 | - }, $ids ); |
|
251 | + }, $ids); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
@@ -256,35 +256,35 @@ discard block |
||
256 | 256 | * |
257 | 257 | * @return string[] |
258 | 258 | */ |
259 | - private function parseClaimIds( array $params ) { |
|
259 | + private function parseClaimIds(array $params) { |
|
260 | 260 | $ids = $params[self::PARAM_CLAIM_ID]; |
261 | 261 | |
262 | - if ( $ids === null ) { |
|
262 | + if ($ids === null) { |
|
263 | 263 | return []; |
264 | - } elseif ( $ids === [] ) { |
|
264 | + } elseif ($ids === []) { |
|
265 | 265 | $this->errorReporter->dieError( |
266 | - 'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
266 | + 'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
267 | 267 | } |
268 | 268 | |
269 | - foreach ( $ids as $id ) { |
|
270 | - if ( !$this->statementGuidValidator->validate( $id ) ) { |
|
269 | + foreach ($ids as $id) { |
|
270 | + if (!$this->statementGuidValidator->validate($id)) { |
|
271 | 271 | $this->errorReporter->dieError( |
272 | - "Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] ); |
|
272 | + "Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] ); |
|
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
276 | 276 | return $ids; |
277 | 277 | } |
278 | 278 | |
279 | - private function validateParameters( array $params ) { |
|
280 | - if ( $params[self::PARAM_CONSTRAINT_ID] !== null |
|
281 | - && empty( $params[self::PARAM_CONSTRAINT_ID] ) |
|
279 | + private function validateParameters(array $params) { |
|
280 | + if ($params[self::PARAM_CONSTRAINT_ID] !== null |
|
281 | + && empty($params[self::PARAM_CONSTRAINT_ID]) |
|
282 | 282 | ) { |
283 | 283 | $paramConstraintId = self::PARAM_CONSTRAINT_ID; |
284 | 284 | $this->errorReporter->dieError( |
285 | 285 | "If $paramConstraintId is specified, it must be nonempty.", 'no-data' ); |
286 | 286 | } |
287 | - if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) { |
|
287 | + if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) { |
|
288 | 288 | $paramId = self::PARAM_ID; |
289 | 289 | $paramClaimId = self::PARAM_CLAIM_ID; |
290 | 290 | $this->errorReporter->dieError( |
@@ -90,22 +90,22 @@ discard block |
||
90 | 90 | * @throws ConstraintParameterException |
91 | 91 | * @return CheckResult |
92 | 92 | */ |
93 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
94 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
95 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
93 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
94 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
95 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | $parameters = []; |
99 | 99 | $constraintParameters = $constraint->getConstraintParameters(); |
100 | 100 | |
101 | - $propertyId = $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
102 | - $parameters['property'] = [ $propertyId ]; |
|
101 | + $propertyId = $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
102 | + $parameters['property'] = [$propertyId]; |
|
103 | 103 | |
104 | 104 | $snak = $context->getSnak(); |
105 | 105 | |
106 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
106 | + if (!$snak instanceof PropertyValueSnak) { |
|
107 | 107 | // nothing to check |
108 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
108 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | $dataValue = $snak->getDataValue(); |
@@ -114,22 +114,22 @@ discard block |
||
114 | 114 | * error handling: |
115 | 115 | * type of $dataValue for properties with 'Inverse' constraint has to be 'wikibase-entityid' |
116 | 116 | */ |
117 | - if ( $dataValue->getType() !== 'wikibase-entityid' ) { |
|
118 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
117 | + if ($dataValue->getType() !== 'wikibase-entityid') { |
|
118 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
119 | 119 | ->rawParams( |
120 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
120 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
121 | 121 | 'wikibase-entityid' // TODO is there a message for this type so we can localize it? |
122 | 122 | ) |
123 | 123 | ->escaped(); |
124 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
124 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
125 | 125 | } |
126 | 126 | /** @var EntityIdValue $dataValue */ |
127 | 127 | |
128 | 128 | $targetEntityId = $dataValue->getEntityId(); |
129 | - $targetEntity = $this->entityLookup->getEntity( $targetEntityId ); |
|
130 | - if ( $targetEntity === null ) { |
|
131 | - $message = new ViolationMessage( 'wbqc-violation-message-target-entity-must-exist' ); |
|
132 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
129 | + $targetEntity = $this->entityLookup->getEntity($targetEntityId); |
|
130 | + if ($targetEntity === null) { |
|
131 | + $message = new ViolationMessage('wbqc-violation-message-target-entity-must-exist'); |
|
132 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | $inverseStatement = $this->connectionCheckerHelper->findStatementWithPropertyAndEntityIdValue( |
@@ -137,28 +137,28 @@ discard block |
||
137 | 137 | $propertyId, |
138 | 138 | $context->getEntity()->getId() |
139 | 139 | ); |
140 | - if ( $inverseStatement !== null ) { |
|
140 | + if ($inverseStatement !== null) { |
|
141 | 141 | $message = null; |
142 | 142 | $status = CheckResult::STATUS_COMPLIANCE; |
143 | 143 | } else { |
144 | - $message = ( new ViolationMessage( 'wbqc-violation-message-inverse' ) ) |
|
145 | - ->withEntityId( $targetEntityId, Role::SUBJECT ) |
|
146 | - ->withEntityId( $propertyId, Role::PREDICATE ) |
|
147 | - ->withEntityId( $context->getEntity()->getId(), Role::OBJECT ); |
|
144 | + $message = (new ViolationMessage('wbqc-violation-message-inverse')) |
|
145 | + ->withEntityId($targetEntityId, Role::SUBJECT) |
|
146 | + ->withEntityId($propertyId, Role::PREDICATE) |
|
147 | + ->withEntityId($context->getEntity()->getId(), Role::OBJECT); |
|
148 | 148 | $status = CheckResult::STATUS_VIOLATION; |
149 | 149 | } |
150 | 150 | |
151 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
152 | - ->withMetadata( Metadata::ofDependencyMetadata( |
|
153 | - DependencyMetadata::ofEntityId( $targetEntityId ) ) ); |
|
151 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
152 | + ->withMetadata(Metadata::ofDependencyMetadata( |
|
153 | + DependencyMetadata::ofEntityId($targetEntityId) )); |
|
154 | 154 | } |
155 | 155 | |
156 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
156 | + public function checkConstraintParameters(Constraint $constraint) { |
|
157 | 157 | $constraintParameters = $constraint->getConstraintParameters(); |
158 | 158 | $exceptions = []; |
159 | 159 | try { |
160 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
161 | - } catch ( ConstraintParameterException $e ) { |
|
160 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
161 | + } catch (ConstraintParameterException $e) { |
|
162 | 162 | $exceptions[] = $e; |
163 | 163 | } |
164 | 164 | return $exceptions; |
@@ -71,40 +71,40 @@ |
||
71 | 71 | * @throws ConstraintParameterException |
72 | 72 | * @return CheckResult |
73 | 73 | */ |
74 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
75 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
76 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
74 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
75 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
76 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | $parameters = []; |
80 | 80 | $constraintParameters = $constraint->getConstraintParameters(); |
81 | 81 | |
82 | - $propertyId = $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
83 | - $parameters['property'] = [ $propertyId ]; |
|
82 | + $propertyId = $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
83 | + $parameters['property'] = [$propertyId]; |
|
84 | 84 | |
85 | - $message = ( new ViolationMessage( 'wbqc-violation-message-mandatory-qualifier' ) ) |
|
86 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
87 | - ->withEntityId( $propertyId, Role::QUALIFIER_PREDICATE ); |
|
85 | + $message = (new ViolationMessage('wbqc-violation-message-mandatory-qualifier')) |
|
86 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
87 | + ->withEntityId($propertyId, Role::QUALIFIER_PREDICATE); |
|
88 | 88 | $status = CheckResult::STATUS_VIOLATION; |
89 | 89 | |
90 | 90 | /** @var Snak $qualifier */ |
91 | - foreach ( $context->getSnakStatement()->getQualifiers() as $qualifier ) { |
|
92 | - if ( $propertyId->equals( $qualifier->getPropertyId() ) ) { |
|
91 | + foreach ($context->getSnakStatement()->getQualifiers() as $qualifier) { |
|
92 | + if ($propertyId->equals($qualifier->getPropertyId())) { |
|
93 | 93 | $message = null; |
94 | 94 | $status = CheckResult::STATUS_COMPLIANCE; |
95 | 95 | break; |
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
99 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
99 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
100 | 100 | } |
101 | 101 | |
102 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
102 | + public function checkConstraintParameters(Constraint $constraint) { |
|
103 | 103 | $constraintParameters = $constraint->getConstraintParameters(); |
104 | 104 | $exceptions = []; |
105 | 105 | try { |
106 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
107 | - } catch ( ConstraintParameterException $e ) { |
|
106 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
107 | + } catch (ConstraintParameterException $e) { |
|
108 | 108 | $exceptions[] = $e; |
109 | 109 | } |
110 | 110 | return $exceptions; |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return CheckResult |
82 | 82 | */ |
83 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
84 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
85 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
83 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
84 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
85 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | $parameters = []; |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | $snak = $context->getSnak(); |
91 | 91 | $propertyId = $context->getSnak()->getPropertyId(); |
92 | 92 | |
93 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
93 | + if (!$snak instanceof PropertyValueSnak) { |
|
94 | 94 | // nothing to check |
95 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
95 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | $dataValue = $snak->getDataValue(); |
@@ -101,22 +101,22 @@ discard block |
||
101 | 101 | * error handling: |
102 | 102 | * type of $dataValue for properties with 'Symmetric' constraint has to be 'wikibase-entityid' |
103 | 103 | */ |
104 | - if ( $dataValue->getType() !== 'wikibase-entityid' ) { |
|
105 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
104 | + if ($dataValue->getType() !== 'wikibase-entityid') { |
|
105 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
106 | 106 | ->rawParams( |
107 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
107 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
108 | 108 | 'wikibase-entityid' // TODO is there a message for this type so we can localize it? |
109 | 109 | ) |
110 | 110 | ->escaped(); |
111 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
111 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
112 | 112 | } |
113 | 113 | /** @var EntityIdValue $dataValue */ |
114 | 114 | |
115 | 115 | $targetEntityId = $dataValue->getEntityId(); |
116 | - $targetEntity = $this->entityLookup->getEntity( $targetEntityId ); |
|
117 | - if ( $targetEntity === null ) { |
|
118 | - $message = new ViolationMessage( 'wbqc-violation-message-target-entity-must-exist' ); |
|
119 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
116 | + $targetEntity = $this->entityLookup->getEntity($targetEntityId); |
|
117 | + if ($targetEntity === null) { |
|
118 | + $message = new ViolationMessage('wbqc-violation-message-target-entity-must-exist'); |
|
119 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | $symmetricStatement = $this->connectionCheckerHelper->findStatementWithPropertyAndEntityIdValue( |
@@ -124,23 +124,23 @@ discard block |
||
124 | 124 | $propertyId, |
125 | 125 | $context->getEntity()->getId() |
126 | 126 | ); |
127 | - if ( $symmetricStatement !== null ) { |
|
127 | + if ($symmetricStatement !== null) { |
|
128 | 128 | $message = null; |
129 | 129 | $status = CheckResult::STATUS_COMPLIANCE; |
130 | 130 | } else { |
131 | - $message = ( new ViolationMessage( 'wbqc-violation-message-symmetric' ) ) |
|
132 | - ->withEntityId( $targetEntityId, Role::SUBJECT ) |
|
133 | - ->withEntityId( $propertyId, Role::PREDICATE ) |
|
134 | - ->withEntityId( $context->getEntity()->getId(), Role::OBJECT ); |
|
131 | + $message = (new ViolationMessage('wbqc-violation-message-symmetric')) |
|
132 | + ->withEntityId($targetEntityId, Role::SUBJECT) |
|
133 | + ->withEntityId($propertyId, Role::PREDICATE) |
|
134 | + ->withEntityId($context->getEntity()->getId(), Role::OBJECT); |
|
135 | 135 | $status = CheckResult::STATUS_VIOLATION; |
136 | 136 | } |
137 | 137 | |
138 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
139 | - ->withMetadata( Metadata::ofDependencyMetadata( |
|
140 | - DependencyMetadata::ofEntityId( $targetEntityId ) ) ); |
|
138 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
139 | + ->withMetadata(Metadata::ofDependencyMetadata( |
|
140 | + DependencyMetadata::ofEntityId($targetEntityId) )); |
|
141 | 141 | } |
142 | 142 | |
143 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
143 | + public function checkConstraintParameters(Constraint $constraint) { |
|
144 | 144 | // no parameters |
145 | 145 | return []; |
146 | 146 | } |
@@ -95,26 +95,26 @@ discard block |
||
95 | 95 | * @throws ConstraintParameterException |
96 | 96 | * @return CheckResult |
97 | 97 | */ |
98 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
98 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
99 | 99 | $parameters = []; |
100 | 100 | $constraintParameters = $constraint->getConstraintParameters(); |
101 | 101 | |
102 | - $format = $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
103 | - $parameters['pattern'] = [ $format ]; |
|
102 | + $format = $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
103 | + $parameters['pattern'] = [$format]; |
|
104 | 104 | |
105 | 105 | $syntaxClarification = $this->constraintParameterParser->parseSyntaxClarificationParameter( |
106 | 106 | $constraintParameters, |
107 | 107 | WikibaseRepo::getDefaultInstance()->getUserLanguage() // TODO make this part of the Context? |
108 | 108 | ); |
109 | - if ( $syntaxClarification !== null ) { |
|
110 | - $parameters['clarification'] = [ $syntaxClarification ]; |
|
109 | + if ($syntaxClarification !== null) { |
|
110 | + $parameters['clarification'] = [$syntaxClarification]; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | $snak = $context->getSnak(); |
114 | 114 | |
115 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
115 | + if (!$snak instanceof PropertyValueSnak) { |
|
116 | 116 | // nothing to check |
117 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
117 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | $dataValue = $snak->getDataValue(); |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | * error handling: |
124 | 124 | * type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext' |
125 | 125 | */ |
126 | - switch ( $dataValue->getType() ) { |
|
126 | + switch ($dataValue->getType()) { |
|
127 | 127 | case 'string': |
128 | 128 | $text = $dataValue->getValue(); |
129 | 129 | break; |
@@ -132,59 +132,58 @@ discard block |
||
132 | 132 | $text = $dataValue->getText(); |
133 | 133 | break; |
134 | 134 | default: |
135 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-types-2" ) |
|
135 | + $message = wfMessage("wbqc-violation-message-value-needed-of-types-2") |
|
136 | 136 | ->rawParams( |
137 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
138 | - wfMessage( 'datatypes-type-string' )->escaped(), |
|
139 | - wfMessage( 'datatypes-type-monolingualtext' )->escaped() |
|
137 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
138 | + wfMessage('datatypes-type-string')->escaped(), |
|
139 | + wfMessage('datatypes-type-monolingualtext')->escaped() |
|
140 | 140 | ) |
141 | 141 | ->escaped(); |
142 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
142 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
143 | 143 | } |
144 | 144 | |
145 | - if ( $this->sparqlHelper !== null && $this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) ) { |
|
146 | - if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) { |
|
145 | + if ($this->sparqlHelper !== null && $this->config->get('WBQualityConstraintsCheckFormatConstraint')) { |
|
146 | + if ($this->sparqlHelper->matchesRegularExpression($text, $format)) { |
|
147 | 147 | $message = null; |
148 | 148 | $status = CheckResult::STATUS_COMPLIANCE; |
149 | 149 | } else { |
150 | 150 | $message = wfMessage( |
151 | 151 | $syntaxClarification !== null ? |
152 | - 'wbqc-violation-message-format-clarification' : |
|
153 | - 'wbqc-violation-message-format' |
|
152 | + 'wbqc-violation-message-format-clarification' : 'wbqc-violation-message-format' |
|
154 | 153 | )->rawParams( |
155 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ), |
|
156 | - $this->constraintParameterRenderer->formatDataValue( new StringValue( $text ), Role::OBJECT ), |
|
157 | - $this->constraintParameterRenderer->formatByRole( Role::CONSTRAINT_PARAMETER_VALUE, |
|
158 | - '<code><nowiki>' . htmlspecialchars( $format ) . '</nowiki></code>' ) |
|
154 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY), |
|
155 | + $this->constraintParameterRenderer->formatDataValue(new StringValue($text), Role::OBJECT), |
|
156 | + $this->constraintParameterRenderer->formatByRole(Role::CONSTRAINT_PARAMETER_VALUE, |
|
157 | + '<code><nowiki>'.htmlspecialchars($format).'</nowiki></code>') |
|
159 | 158 | ); |
160 | - if ( $syntaxClarification !== null ) { |
|
161 | - $message->params( $syntaxClarification ); |
|
159 | + if ($syntaxClarification !== null) { |
|
160 | + $message->params($syntaxClarification); |
|
162 | 161 | } |
163 | 162 | $message = $message->escaped(); |
164 | 163 | $status = CheckResult::STATUS_VIOLATION; |
165 | 164 | } |
166 | 165 | } else { |
167 | - $message = ( new ViolationMessage( 'wbqc-violation-message-security-reason' ) ) |
|
168 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ); |
|
166 | + $message = (new ViolationMessage('wbqc-violation-message-security-reason')) |
|
167 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM); |
|
169 | 168 | $status = CheckResult::STATUS_TODO; |
170 | 169 | } |
171 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
170 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
172 | 171 | } |
173 | 172 | |
174 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
173 | + public function checkConstraintParameters(Constraint $constraint) { |
|
175 | 174 | $constraintParameters = $constraint->getConstraintParameters(); |
176 | 175 | $exceptions = []; |
177 | 176 | try { |
178 | - $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
179 | - } catch ( ConstraintParameterException $e ) { |
|
177 | + $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
178 | + } catch (ConstraintParameterException $e) { |
|
180 | 179 | $exceptions[] = $e; |
181 | 180 | } |
182 | 181 | try { |
183 | 182 | $this->constraintParameterParser->parseSyntaxClarificationParameter( |
184 | 183 | $constraintParameters, |
185 | - Language::factory( 'en' ) // errors are reported independent of language requested |
|
184 | + Language::factory('en') // errors are reported independent of language requested |
|
186 | 185 | ); |
187 | - } catch ( ConstraintParameterException $e ) { |
|
186 | + } catch (ConstraintParameterException $e) { |
|
188 | 187 | $exceptions[] = $e; |
189 | 188 | } |
190 | 189 | return $exceptions; |
@@ -71,53 +71,53 @@ |
||
71 | 71 | * @throws ConstraintParameterException |
72 | 72 | * @return CheckResult |
73 | 73 | */ |
74 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
75 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
76 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
74 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
75 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
76 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | $parameters = []; |
80 | 80 | $constraintParameters = $constraint->getConstraintParameters(); |
81 | 81 | |
82 | - $properties = $this->constraintParameterParser->parsePropertiesParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
82 | + $properties = $this->constraintParameterParser->parsePropertiesParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
83 | 83 | $parameters['property'] = $properties; |
84 | 84 | |
85 | 85 | $message = null; |
86 | 86 | $status = CheckResult::STATUS_COMPLIANCE; |
87 | 87 | |
88 | 88 | /** @var Snak $qualifier */ |
89 | - foreach ( $context->getSnakStatement()->getQualifiers() as $qualifier ) { |
|
89 | + foreach ($context->getSnakStatement()->getQualifiers() as $qualifier) { |
|
90 | 90 | $allowedQualifier = false; |
91 | - foreach ( $properties as $property ) { |
|
92 | - if ( $qualifier->getPropertyId()->equals( $property ) ) { |
|
91 | + foreach ($properties as $property) { |
|
92 | + if ($qualifier->getPropertyId()->equals($property)) { |
|
93 | 93 | $allowedQualifier = true; |
94 | 94 | break; |
95 | 95 | } |
96 | 96 | } |
97 | - if ( !$allowedQualifier ) { |
|
98 | - if ( empty( $properties ) || $properties === [ '' ] ) { |
|
99 | - $message = ( new ViolationMessage( 'wbqc-violation-message-no-qualifiers' ) ) |
|
100 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ); |
|
97 | + if (!$allowedQualifier) { |
|
98 | + if (empty($properties) || $properties === ['']) { |
|
99 | + $message = (new ViolationMessage('wbqc-violation-message-no-qualifiers')) |
|
100 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY); |
|
101 | 101 | } else { |
102 | - $message = ( new ViolationMessage( 'wbqc-violation-message-qualifiers' ) ) |
|
103 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
104 | - ->withEntityId( $qualifier->getPropertyId(), Role::QUALIFIER_PREDICATE ) |
|
105 | - ->withEntityIdList( $properties, Role::QUALIFIER_PREDICATE ); |
|
102 | + $message = (new ViolationMessage('wbqc-violation-message-qualifiers')) |
|
103 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
104 | + ->withEntityId($qualifier->getPropertyId(), Role::QUALIFIER_PREDICATE) |
|
105 | + ->withEntityIdList($properties, Role::QUALIFIER_PREDICATE); |
|
106 | 106 | } |
107 | 107 | $status = CheckResult::STATUS_VIOLATION; |
108 | 108 | break; |
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
112 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
112 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
113 | 113 | } |
114 | 114 | |
115 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
115 | + public function checkConstraintParameters(Constraint $constraint) { |
|
116 | 116 | $constraintParameters = $constraint->getConstraintParameters(); |
117 | 117 | $exceptions = []; |
118 | 118 | try { |
119 | - $this->constraintParameterParser->parsePropertiesParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
120 | - } catch ( ConstraintParameterException $e ) { |
|
119 | + $this->constraintParameterParser->parsePropertiesParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
120 | + } catch (ConstraintParameterException $e) { |
|
121 | 121 | $exceptions[] = $e; |
122 | 122 | } |
123 | 123 | return $exceptions; |
@@ -74,22 +74,22 @@ discard block |
||
74 | 74 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
75 | 75 | * @return CheckResult |
76 | 76 | */ |
77 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
78 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
79 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
77 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
78 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
79 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | $parameters = []; |
83 | 83 | |
84 | - if ( $this->sparqlHelper !== null ) { |
|
85 | - if ( $context->getType() === 'statement' ) { |
|
84 | + if ($this->sparqlHelper !== null) { |
|
85 | + if ($context->getType() === 'statement') { |
|
86 | 86 | $result = $this->sparqlHelper->findEntitiesWithSameStatement( |
87 | 87 | $context->getSnakStatement(), |
88 | 88 | true // ignore deprecated statements |
89 | 89 | ); |
90 | 90 | } else { |
91 | - if ( $context->getSnak()->getType() !== 'value' ) { |
|
92 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
91 | + if ($context->getSnak()->getType() !== 'value') { |
|
92 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
93 | 93 | } |
94 | 94 | $result = $this->sparqlHelper->findEntitiesWithSameQualifierOrReference( |
95 | 95 | $context->getEntity()->getId(), |
@@ -102,27 +102,27 @@ discard block |
||
102 | 102 | $otherEntities = $result->getArray(); |
103 | 103 | $metadata = $result->getMetadata(); |
104 | 104 | |
105 | - if ( $otherEntities === [] ) { |
|
105 | + if ($otherEntities === []) { |
|
106 | 106 | $status = CheckResult::STATUS_COMPLIANCE; |
107 | 107 | $message = null; |
108 | 108 | } else { |
109 | - $otherEntities = array_values( array_filter( $otherEntities ) ); // remove nulls |
|
109 | + $otherEntities = array_values(array_filter($otherEntities)); // remove nulls |
|
110 | 110 | $status = CheckResult::STATUS_VIOLATION; |
111 | - $message = ( new ViolationMessage( 'wbqc-violation-message-unique-value' ) ) |
|
112 | - ->withEntityIdList( $otherEntities, Role::SUBJECT ); |
|
111 | + $message = (new ViolationMessage('wbqc-violation-message-unique-value')) |
|
112 | + ->withEntityIdList($otherEntities, Role::SUBJECT); |
|
113 | 113 | } |
114 | 114 | } else { |
115 | 115 | $status = CheckResult::STATUS_TODO; |
116 | - $message = ( new ViolationMessage( 'wbqc-violation-message-not-yet-implemented' ) ) |
|
117 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ); |
|
116 | + $message = (new ViolationMessage('wbqc-violation-message-not-yet-implemented')) |
|
117 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM); |
|
118 | 118 | $metadata = Metadata::blank(); |
119 | 119 | } |
120 | 120 | |
121 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
122 | - ->withMetadata( $metadata ); |
|
121 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
122 | + ->withMetadata($metadata); |
|
123 | 123 | } |
124 | 124 | |
125 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
125 | + public function checkConstraintParameters(Constraint $constraint) { |
|
126 | 126 | // no parameters |
127 | 127 | return []; |
128 | 128 | } |