@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | StatementList $statementList, |
29 | 29 | PropertyId $propertyId |
30 | 30 | ) { |
31 | - $statementListByPropertyId = $statementList->getByPropertyId( $propertyId ); |
|
32 | - if ( $statementListByPropertyId->isEmpty() ) { |
|
31 | + $statementListByPropertyId = $statementList->getByPropertyId($propertyId); |
|
32 | + if ($statementListByPropertyId->isEmpty()) { |
|
33 | 33 | return null; |
34 | 34 | } else { |
35 | 35 | return $statementListByPropertyId->toArray()[0]; |
@@ -50,15 +50,15 @@ discard block |
||
50 | 50 | PropertyId $propertyId, |
51 | 51 | EntityId $value |
52 | 52 | ) { |
53 | - $statementListByPropertyId = $statementList->getByPropertyId( $propertyId ); |
|
53 | + $statementListByPropertyId = $statementList->getByPropertyId($propertyId); |
|
54 | 54 | /** @var Statement $statement */ |
55 | - foreach ( $statementListByPropertyId as $statement ) { |
|
55 | + foreach ($statementListByPropertyId as $statement) { |
|
56 | 56 | $snak = $statement->getMainSnak(); |
57 | - if ( $snak->getType() === 'value' ) { |
|
57 | + if ($snak->getType() === 'value') { |
|
58 | 58 | $dataValue = $snak->getDataValue(); |
59 | 59 | if ( |
60 | 60 | $dataValue->getType() === 'wikibase-entityid' && |
61 | - $dataValue->getEntityId()->equals( $value ) |
|
61 | + $dataValue->getEntityId()->equals($value) |
|
62 | 62 | ) { |
63 | 63 | return $statement; |
64 | 64 | } |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | PropertyId $propertyId, |
82 | 82 | array $values |
83 | 83 | ) { |
84 | - $statementListByPropertyId = $statementList->getByPropertyId( $propertyId ); |
|
84 | + $statementListByPropertyId = $statementList->getByPropertyId($propertyId); |
|
85 | 85 | /** @var Statement $statement */ |
86 | - foreach ( $statementListByPropertyId as $statement ) { |
|
86 | + foreach ($statementListByPropertyId as $statement) { |
|
87 | 87 | $snak = $statement->getMainSnak(); |
88 | - foreach ( $values as $value ) { |
|
89 | - if ( $value->matchesSnak( $snak ) ) { |
|
88 | + foreach ($values as $value) { |
|
89 | + if ($value->matchesSnak($snak)) { |
|
90 | 90 | return $statement; |
91 | 91 | } |
92 | 92 | } |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | $this->dataFactory = $dataFactory; |
49 | 49 | $this->logger = $logger; |
50 | 50 | $this->constraintCheckDurationLimits = [ |
51 | - 'info' => $config->get( 'WBQualityConstraintsCheckDurationInfoSeconds' ), |
|
52 | - 'warning' => $config->get( 'WBQualityConstraintsCheckDurationWarningSeconds' ), |
|
51 | + 'info' => $config->get('WBQualityConstraintsCheckDurationInfoSeconds'), |
|
52 | + 'warning' => $config->get('WBQualityConstraintsCheckDurationWarningSeconds'), |
|
53 | 53 | ]; |
54 | 54 | } |
55 | 55 | |
@@ -75,41 +75,41 @@ discard block |
||
75 | 75 | $durationSeconds, |
76 | 76 | $method |
77 | 77 | ) { |
78 | - $constraintCheckerClassShortName = substr( strrchr( $constraintCheckerClass, '\\' ), 1 ); |
|
78 | + $constraintCheckerClassShortName = substr(strrchr($constraintCheckerClass, '\\'), 1); |
|
79 | 79 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
80 | 80 | |
81 | 81 | $this->dataFactory->timing( |
82 | - 'wikibase.quality.constraints.check.timing.' . |
|
83 | - $constraintTypeItemId . '-' . |
|
82 | + 'wikibase.quality.constraints.check.timing.'. |
|
83 | + $constraintTypeItemId.'-'. |
|
84 | 84 | $constraintCheckerClassShortName, |
85 | 85 | $durationSeconds * 1000 |
86 | 86 | ); |
87 | 87 | |
88 | 88 | // find the longest limit (and associated log level) that the duration exceeds |
89 | - foreach ( $this->constraintCheckDurationLimits as $level => $limit ) { |
|
89 | + foreach ($this->constraintCheckDurationLimits as $level => $limit) { |
|
90 | 90 | if ( |
91 | 91 | // duration exceeds this limit |
92 | - isset( $limit ) && $durationSeconds > $limit && |
|
92 | + isset($limit) && $durationSeconds > $limit && |
|
93 | 93 | // this limit is longer than previous longest limit |
94 | - ( !isset( $limitSeconds ) || $limit > $limitSeconds ) |
|
94 | + (!isset($limitSeconds) || $limit > $limitSeconds) |
|
95 | 95 | ) { |
96 | 96 | $limitSeconds = $limit; |
97 | 97 | $logLevel = $level; |
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
101 | - if ( !isset( $limitSeconds ) ) { |
|
101 | + if (!isset($limitSeconds)) { |
|
102 | 102 | return; |
103 | 103 | } |
104 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
104 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
105 | 105 | // TODO log less details but still log something |
106 | 106 | return; |
107 | 107 | } |
108 | 108 | |
109 | 109 | $this->logger->log( |
110 | 110 | $logLevel, |
111 | - 'Constraint check with {constraintCheckerClassShortName} ' . |
|
112 | - 'took longer than {limitSeconds} second(s) ' . |
|
111 | + 'Constraint check with {constraintCheckerClassShortName} '. |
|
112 | + 'took longer than {limitSeconds} second(s) '. |
|
113 | 113 | '(duration: {durationSeconds} seconds).', |
114 | 114 | [ |
115 | 115 | 'method' => $method, |
@@ -75,15 +75,15 @@ discard block |
||
75 | 75 | * @param array $parameters |
76 | 76 | * @throws ConstraintParameterException |
77 | 77 | */ |
78 | - public function checkError( array $parameters ) { |
|
79 | - if ( array_key_exists( '@error', $parameters ) ) { |
|
78 | + public function checkError(array $parameters) { |
|
79 | + if (array_key_exists('@error', $parameters)) { |
|
80 | 80 | $error = $parameters['@error']; |
81 | - if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) { |
|
81 | + if (array_key_exists('toolong', $error) && $error['toolong']) { |
|
82 | 82 | $msg = 'wbqc-violation-message-parameters-error-toolong'; |
83 | 83 | } else { |
84 | 84 | $msg = 'wbqc-violation-message-parameters-error-unknown'; |
85 | 85 | } |
86 | - throw new ConstraintParameterException( wfMessage( $msg )->escaped() ); |
|
86 | + throw new ConstraintParameterException(wfMessage($msg)->escaped()); |
|
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
@@ -93,11 +93,11 @@ discard block |
||
93 | 93 | * @param string $parameterId |
94 | 94 | * @throws ConstraintParameterException |
95 | 95 | */ |
96 | - private function requireSingleParameter( array $parameters, $parameterId ) { |
|
97 | - if ( count( $parameters[$parameterId] ) !== 1 ) { |
|
96 | + private function requireSingleParameter(array $parameters, $parameterId) { |
|
97 | + if (count($parameters[$parameterId]) !== 1) { |
|
98 | 98 | throw new ConstraintParameterException( |
99 | - wfMessage( 'wbqc-violation-message-parameter-single' ) |
|
100 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
99 | + wfMessage('wbqc-violation-message-parameter-single') |
|
100 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
101 | 101 | ->escaped() |
102 | 102 | ); |
103 | 103 | } |
@@ -110,11 +110,11 @@ discard block |
||
110 | 110 | * @return void |
111 | 111 | * @throws ConstraintParameterException |
112 | 112 | */ |
113 | - private function requireValueParameter( Snak $snak, $parameterId ) { |
|
114 | - if ( !( $snak instanceof PropertyValueSnak ) ) { |
|
113 | + private function requireValueParameter(Snak $snak, $parameterId) { |
|
114 | + if (!($snak instanceof PropertyValueSnak)) { |
|
115 | 115 | throw new ConstraintParameterException( |
116 | - wfMessage( 'wbqc-violation-message-parameter-value' ) |
|
117 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
116 | + wfMessage('wbqc-violation-message-parameter-value') |
|
117 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
118 | 118 | ->escaped() |
119 | 119 | ); |
120 | 120 | } |
@@ -127,18 +127,18 @@ discard block |
||
127 | 127 | * @throws ConstraintParameterException |
128 | 128 | * @return EntityId |
129 | 129 | */ |
130 | - private function parseEntityIdParameter( array $snakSerialization, $parameterId ) { |
|
131 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
132 | - $this->requireValueParameter( $snak, $parameterId ); |
|
130 | + private function parseEntityIdParameter(array $snakSerialization, $parameterId) { |
|
131 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
132 | + $this->requireValueParameter($snak, $parameterId); |
|
133 | 133 | $value = $snak->getDataValue(); |
134 | - if ( $value instanceof EntityIdValue ) { |
|
134 | + if ($value instanceof EntityIdValue) { |
|
135 | 135 | return $value->getEntityId(); |
136 | 136 | } else { |
137 | 137 | throw new ConstraintParameterException( |
138 | - wfMessage( 'wbqc-violation-message-parameter-entity' ) |
|
138 | + wfMessage('wbqc-violation-message-parameter-entity') |
|
139 | 139 | ->rawParams( |
140 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
141 | - $this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
140 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
141 | + $this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
142 | 142 | ) |
143 | 143 | ->escaped() |
144 | 144 | ); |
@@ -151,21 +151,21 @@ discard block |
||
151 | 151 | * @throws ConstraintParameterException if the parameter is invalid or missing |
152 | 152 | * @return string[] class entity ID serializations |
153 | 153 | */ |
154 | - public function parseClassParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
155 | - $this->checkError( $constraintParameters ); |
|
156 | - $classId = $this->config->get( 'WBQualityConstraintsClassId' ); |
|
157 | - if ( !array_key_exists( $classId, $constraintParameters ) ) { |
|
154 | + public function parseClassParameter(array $constraintParameters, $constraintTypeItemId) { |
|
155 | + $this->checkError($constraintParameters); |
|
156 | + $classId = $this->config->get('WBQualityConstraintsClassId'); |
|
157 | + if (!array_key_exists($classId, $constraintParameters)) { |
|
158 | 158 | throw new ConstraintParameterException( |
159 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
160 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
161 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $classId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
159 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
160 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
161 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($classId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
162 | 162 | ->escaped() |
163 | 163 | ); |
164 | 164 | } |
165 | 165 | |
166 | 166 | $classes = []; |
167 | - foreach ( $constraintParameters[$classId] as $class ) { |
|
168 | - $classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization(); |
|
167 | + foreach ($constraintParameters[$classId] as $class) { |
|
168 | + $classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization(); |
|
169 | 169 | } |
170 | 170 | return $classes; |
171 | 171 | } |
@@ -176,33 +176,33 @@ discard block |
||
176 | 176 | * @throws ConstraintParameterException if the parameter is invalid or missing |
177 | 177 | * @return string 'instance' or 'subclass' |
178 | 178 | */ |
179 | - public function parseRelationParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
180 | - $this->checkError( $constraintParameters ); |
|
181 | - $relationId = $this->config->get( 'WBQualityConstraintsRelationId' ); |
|
182 | - if ( !array_key_exists( $relationId, $constraintParameters ) ) { |
|
179 | + public function parseRelationParameter(array $constraintParameters, $constraintTypeItemId) { |
|
180 | + $this->checkError($constraintParameters); |
|
181 | + $relationId = $this->config->get('WBQualityConstraintsRelationId'); |
|
182 | + if (!array_key_exists($relationId, $constraintParameters)) { |
|
183 | 183 | throw new ConstraintParameterException( |
184 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
185 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
186 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $relationId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
184 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
185 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
186 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($relationId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
187 | 187 | ->escaped() |
188 | 188 | ); |
189 | 189 | } |
190 | 190 | |
191 | - $this->requireSingleParameter( $constraintParameters, $relationId ); |
|
192 | - $relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId ); |
|
193 | - $instanceId = $this->config->get( 'WBQualityConstraintsInstanceOfRelationId' ); |
|
194 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfRelationId' ); |
|
195 | - switch ( $relationEntityId ) { |
|
191 | + $this->requireSingleParameter($constraintParameters, $relationId); |
|
192 | + $relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId); |
|
193 | + $instanceId = $this->config->get('WBQualityConstraintsInstanceOfRelationId'); |
|
194 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfRelationId'); |
|
195 | + switch ($relationEntityId) { |
|
196 | 196 | case $instanceId: |
197 | 197 | return 'instance'; |
198 | 198 | case $subclassId: |
199 | 199 | return 'subclass'; |
200 | 200 | default: |
201 | 201 | throw new ConstraintParameterException( |
202 | - wfMessage( 'wbqc-violation-message-parameter-oneof' ) |
|
203 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $relationId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
204 | - ->numParams( 2 ) |
|
205 | - ->rawParams( $this->constraintParameterRenderer->formatItemIdList( [ $instanceId, $subclassId ], Role::CONSTRAINT_PARAMETER_VALUE ) ) |
|
202 | + wfMessage('wbqc-violation-message-parameter-oneof') |
|
203 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($relationId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
204 | + ->numParams(2) |
|
205 | + ->rawParams($this->constraintParameterRenderer->formatItemIdList([$instanceId, $subclassId], Role::CONSTRAINT_PARAMETER_VALUE)) |
|
206 | 206 | ->escaped() |
207 | 207 | ); |
208 | 208 | } |
@@ -215,21 +215,21 @@ discard block |
||
215 | 215 | * @throws ConstraintParameterException |
216 | 216 | * @return PropertyId |
217 | 217 | */ |
218 | - private function parsePropertyIdParameter( array $snakSerialization, $parameterId ) { |
|
219 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
220 | - $this->requireValueParameter( $snak, $parameterId ); |
|
218 | + private function parsePropertyIdParameter(array $snakSerialization, $parameterId) { |
|
219 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
220 | + $this->requireValueParameter($snak, $parameterId); |
|
221 | 221 | $value = $snak->getDataValue(); |
222 | - if ( $value instanceof EntityIdValue ) { |
|
222 | + if ($value instanceof EntityIdValue) { |
|
223 | 223 | $id = $value->getEntityId(); |
224 | - if ( $id instanceof PropertyId ) { |
|
224 | + if ($id instanceof PropertyId) { |
|
225 | 225 | return $id; |
226 | 226 | } |
227 | 227 | } |
228 | 228 | throw new ConstraintParameterException( |
229 | - wfMessage( 'wbqc-violation-message-parameter-property' ) |
|
229 | + wfMessage('wbqc-violation-message-parameter-property') |
|
230 | 230 | ->rawParams( |
231 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
232 | - $this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
231 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
232 | + $this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
233 | 233 | ) |
234 | 234 | ->escaped() |
235 | 235 | ); |
@@ -242,33 +242,33 @@ discard block |
||
242 | 242 | * @throws ConstraintParameterException if the parameter is invalid or missing |
243 | 243 | * @return PropertyId |
244 | 244 | */ |
245 | - public function parsePropertyParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
246 | - $this->checkError( $constraintParameters ); |
|
247 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
248 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
245 | + public function parsePropertyParameter(array $constraintParameters, $constraintTypeItemId) { |
|
246 | + $this->checkError($constraintParameters); |
|
247 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
248 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
249 | 249 | throw new ConstraintParameterException( |
250 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
251 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
252 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
250 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
251 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
252 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
253 | 253 | ->escaped() |
254 | 254 | ); |
255 | 255 | } |
256 | 256 | |
257 | - $this->requireSingleParameter( $constraintParameters, $propertyId ); |
|
258 | - return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId ); |
|
257 | + $this->requireSingleParameter($constraintParameters, $propertyId); |
|
258 | + return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId); |
|
259 | 259 | } |
260 | 260 | |
261 | - private function parseItemIdParameter( PropertyValueSnak $snak, $parameterId ) { |
|
262 | - if ( $snak->getDataValue() instanceof EntityIdValue && |
|
261 | + private function parseItemIdParameter(PropertyValueSnak $snak, $parameterId) { |
|
262 | + if ($snak->getDataValue() instanceof EntityIdValue && |
|
263 | 263 | $snak->getDataValue()->getEntityId() instanceof ItemId |
264 | 264 | ) { |
265 | - return ItemIdSnakValue::fromItemId( $snak->getDataValue()->getEntityId() ); |
|
265 | + return ItemIdSnakValue::fromItemId($snak->getDataValue()->getEntityId()); |
|
266 | 266 | } else { |
267 | 267 | throw new ConstraintParameterException( |
268 | - wfMessage( 'wbqc-violation-message-parameter-item' ) |
|
268 | + wfMessage('wbqc-violation-message-parameter-item') |
|
269 | 269 | ->rawParams( |
270 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
271 | - $this->constraintParameterRenderer->formatDataValue( $snak->getDataValue(), Role::CONSTRAINT_PARAMETER_VALUE ) |
|
270 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
271 | + $this->constraintParameterRenderer->formatDataValue($snak->getDataValue(), Role::CONSTRAINT_PARAMETER_VALUE) |
|
272 | 272 | ) |
273 | 273 | ->escaped() |
274 | 274 | ); |
@@ -282,15 +282,15 @@ discard block |
||
282 | 282 | * @throws ConstraintParameterException if the parameter is invalid or missing |
283 | 283 | * @return ItemIdSnakValue[] array of values |
284 | 284 | */ |
285 | - public function parseItemsParameter( array $constraintParameters, $constraintTypeItemId, $required ) { |
|
286 | - $this->checkError( $constraintParameters ); |
|
287 | - $qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
288 | - if ( !array_key_exists( $qualifierId, $constraintParameters ) ) { |
|
289 | - if ( $required ) { |
|
285 | + public function parseItemsParameter(array $constraintParameters, $constraintTypeItemId, $required) { |
|
286 | + $this->checkError($constraintParameters); |
|
287 | + $qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
288 | + if (!array_key_exists($qualifierId, $constraintParameters)) { |
|
289 | + if ($required) { |
|
290 | 290 | throw new ConstraintParameterException( |
291 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
292 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
293 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $qualifierId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
291 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
292 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
293 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($qualifierId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
294 | 294 | ->escaped() |
295 | 295 | ); |
296 | 296 | } else { |
@@ -299,11 +299,11 @@ discard block |
||
299 | 299 | } |
300 | 300 | |
301 | 301 | $values = []; |
302 | - foreach ( $constraintParameters[$qualifierId] as $parameter ) { |
|
303 | - $snak = $this->snakDeserializer->deserialize( $parameter ); |
|
304 | - switch ( true ) { |
|
302 | + foreach ($constraintParameters[$qualifierId] as $parameter) { |
|
303 | + $snak = $this->snakDeserializer->deserialize($parameter); |
|
304 | + switch (true) { |
|
305 | 305 | case $snak instanceof PropertyValueSnak: |
306 | - $values[] = $this->parseItemIdParameter( $snak, $qualifierId ); |
|
306 | + $values[] = $this->parseItemIdParameter($snak, $qualifierId); |
|
307 | 307 | break; |
308 | 308 | case $snak instanceof PropertySomeValueSnak: |
309 | 309 | $values[] = ItemIdSnakValue::someValue(); |
@@ -322,28 +322,28 @@ discard block |
||
322 | 322 | * @throws ConstraintParameterException if the parameter is invalid or missing |
323 | 323 | * @return PropertyId[] |
324 | 324 | */ |
325 | - public function parsePropertiesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
326 | - $this->checkError( $constraintParameters ); |
|
327 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
328 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
325 | + public function parsePropertiesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
326 | + $this->checkError($constraintParameters); |
|
327 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
328 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
329 | 329 | throw new ConstraintParameterException( |
330 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
331 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
332 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
330 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
331 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
332 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
333 | 333 | ->escaped() |
334 | 334 | ); |
335 | 335 | } |
336 | 336 | |
337 | 337 | $parameters = $constraintParameters[$propertyId]; |
338 | - if ( count( $parameters ) === 1 && |
|
339 | - $this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak |
|
338 | + if (count($parameters) === 1 && |
|
339 | + $this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak |
|
340 | 340 | ) { |
341 | 341 | return []; |
342 | 342 | } |
343 | 343 | |
344 | 344 | $properties = []; |
345 | - foreach ( $parameters as $parameter ) { |
|
346 | - $properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId ); |
|
345 | + foreach ($parameters as $parameter) { |
|
346 | + $properties[] = $this->parsePropertyIdParameter($parameter, $propertyId); |
|
347 | 347 | } |
348 | 348 | return $properties; |
349 | 349 | } |
@@ -354,16 +354,16 @@ discard block |
||
354 | 354 | * @throws ConstraintParameterException |
355 | 355 | * @return DataValue|null |
356 | 356 | */ |
357 | - private function parseValueOrNoValueParameter( array $snakSerialization, $parameterId ) { |
|
358 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
359 | - if ( $snak instanceof PropertyValueSnak ) { |
|
357 | + private function parseValueOrNoValueParameter(array $snakSerialization, $parameterId) { |
|
358 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
359 | + if ($snak instanceof PropertyValueSnak) { |
|
360 | 360 | return $snak->getDataValue(); |
361 | - } elseif ( $snak instanceof PropertyNoValueSnak ) { |
|
361 | + } elseif ($snak instanceof PropertyNoValueSnak) { |
|
362 | 362 | return null; |
363 | 363 | } else { |
364 | 364 | throw new ConstraintParameterException( |
365 | - wfMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) |
|
366 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
365 | + wfMessage('wbqc-violation-message-parameter-value-or-novalue') |
|
366 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
367 | 367 | ->escaped() |
368 | 368 | ); |
369 | 369 | } |
@@ -374,13 +374,13 @@ discard block |
||
374 | 374 | * @param string $parameterId |
375 | 375 | * @return DataValue|null |
376 | 376 | */ |
377 | - private function parseValueOrNoValueOrNowParameter( array $snakSerialization, $parameterId ) { |
|
377 | + private function parseValueOrNoValueOrNowParameter(array $snakSerialization, $parameterId) { |
|
378 | 378 | try { |
379 | - return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId ); |
|
380 | - } catch ( ConstraintParameterException $e ) { |
|
379 | + return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId); |
|
380 | + } catch (ConstraintParameterException $e) { |
|
381 | 381 | // unknown value means “now” |
382 | - $timeParser = ( new TimeParserFactory() )->getTimeParser(); |
|
383 | - return $timeParser->parse( gmdate( '+Y-m-d\T00:00:00\Z' ) ); |
|
382 | + $timeParser = (new TimeParserFactory())->getTimeParser(); |
|
383 | + return $timeParser->parse(gmdate('+Y-m-d\T00:00:00\Z')); |
|
384 | 384 | } |
385 | 385 | } |
386 | 386 | |
@@ -391,14 +391,14 @@ discard block |
||
391 | 391 | * @param string $unit |
392 | 392 | * @return bool |
393 | 393 | */ |
394 | - private function exactlyOneQuantityWithUnit( DataValue $min = null, DataValue $max = null, $unit ) { |
|
395 | - if ( $min === null || $max === null ) { |
|
394 | + private function exactlyOneQuantityWithUnit(DataValue $min = null, DataValue $max = null, $unit) { |
|
395 | + if ($min === null || $max === null) { |
|
396 | 396 | return false; |
397 | 397 | } |
398 | - if ( $min->getType() !== 'quantity' || $max->getType() !== 'quantity' ) { |
|
398 | + if ($min->getType() !== 'quantity' || $max->getType() !== 'quantity') { |
|
399 | 399 | return false; |
400 | 400 | } |
401 | - return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit ); |
|
401 | + return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit); |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | /** |
@@ -409,9 +409,9 @@ discard block |
||
409 | 409 | * @throws ConstraintParameterException if the parameter is invalid or missing |
410 | 410 | * @return DataValue[] a pair of two quantity-type data values, either of which may be null to signify an open range |
411 | 411 | */ |
412 | - public function parseRangeParameter( array $constraintParameters, $constraintTypeItemId, $type ) { |
|
413 | - $this->checkError( $constraintParameters ); |
|
414 | - switch ( $type ) { |
|
412 | + public function parseRangeParameter(array $constraintParameters, $constraintTypeItemId, $type) { |
|
413 | + $this->checkError($constraintParameters); |
|
414 | + switch ($type) { |
|
415 | 415 | case 'quantity': |
416 | 416 | $configKey = 'Quantity'; |
417 | 417 | break; |
@@ -420,46 +420,46 @@ discard block |
||
420 | 420 | break; |
421 | 421 | default: |
422 | 422 | throw new ConstraintParameterException( |
423 | - wfMessage( 'wbqc-violation-message-value-needed-of-types-2' ) |
|
423 | + wfMessage('wbqc-violation-message-value-needed-of-types-2') |
|
424 | 424 | ->rawParams( |
425 | - wfMessage( 'datatypes-type-quantity' )->escaped(), |
|
426 | - wfMessage( 'datatypes-type-time' )->escaped() |
|
425 | + wfMessage('datatypes-type-quantity')->escaped(), |
|
426 | + wfMessage('datatypes-type-time')->escaped() |
|
427 | 427 | ) |
428 | 428 | ->escaped() |
429 | 429 | ); |
430 | 430 | } |
431 | - $minimumId = $this->config->get( 'WBQualityConstraintsMinimum' . $configKey . 'Id' ); |
|
432 | - $maximumId = $this->config->get( 'WBQualityConstraintsMaximum' . $configKey . 'Id' ); |
|
433 | - if ( !array_key_exists( $minimumId, $constraintParameters ) || |
|
434 | - !array_key_exists( $maximumId, $constraintParameters ) |
|
431 | + $minimumId = $this->config->get('WBQualityConstraintsMinimum'.$configKey.'Id'); |
|
432 | + $maximumId = $this->config->get('WBQualityConstraintsMaximum'.$configKey.'Id'); |
|
433 | + if (!array_key_exists($minimumId, $constraintParameters) || |
|
434 | + !array_key_exists($maximumId, $constraintParameters) |
|
435 | 435 | ) { |
436 | 436 | throw new ConstraintParameterException( |
437 | - wfMessage( 'wbqc-violation-message-range-parameters-needed' ) |
|
437 | + wfMessage('wbqc-violation-message-range-parameters-needed') |
|
438 | 438 | ->rawParams( |
439 | - wfMessage( 'datatypes-type-' . $type )->escaped(), |
|
440 | - $this->constraintParameterRenderer->formatPropertyId( $minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
441 | - $this->constraintParameterRenderer->formatPropertyId( $maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
439 | + wfMessage('datatypes-type-'.$type)->escaped(), |
|
440 | + $this->constraintParameterRenderer->formatPropertyId($minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
441 | + $this->constraintParameterRenderer->formatPropertyId($maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
442 | 442 | ) |
443 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
443 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
444 | 444 | ->escaped() |
445 | 445 | ); |
446 | 446 | } |
447 | 447 | |
448 | - $this->requireSingleParameter( $constraintParameters, $minimumId ); |
|
449 | - $this->requireSingleParameter( $constraintParameters, $maximumId ); |
|
448 | + $this->requireSingleParameter($constraintParameters, $minimumId); |
|
449 | + $this->requireSingleParameter($constraintParameters, $maximumId); |
|
450 | 450 | $parseFunction = $configKey === 'Date' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter'; |
451 | - $min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId ); |
|
452 | - $max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId ); |
|
451 | + $min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId); |
|
452 | + $max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId); |
|
453 | 453 | |
454 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
455 | - if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) { |
|
454 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
455 | + if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) { |
|
456 | 456 | throw new ConstraintParameterException( |
457 | - wfMessage( 'wbqc-violation-message-range-parameters-one-year' ) |
|
457 | + wfMessage('wbqc-violation-message-range-parameters-one-year') |
|
458 | 458 | ->escaped() |
459 | 459 | ); |
460 | 460 | } |
461 | 461 | |
462 | - return [ $min, $max ]; |
|
462 | + return [$min, $max]; |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | /** |
@@ -469,18 +469,18 @@ discard block |
||
469 | 469 | * @throws ConstraintParameterException |
470 | 470 | * @return string |
471 | 471 | */ |
472 | - private function parseStringParameter( array $snakSerialization, $parameterId ) { |
|
473 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
474 | - $this->requireValueParameter( $snak, $parameterId ); |
|
472 | + private function parseStringParameter(array $snakSerialization, $parameterId) { |
|
473 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
474 | + $this->requireValueParameter($snak, $parameterId); |
|
475 | 475 | $value = $snak->getDataValue(); |
476 | - if ( $value instanceof StringValue ) { |
|
476 | + if ($value instanceof StringValue) { |
|
477 | 477 | return $value->getValue(); |
478 | 478 | } else { |
479 | 479 | throw new ConstraintParameterException( |
480 | - wfMessage( 'wbqc-violation-message-parameter-string' ) |
|
480 | + wfMessage('wbqc-violation-message-parameter-string') |
|
481 | 481 | ->rawParams( |
482 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
483 | - $this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
482 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
483 | + $this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
484 | 484 | ) |
485 | 485 | ->escaped() |
486 | 486 | ); |
@@ -493,15 +493,15 @@ discard block |
||
493 | 493 | * @throws ConstraintParameterException if the parameter is invalid or missing |
494 | 494 | * @return string |
495 | 495 | */ |
496 | - public function parseNamespaceParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
497 | - $this->checkError( $constraintParameters ); |
|
498 | - $namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' ); |
|
499 | - if ( !array_key_exists( $namespaceId, $constraintParameters ) ) { |
|
496 | + public function parseNamespaceParameter(array $constraintParameters, $constraintTypeItemId) { |
|
497 | + $this->checkError($constraintParameters); |
|
498 | + $namespaceId = $this->config->get('WBQualityConstraintsNamespaceId'); |
|
499 | + if (!array_key_exists($namespaceId, $constraintParameters)) { |
|
500 | 500 | return ''; |
501 | 501 | } |
502 | 502 | |
503 | - $this->requireSingleParameter( $constraintParameters, $namespaceId ); |
|
504 | - return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId ); |
|
503 | + $this->requireSingleParameter($constraintParameters, $namespaceId); |
|
504 | + return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId); |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | /** |
@@ -510,20 +510,20 @@ discard block |
||
510 | 510 | * @throws ConstraintParameterException if the parameter is invalid or missing |
511 | 511 | * @return string |
512 | 512 | */ |
513 | - public function parseFormatParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
514 | - $this->checkError( $constraintParameters ); |
|
515 | - $formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' ); |
|
516 | - if ( !array_key_exists( $formatId, $constraintParameters ) ) { |
|
513 | + public function parseFormatParameter(array $constraintParameters, $constraintTypeItemId) { |
|
514 | + $this->checkError($constraintParameters); |
|
515 | + $formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId'); |
|
516 | + if (!array_key_exists($formatId, $constraintParameters)) { |
|
517 | 517 | throw new ConstraintParameterException( |
518 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
519 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
520 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $formatId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
518 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
519 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
520 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($formatId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
521 | 521 | ->escaped() |
522 | 522 | ); |
523 | 523 | } |
524 | 524 | |
525 | - $this->requireSingleParameter( $constraintParameters, $formatId ); |
|
526 | - return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId ); |
|
525 | + $this->requireSingleParameter($constraintParameters, $formatId); |
|
526 | + return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
@@ -531,16 +531,16 @@ discard block |
||
531 | 531 | * @throws ConstraintParameterException if the parameter is invalid |
532 | 532 | * @return EntityId[] |
533 | 533 | */ |
534 | - public function parseExceptionParameter( array $constraintParameters ) { |
|
535 | - $this->checkError( $constraintParameters ); |
|
536 | - $exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' ); |
|
537 | - if ( !array_key_exists( $exceptionId, $constraintParameters ) ) { |
|
534 | + public function parseExceptionParameter(array $constraintParameters) { |
|
535 | + $this->checkError($constraintParameters); |
|
536 | + $exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId'); |
|
537 | + if (!array_key_exists($exceptionId, $constraintParameters)) { |
|
538 | 538 | return []; |
539 | 539 | } |
540 | 540 | |
541 | 541 | return array_map( |
542 | - function( $snakSerialization ) use ( $exceptionId ) { |
|
543 | - return $this->parseEntityIdParameter( $snakSerialization, $exceptionId ); |
|
542 | + function($snakSerialization) use ($exceptionId) { |
|
543 | + return $this->parseEntityIdParameter($snakSerialization, $exceptionId); |
|
544 | 544 | }, |
545 | 545 | $constraintParameters[$exceptionId] |
546 | 546 | ); |
@@ -551,27 +551,27 @@ discard block |
||
551 | 551 | * @throws ConstraintParameterException if the parameter is invalid |
552 | 552 | * @return string|null 'mandatory' or null |
553 | 553 | */ |
554 | - public function parseConstraintStatusParameter( array $constraintParameters ) { |
|
555 | - $this->checkError( $constraintParameters ); |
|
556 | - $constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' ); |
|
557 | - if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) { |
|
554 | + public function parseConstraintStatusParameter(array $constraintParameters) { |
|
555 | + $this->checkError($constraintParameters); |
|
556 | + $constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId'); |
|
557 | + if (!array_key_exists($constraintStatusId, $constraintParameters)) { |
|
558 | 558 | return null; |
559 | 559 | } |
560 | 560 | |
561 | - $mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' ); |
|
562 | - $this->requireSingleParameter( $constraintParameters, $constraintStatusId ); |
|
563 | - $snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] ); |
|
564 | - $this->requireValueParameter( $snak, $constraintStatusId ); |
|
561 | + $mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId'); |
|
562 | + $this->requireSingleParameter($constraintParameters, $constraintStatusId); |
|
563 | + $snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]); |
|
564 | + $this->requireValueParameter($snak, $constraintStatusId); |
|
565 | 565 | $statusId = $snak->getDataValue()->getEntityId()->getSerialization(); |
566 | 566 | |
567 | - if ( $statusId === $mandatoryId ) { |
|
567 | + if ($statusId === $mandatoryId) { |
|
568 | 568 | return 'mandatory'; |
569 | 569 | } else { |
570 | 570 | throw new ConstraintParameterException( |
571 | - wfMessage( 'wbqc-violation-message-parameter-oneof' ) |
|
572 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $constraintStatusId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
573 | - ->numParams( 1 ) |
|
574 | - ->rawParams( $this->constraintParameterRenderer->formatItemIdList( [ $mandatoryId ], Role::CONSTRAINT_PARAMETER_VALUE ) ) |
|
571 | + wfMessage('wbqc-violation-message-parameter-oneof') |
|
572 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($constraintStatusId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
573 | + ->numParams(1) |
|
574 | + ->rawParams($this->constraintParameterRenderer->formatItemIdList([$mandatoryId], Role::CONSTRAINT_PARAMETER_VALUE)) |
|
575 | 575 | ->escaped() |
576 | 576 | ); |
577 | 577 | } |
@@ -584,13 +584,13 @@ discard block |
||
584 | 584 | * @return void |
585 | 585 | * @throws ConstraintParameterException |
586 | 586 | */ |
587 | - private function requireMonolingualTextParameter( DataValue $dataValue, $parameterId ) { |
|
588 | - if ( !( $dataValue instanceof MonolingualTextValue ) ) { |
|
587 | + private function requireMonolingualTextParameter(DataValue $dataValue, $parameterId) { |
|
588 | + if (!($dataValue instanceof MonolingualTextValue)) { |
|
589 | 589 | throw new ConstraintParameterException( |
590 | - wfMessage( 'wbqc-violation-message-parameter-monolingualtext' ) |
|
590 | + wfMessage('wbqc-violation-message-parameter-monolingualtext') |
|
591 | 591 | ->rawParams( |
592 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
593 | - $this->constraintParameterRenderer->formatDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
592 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
593 | + $this->constraintParameterRenderer->formatDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
594 | 594 | ) |
595 | 595 | ->escaped() |
596 | 596 | ); |
@@ -605,26 +605,26 @@ discard block |
||
605 | 605 | * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts |
606 | 606 | * @return string[] |
607 | 607 | */ |
608 | - private function parseMultilingualTextParameter( array $snakSerializations, $parameterId ) { |
|
608 | + private function parseMultilingualTextParameter(array $snakSerializations, $parameterId) { |
|
609 | 609 | $result = []; |
610 | 610 | |
611 | - foreach ( $snakSerializations as $snakSerialization ) { |
|
612 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
613 | - $this->requireValueParameter( $snak, $parameterId ); |
|
611 | + foreach ($snakSerializations as $snakSerialization) { |
|
612 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
613 | + $this->requireValueParameter($snak, $parameterId); |
|
614 | 614 | |
615 | 615 | $value = $snak->getDataValue(); |
616 | - $this->requireMonolingualTextParameter( $value, $parameterId ); |
|
616 | + $this->requireMonolingualTextParameter($value, $parameterId); |
|
617 | 617 | /** @var MonolingualTextValue $value */ |
618 | 618 | |
619 | 619 | $code = $value->getLanguageCode(); |
620 | - if ( array_key_exists( $code, $result ) ) { |
|
620 | + if (array_key_exists($code, $result)) { |
|
621 | 621 | throw new ConstraintParameterException( |
622 | - wfMessage( 'wbqc-violation-message-parameter-single-per-language' ) |
|
622 | + wfMessage('wbqc-violation-message-parameter-single-per-language') |
|
623 | 623 | ->rawParams( |
624 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
624 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
625 | 625 | ) |
626 | 626 | ->plaintextParams( |
627 | - Language::fetchLanguageName( $code ), |
|
627 | + Language::fetchLanguageName($code), |
|
628 | 628 | $code |
629 | 629 | ) |
630 | 630 | ->escaped() |
@@ -643,23 +643,23 @@ discard block |
||
643 | 643 | * @throws ConstraintParameterException if the parameter is invalid |
644 | 644 | * @return string|null |
645 | 645 | */ |
646 | - public function parseSyntaxClarificationParameter( array $constraintParameters, Language $language ) { |
|
647 | - $syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' ); |
|
646 | + public function parseSyntaxClarificationParameter(array $constraintParameters, Language $language) { |
|
647 | + $syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId'); |
|
648 | 648 | |
649 | - if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) { |
|
649 | + if (!array_key_exists($syntaxClarificationId, $constraintParameters)) { |
|
650 | 650 | return null; |
651 | 651 | } |
652 | 652 | |
653 | 653 | $languageCodes = $language->getFallbackLanguages(); |
654 | - array_unshift( $languageCodes, $language->getCode() ); |
|
654 | + array_unshift($languageCodes, $language->getCode()); |
|
655 | 655 | |
656 | 656 | $syntaxClarifications = $this->parseMultilingualTextParameter( |
657 | 657 | $constraintParameters[$syntaxClarificationId], |
658 | 658 | $syntaxClarificationId |
659 | 659 | ); |
660 | 660 | |
661 | - foreach ( $languageCodes as $languageCode ) { |
|
662 | - if ( array_key_exists( $languageCode, $syntaxClarifications ) ) { |
|
661 | + foreach ($languageCodes as $languageCode) { |
|
662 | + if (array_key_exists($languageCode, $syntaxClarifications)) { |
|
663 | 663 | return $syntaxClarifications[$languageCode]; |
664 | 664 | } |
665 | 665 | } |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | public function getDataValue() { |
147 | 147 | $mainSnak = $this->context->getSnak(); |
148 | 148 | |
149 | - if ( $mainSnak instanceof PropertyValueSnak ) { |
|
149 | + if ($mainSnak instanceof PropertyValueSnak) { |
|
150 | 150 | return $mainSnak->getDataValue(); |
151 | 151 | } |
152 | 152 | |
153 | - throw new LogicException( 'Cannot get DataValue, Snak is of type ' . $this->getSnakType() . '.' ); |
|
153 | + throw new LogicException('Cannot get DataValue, Snak is of type '.$this->getSnakType().'.'); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * @param string $key |
179 | 179 | * @param string $value |
180 | 180 | */ |
181 | - public function addParameter( $key, $value ) { |
|
181 | + public function addParameter($key, $value) { |
|
182 | 182 | $this->parameters[$key][] = $value; |
183 | 183 | } |
184 | 184 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | /** |
193 | 193 | * @param string $status |
194 | 194 | */ |
195 | - public function setStatus( $status ) { |
|
195 | + public function setStatus($status) { |
|
196 | 196 | $this->status = $status; |
197 | 197 | } |
198 | 198 | |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * @param Metadata $cm |
208 | 208 | * @return self |
209 | 209 | */ |
210 | - public function withMetadata( Metadata $cm ) { |
|
210 | + public function withMetadata(Metadata $cm) { |
|
211 | 211 | $this->metadata = $cm; |
212 | 212 | return $this; |
213 | 213 | } |
@@ -89,18 +89,18 @@ discard block |
||
89 | 89 | $this->propertyDataTypeLookup = $propertyDataTypeLookup; |
90 | 90 | $this->cache = $cache; |
91 | 91 | |
92 | - $this->entityPrefix = $rdfVocabulary->getNamespaceUri( RdfVocabulary::NS_ENTITY ); |
|
92 | + $this->entityPrefix = $rdfVocabulary->getNamespaceUri(RdfVocabulary::NS_ENTITY); |
|
93 | 93 | $this->prefixes = <<<EOT |
94 | -PREFIX wd: <{$rdfVocabulary->getNamespaceUri( RdfVocabulary::NS_ENTITY )}> |
|
95 | -PREFIX wds: <{$rdfVocabulary->getNamespaceUri( RdfVocabulary::NS_STATEMENT )}> |
|
96 | -PREFIX wdt: <{$rdfVocabulary->getNamespaceUri( RdfVocabulary::NSP_DIRECT_CLAIM )}> |
|
97 | -PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}> |
|
98 | -PREFIX p: <{$rdfVocabulary->getNamespaceUri( RdfVocabulary::NSP_CLAIM )}> |
|
99 | -PREFIX ps: <{$rdfVocabulary->getNamespaceUri( RdfVocabulary::NSP_CLAIM_STATEMENT )}> |
|
100 | -PREFIX pq: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER )}> |
|
101 | -PREFIX pqv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER_VALUE )}> |
|
102 | -PREFIX pr: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE )}> |
|
103 | -PREFIX prv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE_VALUE )}> |
|
94 | +PREFIX wd: <{$rdfVocabulary->getNamespaceUri(RdfVocabulary::NS_ENTITY)}> |
|
95 | +PREFIX wds: <{$rdfVocabulary->getNamespaceUri(RdfVocabulary::NS_STATEMENT)}> |
|
96 | +PREFIX wdt: <{$rdfVocabulary->getNamespaceUri(RdfVocabulary::NSP_DIRECT_CLAIM)}> |
|
97 | +PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}> |
|
98 | +PREFIX p: <{$rdfVocabulary->getNamespaceUri(RdfVocabulary::NSP_CLAIM)}> |
|
99 | +PREFIX ps: <{$rdfVocabulary->getNamespaceUri(RdfVocabulary::NSP_CLAIM_STATEMENT)}> |
|
100 | +PREFIX pq: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER)}> |
|
101 | +PREFIX pqv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER_VALUE)}> |
|
102 | +PREFIX pr: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE)}> |
|
103 | +PREFIX prv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE_VALUE)}> |
|
104 | 104 | PREFIX wikibase: <http://wikiba.se/ontology#> |
105 | 105 | PREFIX wikibase-beta: <http://wikiba.se/ontology-beta#> |
106 | 106 | EOT; |
@@ -117,21 +117,21 @@ discard block |
||
117 | 117 | * @return CachedBool |
118 | 118 | * @throws SparqlHelperException if the query times out or some other error occurs |
119 | 119 | */ |
120 | - public function hasType( $id, array $classes, $withInstance ) { |
|
121 | - $instanceOfId = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
122 | - $subclassOfId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
120 | + public function hasType($id, array $classes, $withInstance) { |
|
121 | + $instanceOfId = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
122 | + $subclassOfId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
123 | 123 | |
124 | - $path = ( $withInstance ? "wdt:$instanceOfId/" : "" ) . "wdt:$subclassOfId*"; |
|
124 | + $path = ($withInstance ? "wdt:$instanceOfId/" : "")."wdt:$subclassOfId*"; |
|
125 | 125 | |
126 | 126 | $metadatas = []; |
127 | 127 | |
128 | - foreach ( array_chunk( $classes, 20 ) as $classesChunk ) { |
|
129 | - $classesValues = implode( ' ', array_map( |
|
130 | - function( $class ) { |
|
131 | - return 'wd:' . $class; |
|
128 | + foreach (array_chunk($classes, 20) as $classesChunk) { |
|
129 | + $classesValues = implode(' ', array_map( |
|
130 | + function($class) { |
|
131 | + return 'wd:'.$class; |
|
132 | 132 | }, |
133 | 133 | $classesChunk |
134 | - ) ); |
|
134 | + )); |
|
135 | 135 | |
136 | 136 | $query = <<<EOF |
137 | 137 | ASK { |
@@ -142,19 +142,19 @@ discard block |
||
142 | 142 | EOF; |
143 | 143 | // TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually |
144 | 144 | |
145 | - $result = $this->runQuery( $query ); |
|
145 | + $result = $this->runQuery($query); |
|
146 | 146 | $metadatas[] = $result->getMetadata(); |
147 | - if ( $result->getArray()['boolean'] ) { |
|
147 | + if ($result->getArray()['boolean']) { |
|
148 | 148 | return new CachedBool( |
149 | 149 | true, |
150 | - Metadata::merge( $metadatas ) |
|
150 | + Metadata::merge($metadatas) |
|
151 | 151 | ); |
152 | 152 | } |
153 | 153 | } |
154 | 154 | |
155 | 155 | return new CachedBool( |
156 | 156 | false, |
157 | - Metadata::merge( $metadatas ) |
|
157 | + Metadata::merge($metadatas) |
|
158 | 158 | ); |
159 | 159 | } |
160 | 160 | |
@@ -170,10 +170,10 @@ discard block |
||
170 | 170 | $ignoreDeprecatedStatements |
171 | 171 | ) { |
172 | 172 | $pid = $statement->getPropertyId()->serialize(); |
173 | - $guid = str_replace( '$', '-', $statement->getGuid() ); |
|
173 | + $guid = str_replace('$', '-', $statement->getGuid()); |
|
174 | 174 | |
175 | 175 | $deprecatedFilter = ''; |
176 | - if ( $ignoreDeprecatedStatements ) { |
|
176 | + if ($ignoreDeprecatedStatements) { |
|
177 | 177 | $deprecatedFilter .= 'MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }'; |
178 | 178 | $deprecatedFilter .= 'MINUS { ?otherStatement wikibase-beta:rank wikibase-beta:DeprecatedRank. }'; |
179 | 179 | } |
@@ -193,9 +193,9 @@ discard block |
||
193 | 193 | LIMIT 10 |
194 | 194 | EOF; |
195 | 195 | |
196 | - $result = $this->runQuery( $query ); |
|
196 | + $result = $this->runQuery($query); |
|
197 | 197 | |
198 | - return $this->getOtherEntities( $result ); |
|
198 | + return $this->getOtherEntities($result); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -220,16 +220,15 @@ discard block |
||
220 | 220 | $dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty( |
221 | 221 | $snak->getPropertyId() |
222 | 222 | ); |
223 | - list ( $value, $isFullValue ) = $this->getRdfLiteral( $dataType, $dataValue ); |
|
224 | - if ( $isFullValue ) { |
|
223 | + list ($value, $isFullValue) = $this->getRdfLiteral($dataType, $dataValue); |
|
224 | + if ($isFullValue) { |
|
225 | 225 | $prefix .= 'v'; |
226 | 226 | } |
227 | 227 | $path = $type === Context::TYPE_QUALIFIER ? |
228 | - "$prefix:$pid" : |
|
229 | - "prov:wasDerivedFrom/$prefix:$pid"; |
|
228 | + "$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid"; |
|
230 | 229 | |
231 | 230 | $deprecatedFilter = ''; |
232 | - if ( $ignoreDeprecatedStatements ) { |
|
231 | + if ($ignoreDeprecatedStatements) { |
|
233 | 232 | $deprecatedFilter = <<< EOF |
234 | 233 | MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. } |
235 | 234 | MINUS { ?otherStatement wikibase-beta:rank wikibase-beta:DeprecatedRank. } |
@@ -250,9 +249,9 @@ discard block |
||
250 | 249 | LIMIT 10 |
251 | 250 | EOF; |
252 | 251 | |
253 | - $result = $this->runQuery( $query ); |
|
252 | + $result = $this->runQuery($query); |
|
254 | 253 | |
255 | - return $this->getOtherEntities( $result ); |
|
254 | + return $this->getOtherEntities($result); |
|
256 | 255 | } |
257 | 256 | |
258 | 257 | /** |
@@ -262,8 +261,8 @@ discard block |
||
262 | 261 | * |
263 | 262 | * @return string |
264 | 263 | */ |
265 | - private function stringLiteral( $text ) { |
|
266 | - return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"'; |
|
264 | + private function stringLiteral($text) { |
|
265 | + return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"'; |
|
267 | 266 | } |
268 | 267 | |
269 | 268 | /** |
@@ -273,17 +272,17 @@ discard block |
||
273 | 272 | * |
274 | 273 | * @return CachedEntityIds |
275 | 274 | */ |
276 | - private function getOtherEntities( CachedQueryResults $results ) { |
|
277 | - return new CachedEntityIds( array_map( |
|
278 | - function ( $resultBindings ) { |
|
275 | + private function getOtherEntities(CachedQueryResults $results) { |
|
276 | + return new CachedEntityIds(array_map( |
|
277 | + function($resultBindings) { |
|
279 | 278 | $entityIRI = $resultBindings['otherEntity']['value']; |
280 | - $entityPrefixLength = strlen( $this->entityPrefix ); |
|
281 | - if ( substr( $entityIRI, 0, $entityPrefixLength ) === $this->entityPrefix ) { |
|
279 | + $entityPrefixLength = strlen($this->entityPrefix); |
|
280 | + if (substr($entityIRI, 0, $entityPrefixLength) === $this->entityPrefix) { |
|
282 | 281 | try { |
283 | 282 | return $this->entityIdParser->parse( |
284 | - substr( $entityIRI, $entityPrefixLength ) |
|
283 | + substr($entityIRI, $entityPrefixLength) |
|
285 | 284 | ); |
286 | - } catch ( EntityIdParsingException $e ) { |
|
285 | + } catch (EntityIdParsingException $e) { |
|
287 | 286 | // fall through |
288 | 287 | } |
289 | 288 | } |
@@ -291,7 +290,7 @@ discard block |
||
291 | 290 | return null; |
292 | 291 | }, |
293 | 292 | $results->getArray()['results']['bindings'] |
294 | - ), $results->getMetadata() ); |
|
293 | + ), $results->getMetadata()); |
|
295 | 294 | } |
296 | 295 | |
297 | 296 | // @codingStandardsIgnoreStart cyclomatic complexity of this function is too high |
@@ -304,47 +303,47 @@ discard block |
||
304 | 303 | * @return array the literal or IRI as a string in SPARQL syntax, |
305 | 304 | * and a boolean indicating whether it refers to a full value node or not |
306 | 305 | */ |
307 | - private function getRdfLiteral( $dataType, DataValue $dataValue ) { |
|
308 | - switch ( $dataType ) { |
|
306 | + private function getRdfLiteral($dataType, DataValue $dataValue) { |
|
307 | + switch ($dataType) { |
|
309 | 308 | case 'string': |
310 | 309 | case 'external-id': |
311 | - return [ $this->stringLiteral( $dataValue->getValue() ), false ]; |
|
310 | + return [$this->stringLiteral($dataValue->getValue()), false]; |
|
312 | 311 | case 'commonsMedia': |
313 | - $url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() ); |
|
314 | - return [ '<' . $url . '>', false ]; |
|
312 | + $url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue()); |
|
313 | + return ['<'.$url.'>', false]; |
|
315 | 314 | case 'geo-shape': |
316 | - $url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() ); |
|
317 | - return [ '<' . $url . '>', false ]; |
|
315 | + $url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue()); |
|
316 | + return ['<'.$url.'>', false]; |
|
318 | 317 | case 'tabular-data': |
319 | - $url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() ); |
|
320 | - return [ '<' . $url . '>', false ]; |
|
318 | + $url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue()); |
|
319 | + return ['<'.$url.'>', false]; |
|
321 | 320 | case 'url': |
322 | 321 | $url = $dataValue->getValue(); |
323 | - if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) { |
|
322 | + if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) { |
|
324 | 323 | // not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF) |
325 | 324 | // such an URL should never reach us, so just throw |
326 | - throw new InvalidArgumentException( 'invalid URL: ' . $url ); |
|
325 | + throw new InvalidArgumentException('invalid URL: '.$url); |
|
327 | 326 | } |
328 | - return [ '<' . $url . '>', false ]; |
|
327 | + return ['<'.$url.'>', false]; |
|
329 | 328 | case 'wikibase-item': |
330 | 329 | case 'wikibase-property': |
331 | 330 | /** @var EntityIdValue $dataValue */ |
332 | - return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ]; |
|
331 | + return ['wd:'.$dataValue->getEntityId()->getSerialization(), false]; |
|
333 | 332 | case 'monolingualtext': |
334 | 333 | /** @var MonolingualTextValue $dataValue */ |
335 | 334 | $lang = $dataValue->getLanguageCode(); |
336 | - if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) { |
|
335 | + if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) { |
|
337 | 336 | // not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG) |
338 | 337 | // such a language tag should never reach us, so just throw |
339 | - throw new InvalidArgumentException( 'invalid language tag: ' . $lang ); |
|
338 | + throw new InvalidArgumentException('invalid language tag: '.$lang); |
|
340 | 339 | } |
341 | - return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ]; |
|
340 | + return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false]; |
|
342 | 341 | case 'globe-coordinate': |
343 | 342 | case 'quantity': |
344 | 343 | case 'time': |
345 | - return [ 'wdv:' . $dataValue->getHash(), true ]; |
|
344 | + return ['wdv:'.$dataValue->getHash(), true]; |
|
346 | 345 | default: |
347 | - throw new InvalidArgumentException( 'unknown data type: ' . $dataType ); |
|
346 | + throw new InvalidArgumentException('unknown data type: '.$dataType); |
|
348 | 347 | } |
349 | 348 | } |
350 | 349 | // @codingStandardsIgnoreEnd |
@@ -357,41 +356,41 @@ discard block |
||
357 | 356 | * @throws SparqlHelperException if the query times out or some other error occurs |
358 | 357 | * @throws ConstraintParameterException if the $regex is invalid |
359 | 358 | */ |
360 | - public function matchesRegularExpression( $text, $regex ) { |
|
359 | + public function matchesRegularExpression($text, $regex) { |
|
361 | 360 | // caching wrapper around matchesRegularExpressionWithSparql |
362 | 361 | |
363 | - $textHash = hash( 'sha256', $text ); |
|
364 | - $cacheMapSize = $this->config->get( 'WBQualityConstraintsFormatCacheMapSize' ); |
|
362 | + $textHash = hash('sha256', $text); |
|
363 | + $cacheMapSize = $this->config->get('WBQualityConstraintsFormatCacheMapSize'); |
|
365 | 364 | |
366 | 365 | $cacheMapArray = $this->cache->getWithSetCallback( |
367 | 366 | $this->cache->makeKey( |
368 | 367 | 'WikibaseQualityConstraints', // extension |
369 | 368 | 'regex', // action |
370 | 369 | 'WDQS-Java', // regex flavor |
371 | - hash( 'sha256', $regex ) |
|
370 | + hash('sha256', $regex) |
|
372 | 371 | ), |
373 | 372 | WANObjectCache::TTL_DAY, |
374 | - function( $cacheMapArray ) use ( $text, $regex, $textHash, $cacheMapSize ) { |
|
373 | + function($cacheMapArray) use ($text, $regex, $textHash, $cacheMapSize) { |
|
375 | 374 | // Initialize the cache map if not set |
376 | - if ( $cacheMapArray === false ) { |
|
375 | + if ($cacheMapArray === false) { |
|
377 | 376 | $key = 'wikibase.quality.constraints.regex.cache.refresh.init'; |
378 | - $this->dataFactory->increment( $key ); |
|
377 | + $this->dataFactory->increment($key); |
|
379 | 378 | return []; |
380 | 379 | } |
381 | 380 | |
382 | 381 | $key = 'wikibase.quality.constraints.regex.cache.refresh'; |
383 | - $this->dataFactory->increment( $key ); |
|
384 | - $cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $cacheMapSize ); |
|
385 | - if ( $cacheMap->has( $textHash ) ) { |
|
382 | + $this->dataFactory->increment($key); |
|
383 | + $cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $cacheMapSize); |
|
384 | + if ($cacheMap->has($textHash)) { |
|
386 | 385 | $key = 'wikibase.quality.constraints.regex.cache.refresh.hit'; |
387 | - $this->dataFactory->increment( $key ); |
|
388 | - $cacheMap->get( $textHash ); // ping cache |
|
386 | + $this->dataFactory->increment($key); |
|
387 | + $cacheMap->get($textHash); // ping cache |
|
389 | 388 | } else { |
390 | 389 | $key = 'wikibase.quality.constraints.regex.cache.refresh.miss'; |
391 | - $this->dataFactory->increment( $key ); |
|
390 | + $this->dataFactory->increment($key); |
|
392 | 391 | $cacheMap->set( |
393 | 392 | $textHash, |
394 | - $this->matchesRegularExpressionWithSparql( $text, $regex ), |
|
393 | + $this->matchesRegularExpressionWithSparql($text, $regex), |
|
395 | 394 | 3 / 8 |
396 | 395 | ); |
397 | 396 | } |
@@ -409,14 +408,14 @@ discard block |
||
409 | 408 | ] |
410 | 409 | ); |
411 | 410 | |
412 | - if ( isset( $cacheMapArray[$textHash] ) ) { |
|
411 | + if (isset($cacheMapArray[$textHash])) { |
|
413 | 412 | $key = 'wikibase.quality.constraints.regex.cache.hit'; |
414 | - $this->dataFactory->increment( $key ); |
|
413 | + $this->dataFactory->increment($key); |
|
415 | 414 | return $cacheMapArray[$textHash]; |
416 | 415 | } else { |
417 | 416 | $key = 'wikibase.quality.constraints.regex.cache.miss'; |
418 | - $this->dataFactory->increment( $key ); |
|
419 | - return $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
417 | + $this->dataFactory->increment($key); |
|
418 | + return $this->matchesRegularExpressionWithSparql($text, $regex); |
|
420 | 419 | } |
421 | 420 | } |
422 | 421 | |
@@ -431,26 +430,26 @@ discard block |
||
431 | 430 | * @throws SparqlHelperException if the query times out or some other error occurs |
432 | 431 | * @throws ConstraintParameterException if the $regex is invalid |
433 | 432 | */ |
434 | - public function matchesRegularExpressionWithSparql( $text, $regex ) { |
|
435 | - $textStringLiteral = $this->stringLiteral( $text ); |
|
436 | - $regexStringLiteral = $this->stringLiteral( '^' . $regex . '$' ); |
|
433 | + public function matchesRegularExpressionWithSparql($text, $regex) { |
|
434 | + $textStringLiteral = $this->stringLiteral($text); |
|
435 | + $regexStringLiteral = $this->stringLiteral('^'.$regex.'$'); |
|
437 | 436 | |
438 | 437 | $query = <<<EOF |
439 | 438 | SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {} |
440 | 439 | EOF; |
441 | 440 | |
442 | - $result = $this->runQuery( $query ); |
|
441 | + $result = $this->runQuery($query); |
|
443 | 442 | |
444 | 443 | $vars = $result->getArray()['results']['bindings'][0]; |
445 | - if ( array_key_exists( 'matches', $vars ) ) { |
|
444 | + if (array_key_exists('matches', $vars)) { |
|
446 | 445 | // true or false ⇒ regex okay, text matches or not |
447 | 446 | return $vars['matches']['value'] === 'true'; |
448 | 447 | } else { |
449 | 448 | // empty result: regex broken |
450 | 449 | throw new ConstraintParameterException( |
451 | - wfMessage( 'wbqc-violation-message-parameter-regex' ) |
|
452 | - ->rawParams( ConstraintParameterRenderer::formatByRole( Role::CONSTRAINT_PARAMETER_VALUE, |
|
453 | - '<code><nowiki>' . htmlspecialchars( $regex ) . '</nowiki></code>' ) ) |
|
450 | + wfMessage('wbqc-violation-message-parameter-regex') |
|
451 | + ->rawParams(ConstraintParameterRenderer::formatByRole(Role::CONSTRAINT_PARAMETER_VALUE, |
|
452 | + '<code><nowiki>'.htmlspecialchars($regex).'</nowiki></code>')) |
|
454 | 453 | ->escaped() |
455 | 454 | ); |
456 | 455 | } |
@@ -463,14 +462,14 @@ discard block |
||
463 | 462 | * |
464 | 463 | * @return boolean |
465 | 464 | */ |
466 | - public function isTimeout( $responseContent ) { |
|
467 | - $timeoutRegex = implode( '|', array_map( |
|
468 | - function ( $fqn ) { |
|
469 | - return preg_quote( $fqn, '/' ); |
|
465 | + public function isTimeout($responseContent) { |
|
466 | + $timeoutRegex = implode('|', array_map( |
|
467 | + function($fqn) { |
|
468 | + return preg_quote($fqn, '/'); |
|
470 | 469 | }, |
471 | - $this->config->get( 'WBQualityConstraintsSparqlTimeoutExceptionClasses' ) |
|
472 | - ) ); |
|
473 | - return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent ); |
|
470 | + $this->config->get('WBQualityConstraintsSparqlTimeoutExceptionClasses') |
|
471 | + )); |
|
472 | + return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent); |
|
474 | 473 | } |
475 | 474 | |
476 | 475 | /** |
@@ -482,17 +481,17 @@ discard block |
||
482 | 481 | * @return integer|boolean the max-age (in seconds) |
483 | 482 | * or a plain boolean if no max-age can be determined |
484 | 483 | */ |
485 | - public function getCacheMaxAge( $responseHeaders ) { |
|
484 | + public function getCacheMaxAge($responseHeaders) { |
|
486 | 485 | if ( |
487 | - array_key_exists( 'x-cache-status', $responseHeaders ) && |
|
488 | - preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] ) |
|
486 | + array_key_exists('x-cache-status', $responseHeaders) && |
|
487 | + preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0]) |
|
489 | 488 | ) { |
490 | 489 | $maxage = []; |
491 | 490 | if ( |
492 | - array_key_exists( 'cache-control', $responseHeaders ) && |
|
493 | - preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage ) |
|
491 | + array_key_exists('cache-control', $responseHeaders) && |
|
492 | + preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage) |
|
494 | 493 | ) { |
495 | - return intval( $maxage[1] ); |
|
494 | + return intval($maxage[1]); |
|
496 | 495 | } else { |
497 | 496 | return true; |
498 | 497 | } |
@@ -510,59 +509,58 @@ discard block |
||
510 | 509 | * |
511 | 510 | * @throws SparqlHelperException if the query times out or some other error occurs |
512 | 511 | */ |
513 | - public function runQuery( $query ) { |
|
512 | + public function runQuery($query) { |
|
514 | 513 | |
515 | - $endpoint = $this->config->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
516 | - $maxQueryTimeMillis = $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' ); |
|
517 | - $url = $endpoint . '?' . http_build_query( |
|
514 | + $endpoint = $this->config->get('WBQualityConstraintsSparqlEndpoint'); |
|
515 | + $maxQueryTimeMillis = $this->config->get('WBQualityConstraintsSparqlMaxMillis'); |
|
516 | + $url = $endpoint.'?'.http_build_query( |
|
518 | 517 | [ |
519 | - 'query' => "#wbqc\n" . $this->prefixes . $query, |
|
518 | + 'query' => "#wbqc\n".$this->prefixes.$query, |
|
520 | 519 | 'format' => 'json', |
521 | 520 | 'maxQueryTimeMillis' => $maxQueryTimeMillis, |
522 | 521 | ], |
523 | - null, ini_get( 'arg_separator.output' ), |
|
522 | + null, ini_get('arg_separator.output'), |
|
524 | 523 | // encode spaces with %20, not + |
525 | 524 | PHP_QUERY_RFC3986 |
526 | 525 | ); |
527 | 526 | |
528 | 527 | $options = [ |
529 | 528 | 'method' => 'GET', |
530 | - 'timeout' => (int)round( ( $maxQueryTimeMillis + 1000 ) / 1000 ), |
|
529 | + 'timeout' => (int) round(($maxQueryTimeMillis + 1000) / 1000), |
|
531 | 530 | 'connectTimeout' => 'default', |
532 | 531 | ]; |
533 | - $request = MWHttpRequest::factory( $url, $options ); |
|
534 | - $startTime = microtime( true ); |
|
532 | + $request = MWHttpRequest::factory($url, $options); |
|
533 | + $startTime = microtime(true); |
|
535 | 534 | $status = $request->execute(); |
536 | - $endTime = microtime( true ); |
|
535 | + $endTime = microtime(true); |
|
537 | 536 | $this->dataFactory->timing( |
538 | 537 | 'wikibase.quality.constraints.sparql.timing', |
539 | - ( $endTime - $startTime ) * 1000 |
|
538 | + ($endTime - $startTime) * 1000 |
|
540 | 539 | ); |
541 | 540 | |
542 | - $maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() ); |
|
543 | - if ( $maxAge ) { |
|
544 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' ); |
|
541 | + $maxAge = $this->getCacheMaxAge($request->getResponseHeaders()); |
|
542 | + if ($maxAge) { |
|
543 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.cached'); |
|
545 | 544 | } |
546 | 545 | |
547 | - if ( $status->isOk() ) { |
|
546 | + if ($status->isOk()) { |
|
548 | 547 | $json = $request->getContent(); |
549 | - $arr = json_decode( $json, true ); |
|
548 | + $arr = json_decode($json, true); |
|
550 | 549 | return new CachedQueryResults( |
551 | 550 | $arr, |
552 | 551 | Metadata::ofCachingMetadata( |
553 | 552 | $maxAge ? |
554 | - CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) : |
|
555 | - CachingMetadata::fresh() |
|
553 | + CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh() |
|
556 | 554 | ) |
557 | 555 | ); |
558 | 556 | } else { |
559 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' ); |
|
557 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.error'); |
|
560 | 558 | |
561 | 559 | $this->dataFactory->increment( |
562 | 560 | "wikibase.quality.constraints.sparql.error.http.{$request->getStatus()}" |
563 | 561 | ); |
564 | 562 | |
565 | - if ( $this->isTimeout( $request->getContent() ) ) { |
|
563 | + if ($this->isTimeout($request->getContent())) { |
|
566 | 564 | $this->dataFactory->increment( |
567 | 565 | 'wikibase.quality.constraints.sparql.error.timeout' |
568 | 566 | ); |
@@ -79,23 +79,23 @@ discard block |
||
79 | 79 | * @return bool |
80 | 80 | * @throws OverflowException if $entitiesChecked exceeds the configured limit |
81 | 81 | */ |
82 | - private function isSubclassOf( EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0 ) { |
|
83 | - $maxEntities = $this->config->get( 'WBQualityConstraintsTypeCheckMaxEntities' ); |
|
82 | + private function isSubclassOf(EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0) { |
|
83 | + $maxEntities = $this->config->get('WBQualityConstraintsTypeCheckMaxEntities'); |
|
84 | 84 | if ( ++$entitiesChecked > $maxEntities ) { |
85 | - throw new OverflowException( 'Too many entities to check' ); |
|
85 | + throw new OverflowException('Too many entities to check'); |
|
86 | 86 | } |
87 | 87 | |
88 | - $item = $this->entityLookup->getEntity( $comparativeClass ); |
|
89 | - if ( !( $item instanceof StatementListProvider ) ) { |
|
88 | + $item = $this->entityLookup->getEntity($comparativeClass); |
|
89 | + if (!($item instanceof StatementListProvider)) { |
|
90 | 90 | return false; // lookup failed, probably because item doesn't exist |
91 | 91 | } |
92 | 92 | |
93 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
93 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
94 | 94 | /** @var Statement $statement */ |
95 | - foreach ( $item->getStatements()->getByPropertyId( new PropertyId( $subclassId ) ) as $statement ) { |
|
95 | + foreach ($item->getStatements()->getByPropertyId(new PropertyId($subclassId)) as $statement) { |
|
96 | 96 | $mainSnak = $statement->getMainSnak(); |
97 | 97 | |
98 | - if ( !( $this->hasCorrectType( $mainSnak ) ) ) { |
|
98 | + if (!($this->hasCorrectType($mainSnak))) { |
|
99 | 99 | continue; |
100 | 100 | } |
101 | 101 | /** @var PropertyValueSnak $mainSnak */ |
@@ -104,11 +104,11 @@ discard block |
||
104 | 104 | $dataValue = $mainSnak->getDataValue(); |
105 | 105 | $comparativeClass = $dataValue->getEntityId(); |
106 | 106 | |
107 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
107 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
108 | 108 | return true; |
109 | 109 | } |
110 | 110 | |
111 | - if ( $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ) ) { |
|
111 | + if ($this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked)) { |
|
112 | 112 | return true; |
113 | 113 | } |
114 | 114 | } |
@@ -129,23 +129,23 @@ discard block |
||
129 | 129 | * @return CachedBool |
130 | 130 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
131 | 131 | */ |
132 | - public function isSubclassOfWithSparqlFallback( EntityId $comparativeClass, array $classesToCheck ) { |
|
132 | + public function isSubclassOfWithSparqlFallback(EntityId $comparativeClass, array $classesToCheck) { |
|
133 | 133 | try { |
134 | 134 | return new CachedBool( |
135 | - $this->isSubclassOf( $comparativeClass, $classesToCheck ), |
|
135 | + $this->isSubclassOf($comparativeClass, $classesToCheck), |
|
136 | 136 | Metadata::blank() |
137 | 137 | ); |
138 | - } catch ( OverflowException $e ) { |
|
139 | - if ( $this->sparqlHelper !== null ) { |
|
138 | + } catch (OverflowException $e) { |
|
139 | + if ($this->sparqlHelper !== null) { |
|
140 | 140 | MediaWikiServices::getInstance()->getStatsdDataFactory() |
141 | - ->increment( 'wikibase.quality.constraints.sparql.typeFallback' ); |
|
141 | + ->increment('wikibase.quality.constraints.sparql.typeFallback'); |
|
142 | 142 | return $this->sparqlHelper->hasType( |
143 | 143 | $comparativeClass->getSerialization(), |
144 | 144 | $classesToCheck, |
145 | 145 | /* withInstance = */ false |
146 | 146 | ); |
147 | 147 | } else { |
148 | - return new CachedBool( false, Metadata::blank() ); |
|
148 | + return new CachedBool(false, Metadata::blank()); |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | } |
@@ -163,14 +163,14 @@ discard block |
||
163 | 163 | * @return CachedBool |
164 | 164 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
165 | 165 | */ |
166 | - public function hasClassInRelation( StatementList $statements, $relationId, array $classesToCheck ) { |
|
166 | + public function hasClassInRelation(StatementList $statements, $relationId, array $classesToCheck) { |
|
167 | 167 | $metadatas = []; |
168 | 168 | |
169 | 169 | /** @var Statement $statement */ |
170 | - foreach ( $statements->getByPropertyId( new PropertyId( $relationId ) ) as $statement ) { |
|
170 | + foreach ($statements->getByPropertyId(new PropertyId($relationId)) as $statement) { |
|
171 | 171 | $mainSnak = $statement->getMainSnak(); |
172 | 172 | |
173 | - if ( !$this->hasCorrectType( $mainSnak ) ) { |
|
173 | + if (!$this->hasCorrectType($mainSnak)) { |
|
174 | 174 | continue; |
175 | 175 | } |
176 | 176 | /** @var PropertyValueSnak $mainSnak */ |
@@ -179,28 +179,28 @@ discard block |
||
179 | 179 | $dataValue = $mainSnak->getDataValue(); |
180 | 180 | $comparativeClass = $dataValue->getEntityId(); |
181 | 181 | |
182 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
182 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
183 | 183 | // discard $metadatas, we know this is fresh |
184 | - return new CachedBool( true, Metadata::blank() ); |
|
184 | + return new CachedBool(true, Metadata::blank()); |
|
185 | 185 | } |
186 | 186 | |
187 | - $result = $this->isSubclassOfWithSparqlFallback( $comparativeClass, $classesToCheck ); |
|
187 | + $result = $this->isSubclassOfWithSparqlFallback($comparativeClass, $classesToCheck); |
|
188 | 188 | $metadatas[] = $result->getMetadata(); |
189 | - if ( $result->getBool() ) { |
|
189 | + if ($result->getBool()) { |
|
190 | 190 | return new CachedBool( |
191 | 191 | true, |
192 | - Metadata::merge( $metadatas ) |
|
192 | + Metadata::merge($metadatas) |
|
193 | 193 | ); |
194 | 194 | } |
195 | 195 | } |
196 | 196 | |
197 | 197 | return new CachedBool( |
198 | 198 | false, |
199 | - Metadata::merge( $metadatas ) |
|
199 | + Metadata::merge($metadatas) |
|
200 | 200 | ); |
201 | 201 | } |
202 | 202 | |
203 | - private function hasCorrectType( Snak $mainSnak ) { |
|
203 | + private function hasCorrectType(Snak $mainSnak) { |
|
204 | 204 | return $mainSnak instanceof PropertyValueSnak |
205 | 205 | && $mainSnak->getDataValue()->getType() === 'wikibase-entityid'; |
206 | 206 | } |
@@ -214,20 +214,20 @@ discard block |
||
214 | 214 | * |
215 | 215 | * @return string Localized HTML message |
216 | 216 | */ |
217 | - public function getViolationMessage( PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation ) { |
|
217 | + public function getViolationMessage(PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation) { |
|
218 | 218 | // Possible messages: |
219 | 219 | // wbqc-violation-message-type-instance |
220 | 220 | // wbqc-violation-message-type-subclass |
221 | 221 | // wbqc-violation-message-valueType-instance |
222 | 222 | // wbqc-violation-message-valueType-subclass |
223 | - $message = wfMessage( 'wbqc-violation-message-' . $checker . '-' . $relation ); |
|
223 | + $message = wfMessage('wbqc-violation-message-'.$checker.'-'.$relation); |
|
224 | 224 | |
225 | 225 | $message->rawParams( |
226 | - $this->constraintParameterRenderer->formatEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ), |
|
227 | - $this->constraintParameterRenderer->formatEntityId( $entityId, Role::SUBJECT ) |
|
226 | + $this->constraintParameterRenderer->formatEntityId($propertyId, Role::CONSTRAINT_PROPERTY), |
|
227 | + $this->constraintParameterRenderer->formatEntityId($entityId, Role::SUBJECT) |
|
228 | 228 | ); |
229 | - $message->numParams( count( $classes ) ); |
|
230 | - $message->rawParams( $this->constraintParameterRenderer->formatItemIdList( $classes, Role::OBJECT ) ); |
|
229 | + $message->numParams(count($classes)); |
|
230 | + $message->rawParams($this->constraintParameterRenderer->formatItemIdList($classes, Role::OBJECT)); |
|
231 | 231 | |
232 | 232 | return $message->escaped(); |
233 | 233 | } |
@@ -51,22 +51,22 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
53 | 53 | */ |
54 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
55 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
56 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
54 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
55 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
56 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | $parameters = []; |
60 | 60 | |
61 | - if ( $this->sparqlHelper !== null ) { |
|
62 | - if ( $context->getType() === 'statement' ) { |
|
61 | + if ($this->sparqlHelper !== null) { |
|
62 | + if ($context->getType() === 'statement') { |
|
63 | 63 | $result = $this->sparqlHelper->findEntitiesWithSameStatement( |
64 | 64 | $context->getSnakStatement(), |
65 | 65 | true // ignore deprecated statements |
66 | 66 | ); |
67 | 67 | } else { |
68 | - if ( $context->getSnak()->getType() !== 'value' ) { |
|
69 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
68 | + if ($context->getSnak()->getType() !== 'value') { |
|
69 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
70 | 70 | } |
71 | 71 | $result = $this->sparqlHelper->findEntitiesWithSameQualifierOrReference( |
72 | 72 | $context->getEntity()->getId(), |
@@ -79,29 +79,29 @@ discard block |
||
79 | 79 | $otherEntities = $result->getArray(); |
80 | 80 | $metadata = $result->getMetadata(); |
81 | 81 | |
82 | - if ( $otherEntities === [] ) { |
|
82 | + if ($otherEntities === []) { |
|
83 | 83 | $status = CheckResult::STATUS_COMPLIANCE; |
84 | 84 | $message = ''; |
85 | 85 | } else { |
86 | 86 | $status = CheckResult::STATUS_VIOLATION; |
87 | - $message = wfMessage( 'wbqc-violation-message-unique-value' ) |
|
88 | - ->numParams( count( $otherEntities ) ) |
|
89 | - ->rawParams( $this->constraintParameterRenderer->formatEntityIdList( $otherEntities, Role::SUBJECT ) ) |
|
87 | + $message = wfMessage('wbqc-violation-message-unique-value') |
|
88 | + ->numParams(count($otherEntities)) |
|
89 | + ->rawParams($this->constraintParameterRenderer->formatEntityIdList($otherEntities, Role::SUBJECT)) |
|
90 | 90 | ->escaped(); |
91 | 91 | } |
92 | 92 | } else { |
93 | 93 | $status = CheckResult::STATUS_TODO; |
94 | - $message = wfMessage( "wbqc-violation-message-not-yet-implemented" ) |
|
95 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ) ) |
|
94 | + $message = wfMessage("wbqc-violation-message-not-yet-implemented") |
|
95 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM)) |
|
96 | 96 | ->escaped(); |
97 | 97 | $metadata = Metadata::blank(); |
98 | 98 | } |
99 | 99 | |
100 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
101 | - ->withMetadata( $metadata ); |
|
100 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
101 | + ->withMetadata($metadata); |
|
102 | 102 | } |
103 | 103 | |
104 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
104 | + public function checkConstraintParameters(Constraint $constraint) { |
|
105 | 105 | // no parameters |
106 | 106 | return []; |
107 | 107 | } |
@@ -70,25 +70,25 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return CheckResult |
72 | 72 | */ |
73 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
74 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
75 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
73 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
74 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
75 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
76 | 76 | } |
77 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
78 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK ); |
|
77 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
78 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | $parameters = []; |
82 | 82 | $constraintParameters = $constraint->getConstraintParameters(); |
83 | 83 | |
84 | - $propertyId = $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
85 | - $parameters['property'] = [ $propertyId ]; |
|
84 | + $propertyId = $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
85 | + $parameters['property'] = [$propertyId]; |
|
86 | 86 | |
87 | 87 | $snak = $context->getSnak(); |
88 | 88 | |
89 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
89 | + if (!$snak instanceof PropertyValueSnak) { |
|
90 | 90 | // nothing to check |
91 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
91 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | $dataValue = $snak->getDataValue(); |
@@ -97,22 +97,22 @@ discard block |
||
97 | 97 | * error handling: |
98 | 98 | * type of $dataValue for properties with 'Inverse' constraint has to be 'wikibase-entityid' |
99 | 99 | */ |
100 | - if ( $dataValue->getType() !== 'wikibase-entityid' ) { |
|
101 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
100 | + if ($dataValue->getType() !== 'wikibase-entityid') { |
|
101 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
102 | 102 | ->rawParams( |
103 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
103 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
104 | 104 | 'wikibase-entityid' // TODO is there a message for this type so we can localize it? |
105 | 105 | ) |
106 | 106 | ->escaped(); |
107 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
107 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
108 | 108 | } |
109 | 109 | /** @var EntityIdValue $dataValue */ |
110 | 110 | |
111 | 111 | $targetEntityId = $dataValue->getEntityId(); |
112 | - $targetEntity = $this->entityLookup->getEntity( $targetEntityId ); |
|
113 | - if ( $targetEntity === null ) { |
|
114 | - $message = wfMessage( "wbqc-violation-message-target-entity-must-exist" )->escaped(); |
|
115 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
112 | + $targetEntity = $this->entityLookup->getEntity($targetEntityId); |
|
113 | + if ($targetEntity === null) { |
|
114 | + $message = wfMessage("wbqc-violation-message-target-entity-must-exist")->escaped(); |
|
115 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | $inverseStatement = $this->connectionCheckerHelper->findStatementWithPropertyAndEntityIdValue( |
@@ -120,31 +120,31 @@ discard block |
||
120 | 120 | $propertyId, |
121 | 121 | $context->getEntity()->getId() |
122 | 122 | ); |
123 | - if ( $inverseStatement !== null ) { |
|
123 | + if ($inverseStatement !== null) { |
|
124 | 124 | $message = ''; |
125 | 125 | $status = CheckResult::STATUS_COMPLIANCE; |
126 | 126 | } else { |
127 | - $message = wfMessage( 'wbqc-violation-message-inverse' ) |
|
127 | + $message = wfMessage('wbqc-violation-message-inverse') |
|
128 | 128 | ->rawParams( |
129 | - $this->constraintParameterRenderer->formatEntityId( $targetEntityId, Role::SUBJECT ), |
|
130 | - $this->constraintParameterRenderer->formatEntityId( $propertyId, Role::PREDICATE ), |
|
131 | - $this->constraintParameterRenderer->formatEntityId( $context->getEntity()->getId(), Role::OBJECT ) |
|
129 | + $this->constraintParameterRenderer->formatEntityId($targetEntityId, Role::SUBJECT), |
|
130 | + $this->constraintParameterRenderer->formatEntityId($propertyId, Role::PREDICATE), |
|
131 | + $this->constraintParameterRenderer->formatEntityId($context->getEntity()->getId(), Role::OBJECT) |
|
132 | 132 | ) |
133 | 133 | ->escaped(); |
134 | 134 | $status = CheckResult::STATUS_VIOLATION; |
135 | 135 | } |
136 | 136 | |
137 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
138 | - ->withMetadata( Metadata::ofDependencyMetadata( |
|
139 | - DependencyMetadata::ofEntityId( $targetEntityId ) ) ); |
|
137 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
138 | + ->withMetadata(Metadata::ofDependencyMetadata( |
|
139 | + DependencyMetadata::ofEntityId($targetEntityId) )); |
|
140 | 140 | } |
141 | 141 | |
142 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
142 | + public function checkConstraintParameters(Constraint $constraint) { |
|
143 | 143 | $constraintParameters = $constraint->getConstraintParameters(); |
144 | 144 | $exceptions = []; |
145 | 145 | try { |
146 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
147 | - } catch ( ConstraintParameterException $e ) { |
|
146 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
147 | + } catch (ConstraintParameterException $e) { |
|
148 | 148 | $exceptions[] = $e; |
149 | 149 | } |
150 | 150 | return $exceptions; |
@@ -82,35 +82,35 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
84 | 84 | */ |
85 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
86 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
87 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
85 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
86 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
87 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | $parameters = []; |
91 | 91 | $constraintParameters = $constraint->getConstraintParameters(); |
92 | 92 | |
93 | - $classes = $this->constraintParameterParser->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
93 | + $classes = $this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
94 | 94 | $parameters['class'] = array_map( |
95 | - function( $id ) { |
|
96 | - return new ItemId( $id ); |
|
95 | + function($id) { |
|
96 | + return new ItemId($id); |
|
97 | 97 | }, |
98 | 98 | $classes |
99 | 99 | ); |
100 | 100 | |
101 | - $relation = $this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
102 | - if ( $relation === 'instance' ) { |
|
103 | - $relationId = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
104 | - } elseif ( $relation === 'subclass' ) { |
|
105 | - $relationId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
101 | + $relation = $this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
102 | + if ($relation === 'instance') { |
|
103 | + $relationId = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
104 | + } elseif ($relation === 'subclass') { |
|
105 | + $relationId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
106 | 106 | } |
107 | - $parameters['relation'] = [ $relation ]; |
|
107 | + $parameters['relation'] = [$relation]; |
|
108 | 108 | |
109 | 109 | $snak = $context->getSnak(); |
110 | 110 | |
111 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
111 | + if (!$snak instanceof PropertyValueSnak) { |
|
112 | 112 | // nothing to check |
113 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
113 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | $dataValue = $snak->getDataValue(); |
@@ -119,22 +119,22 @@ discard block |
||
119 | 119 | * error handling: |
120 | 120 | * type of $dataValue for properties with 'Value type' constraint has to be 'wikibase-entityid' |
121 | 121 | */ |
122 | - if ( $dataValue->getType() !== 'wikibase-entityid' ) { |
|
123 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
122 | + if ($dataValue->getType() !== 'wikibase-entityid') { |
|
123 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
124 | 124 | ->rawParams( |
125 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
125 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
126 | 126 | 'wikibase-entityid' // TODO is there a message for this type so we can localize it? |
127 | 127 | ) |
128 | 128 | ->escaped(); |
129 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
129 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
130 | 130 | } |
131 | 131 | /** @var EntityIdValue $dataValue */ |
132 | 132 | |
133 | - $item = $this->entityLookup->getEntity( $dataValue->getEntityId() ); |
|
133 | + $item = $this->entityLookup->getEntity($dataValue->getEntityId()); |
|
134 | 134 | |
135 | - if ( !( $item instanceof StatementListProvider ) ) { |
|
136 | - $message = wfMessage( "wbqc-violation-message-value-entity-must-exist" )->escaped(); |
|
137 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
135 | + if (!($item instanceof StatementListProvider)) { |
|
136 | + $message = wfMessage("wbqc-violation-message-value-entity-must-exist")->escaped(); |
|
137 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | $statements = $item->getStatements(); |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $classes |
146 | 146 | ); |
147 | 147 | |
148 | - if ( $result->getBool() ) { |
|
148 | + if ($result->getBool()) { |
|
149 | 149 | $message = ''; |
150 | 150 | $status = CheckResult::STATUS_COMPLIANCE; |
151 | 151 | } else { |
@@ -159,21 +159,21 @@ discard block |
||
159 | 159 | $status = CheckResult::STATUS_VIOLATION; |
160 | 160 | } |
161 | 161 | |
162 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
163 | - ->withMetadata( $result->getMetadata() ); |
|
162 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
163 | + ->withMetadata($result->getMetadata()); |
|
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->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
171 | - } catch ( ConstraintParameterException $e ) { |
|
170 | + $this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
171 | + } catch (ConstraintParameterException $e) { |
|
172 | 172 | $exceptions[] = $e; |
173 | 173 | } |
174 | 174 | try { |
175 | - $this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
176 | - } catch ( ConstraintParameterException $e ) { |
|
175 | + $this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
176 | + } catch (ConstraintParameterException $e) { |
|
177 | 177 | $exceptions[] = $e; |
178 | 178 | } |
179 | 179 | return $exceptions; |