@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | * @throws ConstraintParameterException |
85 | 85 | * @return array [ DataValue|null $min, DataValue|null $max, PropertyId $property, array $parameters ] |
86 | 86 | */ |
87 | - private function parseConstraintParameters( Constraint $constraint ) { |
|
88 | - list( $min, $max ) = $this->constraintParameterParser->parseRangeParameter( |
|
87 | + private function parseConstraintParameters(Constraint $constraint) { |
|
88 | + list($min, $max) = $this->constraintParameterParser->parseRangeParameter( |
|
89 | 89 | $constraint->getConstraintParameters(), |
90 | 90 | $constraint->getConstraintTypeItemId(), |
91 | 91 | 'quantity' |
@@ -95,15 +95,15 @@ discard block |
||
95 | 95 | $constraint->getConstraintTypeItemId() |
96 | 96 | ); |
97 | 97 | |
98 | - if ( $min !== null ) { |
|
99 | - $parameters['minimum_quantity'] = [ $min ]; |
|
98 | + if ($min !== null) { |
|
99 | + $parameters['minimum_quantity'] = [$min]; |
|
100 | 100 | } |
101 | - if ( $max !== null ) { |
|
102 | - $parameters['maximum_quantity'] = [ $max ]; |
|
101 | + if ($max !== null) { |
|
102 | + $parameters['maximum_quantity'] = [$max]; |
|
103 | 103 | } |
104 | - $parameters['property'] = [ $property ]; |
|
104 | + $parameters['property'] = [$property]; |
|
105 | 105 | |
106 | - return [ $min, $max, $property, $parameters ]; |
|
106 | + return [$min, $max, $property, $parameters]; |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -113,13 +113,13 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @return bool |
115 | 115 | */ |
116 | - private function rangeInYears( $min, $max ) { |
|
117 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
116 | + private function rangeInYears($min, $max) { |
|
117 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
118 | 118 | |
119 | - if ( $min !== null && $min->getUnit() === $yearUnit ) { |
|
119 | + if ($min !== null && $min->getUnit() === $yearUnit) { |
|
120 | 120 | return true; |
121 | 121 | } |
122 | - if ( $max !== null && $max->getUnit() === $yearUnit ) { |
|
122 | + if ($max !== null && $max->getUnit() === $yearUnit) { |
|
123 | 123 | return true; |
124 | 124 | } |
125 | 125 | |
@@ -135,59 +135,58 @@ discard block |
||
135 | 135 | * @throws ConstraintParameterException |
136 | 136 | * @return CheckResult |
137 | 137 | */ |
138 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
139 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
140 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
138 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
139 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
140 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | $parameters = []; |
144 | 144 | |
145 | 145 | $snak = $context->getSnak(); |
146 | 146 | |
147 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
147 | + if (!$snak instanceof PropertyValueSnak) { |
|
148 | 148 | // nothing to check |
149 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
149 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | $minuend = $snak->getDataValue(); |
153 | 153 | |
154 | 154 | /** @var PropertyId $property */ |
155 | - list( $min, $max, $property, $parameters ) = $this->parseConstraintParameters( $constraint ); |
|
155 | + list($min, $max, $property, $parameters) = $this->parseConstraintParameters($constraint); |
|
156 | 156 | |
157 | 157 | // checks only the first occurrence of the referenced property (this constraint implies a single value constraint on that property) |
158 | - foreach ( $context->getSnakGroup() as $otherSnak ) { |
|
158 | + foreach ($context->getSnakGroup() as $otherSnak) { |
|
159 | 159 | if ( |
160 | - !$property->equals( $otherSnak->getPropertyId() ) || |
|
160 | + !$property->equals($otherSnak->getPropertyId()) || |
|
161 | 161 | !$otherSnak instanceof PropertyValueSnak |
162 | 162 | ) { |
163 | 163 | continue; |
164 | 164 | } |
165 | 165 | |
166 | 166 | $subtrahend = $otherSnak->getDataValue(); |
167 | - if ( $subtrahend->getType() === $minuend->getType() ) { |
|
168 | - $diff = $this->rangeInYears( $min, $max ) && $minuend->getType() === 'time' ? |
|
169 | - $this->rangeCheckerHelper->getDifferenceInYears( $minuend, $subtrahend ) : |
|
170 | - $this->rangeCheckerHelper->getDifference( $minuend, $subtrahend ); |
|
167 | + if ($subtrahend->getType() === $minuend->getType()) { |
|
168 | + $diff = $this->rangeInYears($min, $max) && $minuend->getType() === 'time' ? |
|
169 | + $this->rangeCheckerHelper->getDifferenceInYears($minuend, $subtrahend) : $this->rangeCheckerHelper->getDifference($minuend, $subtrahend); |
|
171 | 170 | |
172 | - if ( $this->rangeCheckerHelper->getComparison( $min, $diff ) > 0 || |
|
173 | - $this->rangeCheckerHelper->getComparison( $diff, $max ) > 0 |
|
171 | + if ($this->rangeCheckerHelper->getComparison($min, $diff) > 0 || |
|
172 | + $this->rangeCheckerHelper->getComparison($diff, $max) > 0 |
|
174 | 173 | ) { |
175 | 174 | // at least one of $min, $max is set at this point, otherwise there could be no violation |
176 | - $openness = $min !== null ? ( $max !== null ? '' : '-rightopen' ) : '-leftopen'; |
|
175 | + $openness = $min !== null ? ($max !== null ? '' : '-rightopen') : '-leftopen'; |
|
177 | 176 | // possible message keys: |
178 | 177 | // wbqc-violation-message-diff-within-range |
179 | 178 | // wbqc-violation-message-diff-within-range-leftopen |
180 | 179 | // wbqc-violation-message-diff-within-range-rightopen |
181 | - $message = ( new ViolationMessage( "wbqc-violation-message-diff-within-range$openness" ) ) |
|
182 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ) |
|
183 | - ->withDataValue( $minuend, Role::OBJECT ) |
|
184 | - ->withEntityId( $otherSnak->getPropertyId(), Role::PREDICATE ) |
|
185 | - ->withDataValue( $subtrahend, Role::OBJECT ); |
|
186 | - if ( $min !== null ) { |
|
187 | - $message = $message->withDataValue( $min, Role::OBJECT ); |
|
180 | + $message = (new ViolationMessage("wbqc-violation-message-diff-within-range$openness")) |
|
181 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE) |
|
182 | + ->withDataValue($minuend, Role::OBJECT) |
|
183 | + ->withEntityId($otherSnak->getPropertyId(), Role::PREDICATE) |
|
184 | + ->withDataValue($subtrahend, Role::OBJECT); |
|
185 | + if ($min !== null) { |
|
186 | + $message = $message->withDataValue($min, Role::OBJECT); |
|
188 | 187 | } |
189 | - if ( $max !== null ) { |
|
190 | - $message = $message->withDataValue( $max, Role::OBJECT ); |
|
188 | + if ($max !== null) { |
|
189 | + $message = $message->withDataValue($max, Role::OBJECT); |
|
191 | 190 | } |
192 | 191 | $status = CheckResult::STATUS_VIOLATION; |
193 | 192 | } else { |
@@ -195,19 +194,19 @@ discard block |
||
195 | 194 | $status = CheckResult::STATUS_COMPLIANCE; |
196 | 195 | } |
197 | 196 | } else { |
198 | - $message = new ViolationMessage( 'wbqc-violation-message-diff-within-range-must-have-equal-types' ); |
|
197 | + $message = new ViolationMessage('wbqc-violation-message-diff-within-range-must-have-equal-types'); |
|
199 | 198 | $status = CheckResult::STATUS_VIOLATION; |
200 | 199 | } |
201 | 200 | |
202 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
201 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
203 | 202 | } |
204 | 203 | |
205 | - $message = new ViolationMessage( 'wbqc-violation-message-diff-within-range-property-must-exist' ); |
|
204 | + $message = new ViolationMessage('wbqc-violation-message-diff-within-range-property-must-exist'); |
|
206 | 205 | $status = CheckResult::STATUS_VIOLATION; |
207 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
206 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
208 | 207 | } |
209 | 208 | |
210 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
209 | + public function checkConstraintParameters(Constraint $constraint) { |
|
211 | 210 | $constraintParameters = $constraint->getConstraintParameters(); |
212 | 211 | $exceptions = []; |
213 | 212 | try { |
@@ -216,12 +215,12 @@ discard block |
||
216 | 215 | $constraint->getConstraintTypeItemId(), |
217 | 216 | 'quantity' |
218 | 217 | ); |
219 | - } catch ( ConstraintParameterException $e ) { |
|
218 | + } catch (ConstraintParameterException $e) { |
|
220 | 219 | $exceptions[] = $e; |
221 | 220 | } |
222 | 221 | try { |
223 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
224 | - } catch ( ConstraintParameterException $e ) { |
|
222 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
223 | + } catch (ConstraintParameterException $e) { |
|
225 | 224 | $exceptions[] = $e; |
226 | 225 | } |
227 | 226 | return $exceptions; |
@@ -89,23 +89,23 @@ discard block |
||
89 | 89 | * @return bool |
90 | 90 | * @throws OverflowException if $entitiesChecked exceeds the configured limit |
91 | 91 | */ |
92 | - private function isSubclassOf( EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0 ) { |
|
93 | - $maxEntities = $this->config->get( 'WBQualityConstraintsTypeCheckMaxEntities' ); |
|
92 | + private function isSubclassOf(EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0) { |
|
93 | + $maxEntities = $this->config->get('WBQualityConstraintsTypeCheckMaxEntities'); |
|
94 | 94 | if ( ++$entitiesChecked > $maxEntities ) { |
95 | - throw new OverflowException( 'Too many entities to check' ); |
|
95 | + throw new OverflowException('Too many entities to check'); |
|
96 | 96 | } |
97 | 97 | |
98 | - $item = $this->entityLookup->getEntity( $comparativeClass ); |
|
99 | - if ( !( $item instanceof StatementListProvider ) ) { |
|
98 | + $item = $this->entityLookup->getEntity($comparativeClass); |
|
99 | + if (!($item instanceof StatementListProvider)) { |
|
100 | 100 | return false; // lookup failed, probably because item doesn't exist |
101 | 101 | } |
102 | 102 | |
103 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
103 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
104 | 104 | /** @var Statement $statement */ |
105 | - foreach ( $item->getStatements()->getByPropertyId( new PropertyId( $subclassId ) ) as $statement ) { |
|
105 | + foreach ($item->getStatements()->getByPropertyId(new PropertyId($subclassId)) as $statement) { |
|
106 | 106 | $mainSnak = $statement->getMainSnak(); |
107 | 107 | |
108 | - if ( !( $this->hasCorrectType( $mainSnak ) ) ) { |
|
108 | + if (!($this->hasCorrectType($mainSnak))) { |
|
109 | 109 | continue; |
110 | 110 | } |
111 | 111 | /** @var PropertyValueSnak $mainSnak */ |
@@ -114,11 +114,11 @@ discard block |
||
114 | 114 | $dataValue = $mainSnak->getDataValue(); |
115 | 115 | $comparativeClass = $dataValue->getEntityId(); |
116 | 116 | |
117 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
117 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
118 | 118 | return true; |
119 | 119 | } |
120 | 120 | |
121 | - if ( $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ) ) { |
|
121 | + if ($this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked)) { |
|
122 | 122 | return true; |
123 | 123 | } |
124 | 124 | } |
@@ -139,14 +139,14 @@ discard block |
||
139 | 139 | * @return CachedBool |
140 | 140 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
141 | 141 | */ |
142 | - public function isSubclassOfWithSparqlFallback( EntityId $comparativeClass, array $classesToCheck ) { |
|
142 | + public function isSubclassOfWithSparqlFallback(EntityId $comparativeClass, array $classesToCheck) { |
|
143 | 143 | try { |
144 | 144 | return new CachedBool( |
145 | - $this->isSubclassOf( $comparativeClass, $classesToCheck ), |
|
145 | + $this->isSubclassOf($comparativeClass, $classesToCheck), |
|
146 | 146 | Metadata::blank() |
147 | 147 | ); |
148 | - } catch ( OverflowException $e ) { |
|
149 | - if ( $this->sparqlHelper !== null ) { |
|
148 | + } catch (OverflowException $e) { |
|
149 | + if ($this->sparqlHelper !== null) { |
|
150 | 150 | $this->dataFactory->increment( |
151 | 151 | 'wikibase.quality.constraints.sparql.typeFallback' |
152 | 152 | ); |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | /* withInstance = */ false |
157 | 157 | ); |
158 | 158 | } else { |
159 | - return new CachedBool( false, Metadata::blank() ); |
|
159 | + return new CachedBool(false, Metadata::blank()); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | } |
@@ -174,13 +174,13 @@ discard block |
||
174 | 174 | * @return CachedBool |
175 | 175 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
176 | 176 | */ |
177 | - public function hasClassInRelation( StatementList $statements, array $relationIds, array $classesToCheck ) { |
|
177 | + public function hasClassInRelation(StatementList $statements, array $relationIds, array $classesToCheck) { |
|
178 | 178 | $metadatas = []; |
179 | 179 | |
180 | - foreach ( $this->getStatementsByPropertyIds( $statements, $relationIds ) as $statement ) { |
|
180 | + foreach ($this->getStatementsByPropertyIds($statements, $relationIds) as $statement) { |
|
181 | 181 | $mainSnak = $statement->getMainSnak(); |
182 | 182 | |
183 | - if ( !$this->hasCorrectType( $mainSnak ) ) { |
|
183 | + if (!$this->hasCorrectType($mainSnak)) { |
|
184 | 184 | continue; |
185 | 185 | } |
186 | 186 | /** @var PropertyValueSnak $mainSnak */ |
@@ -189,28 +189,28 @@ discard block |
||
189 | 189 | $dataValue = $mainSnak->getDataValue(); |
190 | 190 | $comparativeClass = $dataValue->getEntityId(); |
191 | 191 | |
192 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
192 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
193 | 193 | // discard $metadatas, we know this is fresh |
194 | - return new CachedBool( true, Metadata::blank() ); |
|
194 | + return new CachedBool(true, Metadata::blank()); |
|
195 | 195 | } |
196 | 196 | |
197 | - $result = $this->isSubclassOfWithSparqlFallback( $comparativeClass, $classesToCheck ); |
|
197 | + $result = $this->isSubclassOfWithSparqlFallback($comparativeClass, $classesToCheck); |
|
198 | 198 | $metadatas[] = $result->getMetadata(); |
199 | - if ( $result->getBool() ) { |
|
199 | + if ($result->getBool()) { |
|
200 | 200 | return new CachedBool( |
201 | 201 | true, |
202 | - Metadata::merge( $metadatas ) |
|
202 | + Metadata::merge($metadatas) |
|
203 | 203 | ); |
204 | 204 | } |
205 | 205 | } |
206 | 206 | |
207 | 207 | return new CachedBool( |
208 | 208 | false, |
209 | - Metadata::merge( $metadatas ) |
|
209 | + Metadata::merge($metadatas) |
|
210 | 210 | ); |
211 | 211 | } |
212 | 212 | |
213 | - private function hasCorrectType( Snak $mainSnak ) { |
|
213 | + private function hasCorrectType(Snak $mainSnak) { |
|
214 | 214 | return $mainSnak instanceof PropertyValueSnak |
215 | 215 | && $mainSnak->getDataValue()->getType() === 'wikibase-entityid'; |
216 | 216 | } |
@@ -227,12 +227,12 @@ discard block |
||
227 | 227 | ) { |
228 | 228 | $statementArrays = []; |
229 | 229 | |
230 | - foreach ( $propertyIdSerializations as $propertyIdSerialization ) { |
|
231 | - $propertyId = new PropertyId( $propertyIdSerialization ); |
|
232 | - $statementArrays[] = $statements->getByPropertyId( $propertyId )->toArray(); |
|
230 | + foreach ($propertyIdSerializations as $propertyIdSerialization) { |
|
231 | + $propertyId = new PropertyId($propertyIdSerialization); |
|
232 | + $statementArrays[] = $statements->getByPropertyId($propertyId)->toArray(); |
|
233 | 233 | } |
234 | 234 | |
235 | - return call_user_func_array( 'array_merge', $statementArrays ); |
|
235 | + return call_user_func_array('array_merge', $statementArrays); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -244,10 +244,10 @@ discard block |
||
244 | 244 | * |
245 | 245 | * @return ViolationMessage |
246 | 246 | */ |
247 | - public function getViolationMessage( PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation ) { |
|
247 | + public function getViolationMessage(PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation) { |
|
248 | 248 | $classes = array_map( |
249 | - function( $itemIdSerialization ) { |
|
250 | - return new ItemId( $itemIdSerialization ); |
|
249 | + function($itemIdSerialization) { |
|
250 | + return new ItemId($itemIdSerialization); |
|
251 | 251 | }, |
252 | 252 | $classes |
253 | 253 | ); |
@@ -259,10 +259,10 @@ discard block |
||
259 | 259 | // wbqc-violation-message-valueType-instance |
260 | 260 | // wbqc-violation-message-valueType-subclass |
261 | 261 | // wbqc-violation-message-valueType-instanceOrSubclass |
262 | - return ( new ViolationMessage( 'wbqc-violation-message-' . $checker . '-' . $relation ) ) |
|
263 | - ->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ) |
|
264 | - ->withEntityId( $entityId, Role::SUBJECT ) |
|
265 | - ->withEntityIdList( $classes, Role::OBJECT ); |
|
262 | + return (new ViolationMessage('wbqc-violation-message-'.$checker.'-'.$relation)) |
|
263 | + ->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY) |
|
264 | + ->withEntityId($entityId, Role::SUBJECT) |
|
265 | + ->withEntityIdList($classes, Role::OBJECT); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | } |
@@ -85,17 +85,17 @@ discard block |
||
85 | 85 | public function __construct( |
86 | 86 | $messageKey |
87 | 87 | ) { |
88 | - if ( strpos( $messageKey, self::MESSAGE_KEY_PREFIX ) !== 0 ) { |
|
88 | + if (strpos($messageKey, self::MESSAGE_KEY_PREFIX) !== 0) { |
|
89 | 89 | throw new InvalidArgumentException( |
90 | - 'ViolationMessage key ⧼' . |
|
91 | - $messageKey . |
|
92 | - '⧽ should start with "' . |
|
93 | - self::MESSAGE_KEY_PREFIX . |
|
90 | + 'ViolationMessage key ⧼'. |
|
91 | + $messageKey. |
|
92 | + '⧽ should start with "'. |
|
93 | + self::MESSAGE_KEY_PREFIX. |
|
94 | 94 | '".' |
95 | 95 | ); |
96 | 96 | } |
97 | 97 | |
98 | - $this->messageKeySuffix = substr( $messageKey, strlen( self::MESSAGE_KEY_PREFIX ) ); |
|
98 | + $this->messageKeySuffix = substr($messageKey, strlen(self::MESSAGE_KEY_PREFIX)); |
|
99 | 99 | $this->arguments = []; |
100 | 100 | } |
101 | 101 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @return string |
105 | 105 | */ |
106 | 106 | public function getMessageKey() { |
107 | - return self::MESSAGE_KEY_PREFIX . $this->messageKeySuffix; |
|
107 | + return self::MESSAGE_KEY_PREFIX.$this->messageKeySuffix; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -122,9 +122,9 @@ discard block |
||
122 | 122 | * @param mixed $value the value, which should match the $type |
123 | 123 | * @return ViolationMessage |
124 | 124 | */ |
125 | - private function withArgument( $type, $role, $value ) { |
|
125 | + private function withArgument($type, $role, $value) { |
|
126 | 126 | $ret = clone $this; |
127 | - $ret->arguments[] = [ 'type' => $type, 'role' => $role, 'value' => $value ]; |
|
127 | + $ret->arguments[] = ['type' => $type, 'role' => $role, 'value' => $value]; |
|
128 | 128 | return $ret; |
129 | 129 | } |
130 | 130 | |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | * @param string|null $role one of the Role::* constants |
137 | 137 | * @return ViolationMessage |
138 | 138 | */ |
139 | - public function withEntityId( EntityId $entityId, $role = null ) { |
|
140 | - return $this->withArgument( self::TYPE_ENTITY_ID, $role, $entityId ); |
|
139 | + public function withEntityId(EntityId $entityId, $role = null) { |
|
140 | + return $this->withArgument(self::TYPE_ENTITY_ID, $role, $entityId); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -154,8 +154,8 @@ discard block |
||
154 | 154 | * @param string|null $role one of the Role::* constants |
155 | 155 | * @return ViolationMessage |
156 | 156 | */ |
157 | - public function withEntityIdList( array $entityIdList, $role = null ) { |
|
158 | - return $this->withArgument( self::TYPE_ENTITY_ID_LIST, $role, $entityIdList ); |
|
157 | + public function withEntityIdList(array $entityIdList, $role = null) { |
|
158 | + return $this->withArgument(self::TYPE_ENTITY_ID_LIST, $role, $entityIdList); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -166,8 +166,8 @@ discard block |
||
166 | 166 | * @param string|null $role one of the Role::* constants |
167 | 167 | * @return ViolationMessage |
168 | 168 | */ |
169 | - public function withItemIdSnakValue( ItemIdSnakValue $value, $role = null ) { |
|
170 | - return $this->withArgument( self::TYPE_ITEM_ID_SNAK_VALUE, $role, $value ); |
|
169 | + public function withItemIdSnakValue(ItemIdSnakValue $value, $role = null) { |
|
170 | + return $this->withArgument(self::TYPE_ITEM_ID_SNAK_VALUE, $role, $value); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | * @param string|null $role one of the Role::* constants |
185 | 185 | * @return ViolationMessage |
186 | 186 | */ |
187 | - public function withItemIdSnakValueList( array $valueList, $role = null ) { |
|
188 | - return $this->withArgument( self::TYPE_ITEM_ID_SNAK_VALUE_LIST, $role, $valueList ); |
|
187 | + public function withItemIdSnakValueList(array $valueList, $role = null) { |
|
188 | + return $this->withArgument(self::TYPE_ITEM_ID_SNAK_VALUE_LIST, $role, $valueList); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | * @param string|null $role one of the Role::* constants |
197 | 197 | * @return ViolationMessage |
198 | 198 | */ |
199 | - public function withDataValue( DataValue $dataValue, $role = null ) { |
|
200 | - return $this->withArgument( self::TYPE_DATA_VALUE, $role, $dataValue ); |
|
199 | + public function withDataValue(DataValue $dataValue, $role = null) { |
|
200 | + return $this->withArgument(self::TYPE_DATA_VALUE, $role, $dataValue); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -212,8 +212,8 @@ discard block |
||
212 | 212 | * @param string|null $role one of the Role::* constants |
213 | 213 | * @return ViolationMessage |
214 | 214 | */ |
215 | - public function withDataValueType( $dataValueType, $role = null ) { |
|
216 | - return $this->withArgument( self::TYPE_DATA_VALUE_TYPE, $role, $dataValueType ); |
|
215 | + public function withDataValueType($dataValueType, $role = null) { |
|
216 | + return $this->withArgument(self::TYPE_DATA_VALUE_TYPE, $role, $dataValueType); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -224,8 +224,8 @@ discard block |
||
224 | 224 | * @param string|null $role one of the Role::* constants |
225 | 225 | * @return ViolationMessage |
226 | 226 | */ |
227 | - public function withInlineCode( $code, $role = null ) { |
|
228 | - return $this->withArgument( self::TYPE_INLINE_CODE, $role, $code ); |
|
227 | + public function withInlineCode($code, $role = null) { |
|
228 | + return $this->withArgument(self::TYPE_INLINE_CODE, $role, $code); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | } |
@@ -54,31 +54,31 @@ discard block |
||
54 | 54 | * (temporarily, pre-rendered strings are allowed and returned without changes) |
55 | 55 | * @return string |
56 | 56 | */ |
57 | - public function render( $violationMessage ) { |
|
58 | - if ( is_string( $violationMessage ) ) { |
|
57 | + public function render($violationMessage) { |
|
58 | + if (is_string($violationMessage)) { |
|
59 | 59 | // TODO remove this once all checkers produce ViolationMessage objects |
60 | 60 | return $violationMessage; |
61 | 61 | } |
62 | 62 | |
63 | 63 | $messageKey = $violationMessage->getMessageKey(); |
64 | - $paramsLists = [ [] ]; |
|
65 | - foreach ( $violationMessage->getArguments() as $argument ) { |
|
66 | - $params = $this->renderArgument( $argument ); |
|
64 | + $paramsLists = [[]]; |
|
65 | + foreach ($violationMessage->getArguments() as $argument) { |
|
66 | + $params = $this->renderArgument($argument); |
|
67 | 67 | $paramsLists[] = $params; |
68 | 68 | } |
69 | - $allParams = call_user_func_array( 'array_merge', $paramsLists ); |
|
70 | - return ( new Message( $messageKey ) ) |
|
71 | - ->params( $allParams ) |
|
69 | + $allParams = call_user_func_array('array_merge', $paramsLists); |
|
70 | + return (new Message($messageKey)) |
|
71 | + ->params($allParams) |
|
72 | 72 | ->escaped(); |
73 | 73 | } |
74 | 74 | |
75 | - private function addRole( $value, $role ) { |
|
76 | - if ( $role === null ) { |
|
75 | + private function addRole($value, $role) { |
|
76 | + if ($role === null) { |
|
77 | 77 | return $value; |
78 | 78 | } |
79 | 79 | |
80 | - return '<span class="wbqc-role wbqc-role-' . htmlspecialchars( $role ) . '">' . |
|
81 | - $value . |
|
80 | + return '<span class="wbqc-role wbqc-role-'.htmlspecialchars($role).'">'. |
|
81 | + $value. |
|
82 | 82 | '</span>'; |
83 | 83 | } |
84 | 84 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @param array $argument |
87 | 87 | * @return array params (for Message::params) |
88 | 88 | */ |
89 | - private function renderArgument( array $argument ) { |
|
89 | + private function renderArgument(array $argument) { |
|
90 | 90 | $methods = [ |
91 | 91 | ViolationMessage::TYPE_ENTITY_ID => 'renderEntityId', |
92 | 92 | ViolationMessage::TYPE_ENTITY_ID_LIST => 'renderEntityIdList', |
@@ -101,55 +101,55 @@ discard block |
||
101 | 101 | $value = $argument['value']; |
102 | 102 | $role = $argument['role']; |
103 | 103 | |
104 | - if ( array_key_exists( $type, $methods ) ) { |
|
104 | + if (array_key_exists($type, $methods)) { |
|
105 | 105 | $method = $methods[$type]; |
106 | - $params = $this->$method( $value, $role ); |
|
106 | + $params = $this->$method($value, $role); |
|
107 | 107 | } else { |
108 | 108 | throw new InvalidArgumentException( |
109 | - 'Unknown ViolationMessage argument type ' . $type . '!' |
|
109 | + 'Unknown ViolationMessage argument type '.$type.'!' |
|
110 | 110 | ); |
111 | 111 | } |
112 | 112 | |
113 | - if ( !array_key_exists( 0, $params ) ) { |
|
114 | - $params = [ $params ]; |
|
113 | + if (!array_key_exists(0, $params)) { |
|
114 | + $params = [$params]; |
|
115 | 115 | } |
116 | 116 | return $params; |
117 | 117 | } |
118 | 118 | |
119 | - private function renderList( array $list, $role, callable $render ) { |
|
120 | - if ( $list === [] ) { |
|
119 | + private function renderList(array $list, $role, callable $render) { |
|
120 | + if ($list === []) { |
|
121 | 121 | return [ |
122 | - Message::numParam( 0 ), |
|
123 | - Message::rawParam( '<ul></ul>' ), |
|
122 | + Message::numParam(0), |
|
123 | + Message::rawParam('<ul></ul>'), |
|
124 | 124 | ]; |
125 | 125 | } |
126 | 126 | |
127 | - if ( count( $list ) > $this->maxListLength ) { |
|
128 | - $list = array_slice( $list, 0, $this->maxListLength ); |
|
127 | + if (count($list) > $this->maxListLength) { |
|
128 | + $list = array_slice($list, 0, $this->maxListLength); |
|
129 | 129 | $truncated = true; |
130 | 130 | } |
131 | 131 | |
132 | 132 | $renderedParams = array_map( |
133 | 133 | $render, |
134 | 134 | $list, |
135 | - array_fill( 0, count( $list ), $role ) |
|
135 | + array_fill(0, count($list), $role) |
|
136 | 136 | ); |
137 | 137 | $renderedElements = array_map( |
138 | - function ( $param ) { |
|
138 | + function($param) { |
|
139 | 139 | return $param['raw']; |
140 | 140 | }, |
141 | 141 | $renderedParams |
142 | 142 | ); |
143 | - if ( isset( $truncated ) ) { |
|
144 | - $renderedElements[] = wfMessage( 'ellipsis' )->escaped(); |
|
143 | + if (isset($truncated)) { |
|
144 | + $renderedElements[] = wfMessage('ellipsis')->escaped(); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | return array_merge( |
148 | 148 | [ |
149 | - Message::numParam( count( $list ) ), |
|
149 | + Message::numParam(count($list)), |
|
150 | 150 | Message::rawParam( |
151 | - '<ul><li>' . |
|
152 | - implode( '</li><li>', $renderedElements ) . |
|
151 | + '<ul><li>'. |
|
152 | + implode('</li><li>', $renderedElements). |
|
153 | 153 | '</li></ul>' |
154 | 154 | ), |
155 | 155 | ], |
@@ -157,35 +157,35 @@ discard block |
||
157 | 157 | ); |
158 | 158 | } |
159 | 159 | |
160 | - private function renderEntityId( EntityId $entityId, $role ) { |
|
161 | - return Message::rawParam( $this->addRole( |
|
162 | - $this->entityIdFormatter->formatEntityId( $entityId ), |
|
160 | + private function renderEntityId(EntityId $entityId, $role) { |
|
161 | + return Message::rawParam($this->addRole( |
|
162 | + $this->entityIdFormatter->formatEntityId($entityId), |
|
163 | 163 | $role |
164 | - ) ); |
|
164 | + )); |
|
165 | 165 | } |
166 | 166 | |
167 | - private function renderEntityIdList( array $entityIdList, $role ) { |
|
168 | - return $this->renderList( $entityIdList, $role, [ $this, 'renderEntityId' ] ); |
|
167 | + private function renderEntityIdList(array $entityIdList, $role) { |
|
168 | + return $this->renderList($entityIdList, $role, [$this, 'renderEntityId']); |
|
169 | 169 | } |
170 | 170 | |
171 | - private function renderItemIdSnakValue( ItemIdSnakValue $value, $role ) { |
|
172 | - switch ( true ) { |
|
171 | + private function renderItemIdSnakValue(ItemIdSnakValue $value, $role) { |
|
172 | + switch (true) { |
|
173 | 173 | case $value->isValue(): |
174 | - return $this->renderEntityId( $value->getItemId(), $role ); |
|
174 | + return $this->renderEntityId($value->getItemId(), $role); |
|
175 | 175 | case $value->isSomeValue(): |
176 | - return Message::rawParam( $this->addRole( |
|
177 | - '<span class="wikibase-snakview-variation-somevaluesnak">' . |
|
178 | - wfMessage( 'wikibase-snakview-snaktypeselector-somevalue' )->escaped() . |
|
176 | + return Message::rawParam($this->addRole( |
|
177 | + '<span class="wikibase-snakview-variation-somevaluesnak">'. |
|
178 | + wfMessage('wikibase-snakview-snaktypeselector-somevalue')->escaped(). |
|
179 | 179 | '</span>', |
180 | 180 | $role |
181 | - ) ); |
|
181 | + )); |
|
182 | 182 | case $value->isNoValue(): |
183 | - return Message::rawParam( $this->addRole( |
|
184 | - '<span class="wikibase-snakview-variation-novaluesnak">' . |
|
185 | - wfMessage( 'wikibase-snakview-snaktypeselector-novalue' )->escaped() . |
|
183 | + return Message::rawParam($this->addRole( |
|
184 | + '<span class="wikibase-snakview-variation-novaluesnak">'. |
|
185 | + wfMessage('wikibase-snakview-snaktypeselector-novalue')->escaped(). |
|
186 | 186 | '</span>', |
187 | 187 | $role |
188 | - ) ); |
|
188 | + )); |
|
189 | 189 | default: |
190 | 190 | // @codeCoverageIgnoreStart |
191 | 191 | throw new LogicException( |
@@ -195,43 +195,43 @@ discard block |
||
195 | 195 | } |
196 | 196 | } |
197 | 197 | |
198 | - private function renderItemIdSnakValueList( array $valueList, $role ) { |
|
199 | - return $this->renderList( $valueList, $role, [ $this, 'renderItemIdSnakValue' ] ); |
|
198 | + private function renderItemIdSnakValueList(array $valueList, $role) { |
|
199 | + return $this->renderList($valueList, $role, [$this, 'renderItemIdSnakValue']); |
|
200 | 200 | } |
201 | 201 | |
202 | - private function renderDataValue( DataValue $dataValue, $role ) { |
|
203 | - return Message::rawParam( $this->addRole( |
|
204 | - $this->dataValueFormatter->format( $dataValue ), |
|
202 | + private function renderDataValue(DataValue $dataValue, $role) { |
|
203 | + return Message::rawParam($this->addRole( |
|
204 | + $this->dataValueFormatter->format($dataValue), |
|
205 | 205 | $role |
206 | - ) ); |
|
206 | + )); |
|
207 | 207 | } |
208 | 208 | |
209 | - private function renderDataValueType( $dataValueType, $role ) { |
|
209 | + private function renderDataValueType($dataValueType, $role) { |
|
210 | 210 | $messageKeys = [ |
211 | 211 | 'string' => 'datatypes-type-string', |
212 | 212 | 'monolingualtext' => 'datatypes-monolingualtext', |
213 | 213 | 'wikibase-entityid' => 'wbqc-dataValueType-wikibase-entityid', |
214 | 214 | ]; |
215 | 215 | |
216 | - if ( array_key_exists( $dataValueType, $messageKeys ) ) { |
|
217 | - return Message::rawParam( $this->addRole( |
|
218 | - wfMessage( $messageKeys[$dataValueType] )->escaped(), |
|
216 | + if (array_key_exists($dataValueType, $messageKeys)) { |
|
217 | + return Message::rawParam($this->addRole( |
|
218 | + wfMessage($messageKeys[$dataValueType])->escaped(), |
|
219 | 219 | $role |
220 | - ) ); |
|
220 | + )); |
|
221 | 221 | } else { |
222 | 222 | // @codeCoverageIgnoreStart |
223 | 223 | throw new LogicException( |
224 | - 'Unknown data value type ' . $dataValueType |
|
224 | + 'Unknown data value type '.$dataValueType |
|
225 | 225 | ); |
226 | 226 | // @codeCoverageIgnoreEnd |
227 | 227 | } |
228 | 228 | } |
229 | 229 | |
230 | - private function renderInlineCode( $code, $role ) { |
|
231 | - return Message::rawParam( $this->addRole( |
|
232 | - '<code>' . htmlspecialchars( $code ) . '</code>', |
|
230 | + private function renderInlineCode($code, $role) { |
|
231 | + return Message::rawParam($this->addRole( |
|
232 | + '<code>'.htmlspecialchars($code).'</code>', |
|
233 | 233 | $role |
234 | - ) ); |
|
234 | + )); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | } |