@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Checker; |
6 | 6 | |
@@ -77,26 +77,26 @@ discard block |
||
77 | 77 | * @return array first element is the namespace number (default namespace for TitleParser), |
78 | 78 | * second element is a string to prepend to the title before giving it to the TitleParser |
79 | 79 | */ |
80 | - private function getCommonsNamespace( string $namespace ): array { |
|
81 | - switch ( $namespace ) { |
|
80 | + private function getCommonsNamespace(string $namespace): array { |
|
81 | + switch ($namespace) { |
|
82 | 82 | case '': |
83 | - return [ NS_MAIN, '' ]; |
|
83 | + return [NS_MAIN, '']; |
|
84 | 84 | // extra namespaces, see operations/mediawiki-config.git, |
85 | 85 | // wmf-config/InitialiseSettings.php, 'wgExtraNamespaces' key, 'commonswiki' subkey |
86 | 86 | case 'Creator': |
87 | - return [ 100, '' ]; |
|
87 | + return [100, '']; |
|
88 | 88 | case 'TimedText': |
89 | - return [ 102, '' ]; |
|
89 | + return [102, '']; |
|
90 | 90 | case 'Sequence': |
91 | - return [ 104, '' ]; |
|
91 | + return [104, '']; |
|
92 | 92 | case 'Institution': |
93 | - return [ 106, '' ]; |
|
93 | + return [106, '']; |
|
94 | 94 | // extension namespace, see mediawiki/extensions/JsonConfig.git, |
95 | 95 | // extension.json, 'namespaces' key, third element |
96 | 96 | case 'Data': |
97 | - return [ 486, '' ]; |
|
97 | + return [486, '']; |
|
98 | 98 | default: |
99 | - return [ NS_MAIN, $namespace . ':' ]; |
|
99 | + return [NS_MAIN, $namespace.':']; |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @throws ConstraintParameterException |
107 | 107 | */ |
108 | - public function checkConstraint( Context $context, Constraint $constraint ): CheckResult { |
|
108 | + public function checkConstraint(Context $context, Constraint $constraint): CheckResult { |
|
109 | 109 | $parameters = []; |
110 | 110 | $constraintParameters = $constraint->getConstraintParameters(); |
111 | 111 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
@@ -114,13 +114,13 @@ discard block |
||
114 | 114 | $constraintParameters, |
115 | 115 | $constraintTypeItemId |
116 | 116 | ); |
117 | - $parameters['namespace'] = [ $namespace ]; |
|
117 | + $parameters['namespace'] = [$namespace]; |
|
118 | 118 | |
119 | 119 | $snak = $context->getSnak(); |
120 | 120 | |
121 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
121 | + if (!$snak instanceof PropertyValueSnak) { |
|
122 | 122 | // nothing to check |
123 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
123 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | $dataValue = $snak->getDataValue(); |
@@ -130,52 +130,52 @@ discard block |
||
130 | 130 | * type of $dataValue for properties with 'Commons link' constraint has to be 'string' |
131 | 131 | * parameter $namespace can be null, works for commons galleries |
132 | 132 | */ |
133 | - if ( $dataValue->getType() !== 'string' ) { |
|
134 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
135 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
136 | - ->withDataValueType( 'string' ); |
|
137 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
133 | + if ($dataValue->getType() !== 'string') { |
|
134 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
135 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
136 | + ->withDataValueType('string'); |
|
137 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | $commonsLink = $dataValue->getValue(); |
141 | - if ( !$this->commonsLinkIsWellFormed( $commonsLink ) ) { |
|
142 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
143 | - new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ) ); |
|
141 | + if (!$this->commonsLinkIsWellFormed($commonsLink)) { |
|
142 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
143 | + new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed')); |
|
144 | 144 | } |
145 | 145 | |
146 | - $dataType = $this->propertyDatatypeLookup->getDataTypeIdForProperty( $snak->getPropertyId() ); |
|
147 | - switch ( $dataType ) { |
|
146 | + $dataType = $this->propertyDatatypeLookup->getDataTypeIdForProperty($snak->getPropertyId()); |
|
147 | + switch ($dataType) { |
|
148 | 148 | case 'geo-shape': |
149 | 149 | case 'tabular-data': |
150 | - if ( strpos( $commonsLink, $namespace . ':' ) !== 0 ) { |
|
151 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
152 | - new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ) ); |
|
150 | + if (strpos($commonsLink, $namespace.':') !== 0) { |
|
151 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
152 | + new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed')); |
|
153 | 153 | } |
154 | 154 | $pageName = $commonsLink; |
155 | 155 | break; |
156 | 156 | default: |
157 | - $pageName = $namespace ? $namespace . ':' . $commonsLink : $commonsLink; |
|
157 | + $pageName = $namespace ? $namespace.':'.$commonsLink : $commonsLink; |
|
158 | 158 | break; |
159 | 159 | } |
160 | 160 | |
161 | - $prefix = $this->getCommonsNamespace( $namespace )[1]; |
|
161 | + $prefix = $this->getCommonsNamespace($namespace)[1]; |
|
162 | 162 | $normalizedTitle = $this->pageNameNormalizer->normalizePageName( |
163 | 163 | $pageName, |
164 | 164 | 'https://commons.wikimedia.org/w/api.php' |
165 | 165 | ); |
166 | - if ( $normalizedTitle === false ) { |
|
167 | - if ( $this->valueIncludesNamespace( $commonsLink, $namespace ) ) { |
|
168 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
169 | - new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ) ); |
|
166 | + if ($normalizedTitle === false) { |
|
167 | + if ($this->valueIncludesNamespace($commonsLink, $namespace)) { |
|
168 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
169 | + new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed')); |
|
170 | 170 | } |
171 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
172 | - new ViolationMessage( 'wbqc-violation-message-commons-link-no-existent' ) ); |
|
171 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
172 | + new ViolationMessage('wbqc-violation-message-commons-link-no-existent')); |
|
173 | 173 | } |
174 | 174 | |
175 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, null ); |
|
175 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, null); |
|
176 | 176 | } |
177 | 177 | |
178 | - public function checkConstraintParameters( Constraint $constraint ): array { |
|
178 | + public function checkConstraintParameters(Constraint $constraint): array { |
|
179 | 179 | $constraintParameters = $constraint->getConstraintParameters(); |
180 | 180 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
181 | 181 | $exceptions = []; |
@@ -184,15 +184,15 @@ discard block |
||
184 | 184 | $constraintParameters, |
185 | 185 | $constraintTypeItemId |
186 | 186 | ); |
187 | - } catch ( ConstraintParameterException $e ) { |
|
187 | + } catch (ConstraintParameterException $e) { |
|
188 | 188 | $exceptions[] = $e; |
189 | 189 | } |
190 | 190 | return $exceptions; |
191 | 191 | } |
192 | 192 | |
193 | - private function commonsLinkIsWellFormed( string $commonsLink ): bool { |
|
194 | - $toReplace = [ "_", "%20" ]; |
|
195 | - $compareString = trim( str_replace( $toReplace, '', $commonsLink ) ); |
|
193 | + private function commonsLinkIsWellFormed(string $commonsLink): bool { |
|
194 | + $toReplace = ["_", "%20"]; |
|
195 | + $compareString = trim(str_replace($toReplace, '', $commonsLink)); |
|
196 | 196 | |
197 | 197 | return $commonsLink === $compareString; |
198 | 198 | } |
@@ -201,9 +201,9 @@ discard block |
||
201 | 201 | * Checks whether the value of the statement already includes the namespace. |
202 | 202 | * This special case should be reported as “malformed title” instead of “title does not exist”. |
203 | 203 | */ |
204 | - private function valueIncludesNamespace( string $value, string $namespace ): bool { |
|
204 | + private function valueIncludesNamespace(string $value, string $namespace): bool { |
|
205 | 205 | return $namespace !== '' && |
206 | - strncasecmp( $value, $namespace . ':', strlen( $namespace ) + 1 ) === 0; |
|
206 | + strncasecmp($value, $namespace.':', strlen($namespace) + 1) === 0; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | } |
@@ -80,26 +80,26 @@ discard block |
||
80 | 80 | * @return bool |
81 | 81 | * @throws OverflowException if $entitiesChecked exceeds the configured limit |
82 | 82 | */ |
83 | - private function isSubclassOf( EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0 ) { |
|
84 | - $maxEntities = $this->config->get( 'WBQualityConstraintsTypeCheckMaxEntities' ); |
|
83 | + private function isSubclassOf(EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0) { |
|
84 | + $maxEntities = $this->config->get('WBQualityConstraintsTypeCheckMaxEntities'); |
|
85 | 85 | if ( ++$entitiesChecked > $maxEntities ) { |
86 | - throw new OverflowException( 'Too many entities to check' ); |
|
86 | + throw new OverflowException('Too many entities to check'); |
|
87 | 87 | } |
88 | 88 | |
89 | - $item = $this->entityLookup->getEntity( $comparativeClass ); |
|
90 | - if ( !( $item instanceof StatementListProvider ) ) { |
|
89 | + $item = $this->entityLookup->getEntity($comparativeClass); |
|
90 | + if (!($item instanceof StatementListProvider)) { |
|
91 | 91 | return false; // lookup failed, probably because item doesn't exist |
92 | 92 | } |
93 | 93 | |
94 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
94 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
95 | 95 | $statements = $item->getStatements() |
96 | - ->getByPropertyId( new PropertyId( $subclassId ) ) |
|
96 | + ->getByPropertyId(new PropertyId($subclassId)) |
|
97 | 97 | ->getBestStatements(); |
98 | 98 | /** @var Statement $statement */ |
99 | - foreach ( $statements as $statement ) { |
|
99 | + foreach ($statements as $statement) { |
|
100 | 100 | $mainSnak = $statement->getMainSnak(); |
101 | 101 | |
102 | - if ( !$this->hasCorrectType( $mainSnak ) ) { |
|
102 | + if (!$this->hasCorrectType($mainSnak)) { |
|
103 | 103 | continue; |
104 | 104 | } |
105 | 105 | /** @var PropertyValueSnak $mainSnak */ |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | '@phan-var EntityIdValue $dataValue'; |
110 | 110 | $comparativeClass = $dataValue->getEntityId(); |
111 | 111 | |
112 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
112 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
113 | 113 | return true; |
114 | 114 | } |
115 | 115 | |
116 | - if ( $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ) ) { |
|
116 | + if ($this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked)) { |
|
117 | 117 | return true; |
118 | 118 | } |
119 | 119 | } |
@@ -134,48 +134,48 @@ discard block |
||
134 | 134 | * @return CachedBool |
135 | 135 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
136 | 136 | */ |
137 | - public function isSubclassOfWithSparqlFallback( EntityId $comparativeClass, array $classesToCheck ) { |
|
137 | + public function isSubclassOfWithSparqlFallback(EntityId $comparativeClass, array $classesToCheck) { |
|
138 | 138 | try { |
139 | 139 | $entitiesChecked = 0; |
140 | - $start1 = microtime( true ); |
|
141 | - $isSubclass = $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ); |
|
142 | - $end1 = microtime( true ); |
|
140 | + $start1 = microtime(true); |
|
141 | + $isSubclass = $this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked); |
|
142 | + $end1 = microtime(true); |
|
143 | 143 | $this->dataFactory->timing( |
144 | 144 | 'wikibase.quality.constraints.type.php.success.timing', |
145 | - ( $end1 - $start1 ) * 1000 |
|
145 | + ($end1 - $start1) * 1000 |
|
146 | 146 | ); |
147 | 147 | $this->dataFactory->timing( // not really a timing, but works like one (we want percentiles etc.) |
148 | 148 | 'wikibase.quality.constraints.type.php.success.entities', |
149 | 149 | $entitiesChecked |
150 | 150 | ); |
151 | 151 | |
152 | - return new CachedBool( $isSubclass, Metadata::blank() ); |
|
153 | - } catch ( OverflowException $e ) { |
|
154 | - $end1 = microtime( true ); |
|
152 | + return new CachedBool($isSubclass, Metadata::blank()); |
|
153 | + } catch (OverflowException $e) { |
|
154 | + $end1 = microtime(true); |
|
155 | 155 | $this->dataFactory->timing( |
156 | 156 | 'wikibase.quality.constraints.type.php.overflow.timing', |
157 | - ( $end1 - $start1 ) * 1000 |
|
157 | + ($end1 - $start1) * 1000 |
|
158 | 158 | ); |
159 | 159 | |
160 | - if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) { |
|
160 | + if (!($this->sparqlHelper instanceof DummySparqlHelper)) { |
|
161 | 161 | $this->dataFactory->increment( |
162 | 162 | 'wikibase.quality.constraints.sparql.typeFallback' |
163 | 163 | ); |
164 | 164 | |
165 | - $start2 = microtime( true ); |
|
165 | + $start2 = microtime(true); |
|
166 | 166 | $hasType = $this->sparqlHelper->hasType( |
167 | 167 | $comparativeClass->getSerialization(), |
168 | 168 | $classesToCheck |
169 | 169 | ); |
170 | - $end2 = microtime( true ); |
|
170 | + $end2 = microtime(true); |
|
171 | 171 | $this->dataFactory->timing( |
172 | 172 | 'wikibase.quality.constraints.type.sparql.success.timing', |
173 | - ( $end2 - $start2 ) * 1000 |
|
173 | + ($end2 - $start2) * 1000 |
|
174 | 174 | ); |
175 | 175 | |
176 | 176 | return $hasType; |
177 | 177 | } else { |
178 | - return new CachedBool( false, Metadata::blank() ); |
|
178 | + return new CachedBool(false, Metadata::blank()); |
|
179 | 179 | } |
180 | 180 | } |
181 | 181 | } |
@@ -193,13 +193,13 @@ discard block |
||
193 | 193 | * @return CachedBool |
194 | 194 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
195 | 195 | */ |
196 | - public function hasClassInRelation( StatementList $statements, array $relationIds, array $classesToCheck ) { |
|
196 | + public function hasClassInRelation(StatementList $statements, array $relationIds, array $classesToCheck) { |
|
197 | 197 | $metadatas = []; |
198 | 198 | |
199 | - foreach ( $this->getBestStatementsByPropertyIds( $statements, $relationIds ) as $statement ) { |
|
199 | + foreach ($this->getBestStatementsByPropertyIds($statements, $relationIds) as $statement) { |
|
200 | 200 | $mainSnak = $statement->getMainSnak(); |
201 | 201 | |
202 | - if ( !$this->hasCorrectType( $mainSnak ) ) { |
|
202 | + if (!$this->hasCorrectType($mainSnak)) { |
|
203 | 203 | continue; |
204 | 204 | } |
205 | 205 | /** @var PropertyValueSnak $mainSnak */ |
@@ -209,24 +209,24 @@ discard block |
||
209 | 209 | '@phan-var EntityIdValue $dataValue'; |
210 | 210 | $comparativeClass = $dataValue->getEntityId(); |
211 | 211 | |
212 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
212 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
213 | 213 | // discard $metadatas, we know this is fresh |
214 | - return new CachedBool( true, Metadata::blank() ); |
|
214 | + return new CachedBool(true, Metadata::blank()); |
|
215 | 215 | } |
216 | 216 | |
217 | - $result = $this->isSubclassOfWithSparqlFallback( $comparativeClass, $classesToCheck ); |
|
217 | + $result = $this->isSubclassOfWithSparqlFallback($comparativeClass, $classesToCheck); |
|
218 | 218 | $metadatas[] = $result->getMetadata(); |
219 | - if ( $result->getBool() ) { |
|
219 | + if ($result->getBool()) { |
|
220 | 220 | return new CachedBool( |
221 | 221 | true, |
222 | - Metadata::merge( $metadatas ) |
|
222 | + Metadata::merge($metadatas) |
|
223 | 223 | ); |
224 | 224 | } |
225 | 225 | } |
226 | 226 | |
227 | 227 | return new CachedBool( |
228 | 228 | false, |
229 | - Metadata::merge( $metadatas ) |
|
229 | + Metadata::merge($metadatas) |
|
230 | 230 | ); |
231 | 231 | } |
232 | 232 | |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | * @return bool |
236 | 236 | * @phan-assert PropertyValueSnak $mainSnak |
237 | 237 | */ |
238 | - private function hasCorrectType( Snak $mainSnak ) { |
|
238 | + private function hasCorrectType(Snak $mainSnak) { |
|
239 | 239 | return $mainSnak instanceof PropertyValueSnak |
240 | 240 | && $mainSnak->getDataValue()->getType() === 'wikibase-entityid'; |
241 | 241 | } |
@@ -252,15 +252,15 @@ discard block |
||
252 | 252 | ) { |
253 | 253 | $statementArrays = []; |
254 | 254 | |
255 | - foreach ( $propertyIdSerializations as $propertyIdSerialization ) { |
|
256 | - $propertyId = new PropertyId( $propertyIdSerialization ); |
|
255 | + foreach ($propertyIdSerializations as $propertyIdSerialization) { |
|
256 | + $propertyId = new PropertyId($propertyIdSerialization); |
|
257 | 257 | $statementArrays[] = $statements |
258 | - ->getByPropertyId( $propertyId ) |
|
258 | + ->getByPropertyId($propertyId) |
|
259 | 259 | ->getBestStatements() |
260 | 260 | ->toArray(); |
261 | 261 | } |
262 | 262 | |
263 | - return call_user_func_array( 'array_merge', $statementArrays ); |
|
263 | + return call_user_func_array('array_merge', $statementArrays); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
@@ -272,10 +272,10 @@ discard block |
||
272 | 272 | * |
273 | 273 | * @return ViolationMessage |
274 | 274 | */ |
275 | - public function getViolationMessage( PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation ) { |
|
275 | + public function getViolationMessage(PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation) { |
|
276 | 276 | $classes = array_map( |
277 | - static function ( $itemIdSerialization ) { |
|
278 | - return new ItemId( $itemIdSerialization ); |
|
277 | + static function($itemIdSerialization) { |
|
278 | + return new ItemId($itemIdSerialization); |
|
279 | 279 | }, |
280 | 280 | $classes |
281 | 281 | ); |
@@ -287,10 +287,10 @@ discard block |
||
287 | 287 | // wbqc-violation-message-valueType-instance |
288 | 288 | // wbqc-violation-message-valueType-subclass |
289 | 289 | // wbqc-violation-message-valueType-instanceOrSubclass |
290 | - return ( new ViolationMessage( 'wbqc-violation-message-' . $checker . '-' . $relation ) ) |
|
291 | - ->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ) |
|
292 | - ->withEntityId( $entityId, Role::SUBJECT ) |
|
293 | - ->withEntityIdList( $classes, Role::OBJECT ); |
|
290 | + return (new ViolationMessage('wbqc-violation-message-'.$checker.'-'.$relation)) |
|
291 | + ->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY) |
|
292 | + ->withEntityId($entityId, Role::SUBJECT) |
|
293 | + ->withEntityIdList($classes, Role::OBJECT); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | } |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | */ |
39 | 39 | private const BATCH_SIZE = 50; |
40 | 40 | |
41 | - public static function newFromGlobalState( Title $title, array $params ) { |
|
42 | - Assert::parameterType( 'string', $params['propertyId'], '$params["propertyId"]' ); |
|
41 | + public static function newFromGlobalState(Title $title, array $params) { |
|
42 | + Assert::parameterType('string', $params['propertyId'], '$params["propertyId"]'); |
|
43 | 43 | $services = MediaWikiServices::getInstance(); |
44 | 44 | return new UpdateConstraintsTableJob( |
45 | 45 | $title, |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | $services->getMainConfig(), |
50 | 50 | ConstraintsServices::getConstraintStore(), |
51 | 51 | $services->getDBLoadBalancerFactory(), |
52 | - WikibaseRepo::getStore()->getEntityRevisionLookup( Store::LOOKUP_CACHING_DISABLED ), |
|
53 | - WikibaseRepo::getBaseDataModelSerializerFactory( $services ) |
|
52 | + WikibaseRepo::getStore()->getEntityRevisionLookup(Store::LOOKUP_CACHING_DISABLED), |
|
53 | + WikibaseRepo::getBaseDataModelSerializerFactory($services) |
|
54 | 54 | ->newSnakSerializer() |
55 | 55 | ); |
56 | 56 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | EntityRevisionLookup $entityRevisionLookup, |
111 | 111 | Serializer $snakSerializer |
112 | 112 | ) { |
113 | - parent::__construct( 'constraintsTableUpdate', $title, $params ); |
|
113 | + parent::__construct('constraintsTableUpdate', $title, $params); |
|
114 | 114 | |
115 | 115 | $this->propertyId = $propertyId; |
116 | 116 | $this->revisionId = $revisionId; |
@@ -121,11 +121,11 @@ discard block |
||
121 | 121 | $this->snakSerializer = $snakSerializer; |
122 | 122 | } |
123 | 123 | |
124 | - public function extractParametersFromQualifiers( SnakList $qualifiers ) { |
|
124 | + public function extractParametersFromQualifiers(SnakList $qualifiers) { |
|
125 | 125 | $parameters = []; |
126 | - foreach ( $qualifiers as $qualifier ) { |
|
126 | + foreach ($qualifiers as $qualifier) { |
|
127 | 127 | $qualifierId = $qualifier->getPropertyId()->getSerialization(); |
128 | - $paramSerialization = $this->snakSerializer->serialize( $qualifier ); |
|
128 | + $paramSerialization = $this->snakSerializer->serialize($qualifier); |
|
129 | 129 | $parameters[$qualifierId][] = $paramSerialization; |
130 | 130 | } |
131 | 131 | return $parameters; |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | '@phan-var \Wikibase\DataModel\Entity\EntityIdValue $dataValue'; |
143 | 143 | $entityId = $dataValue->getEntityId(); |
144 | 144 | $constraintTypeQid = $entityId->getSerialization(); |
145 | - $parameters = $this->extractParametersFromQualifiers( $constraintStatement->getQualifiers() ); |
|
145 | + $parameters = $this->extractParametersFromQualifiers($constraintStatement->getQualifiers()); |
|
146 | 146 | return new Constraint( |
147 | 147 | $constraintId, |
148 | 148 | $propertyId, |
@@ -157,24 +157,24 @@ discard block |
||
157 | 157 | PropertyId $propertyConstraintPropertyId |
158 | 158 | ) { |
159 | 159 | $constraintsStatements = $property->getStatements() |
160 | - ->getByPropertyId( $propertyConstraintPropertyId ) |
|
161 | - ->getByRank( [ Statement::RANK_PREFERRED, Statement::RANK_NORMAL ] ); |
|
160 | + ->getByPropertyId($propertyConstraintPropertyId) |
|
161 | + ->getByRank([Statement::RANK_PREFERRED, Statement::RANK_NORMAL]); |
|
162 | 162 | $constraints = []; |
163 | - foreach ( $constraintsStatements->getIterator() as $constraintStatement ) { |
|
164 | - $constraints[] = $this->extractConstraintFromStatement( $property->getId(), $constraintStatement ); |
|
165 | - if ( count( $constraints ) >= self::BATCH_SIZE ) { |
|
166 | - $constraintStore->insertBatch( $constraints ); |
|
163 | + foreach ($constraintsStatements->getIterator() as $constraintStatement) { |
|
164 | + $constraints[] = $this->extractConstraintFromStatement($property->getId(), $constraintStatement); |
|
165 | + if (count($constraints) >= self::BATCH_SIZE) { |
|
166 | + $constraintStore->insertBatch($constraints); |
|
167 | 167 | // interrupt transaction and wait for replication |
168 | - $connection = $this->lbFactory->getMainLB()->getConnection( DB_PRIMARY ); |
|
169 | - $connection->endAtomic( __CLASS__ ); |
|
170 | - if ( !$connection->explicitTrxActive() ) { |
|
168 | + $connection = $this->lbFactory->getMainLB()->getConnection(DB_PRIMARY); |
|
169 | + $connection->endAtomic(__CLASS__); |
|
170 | + if (!$connection->explicitTrxActive()) { |
|
171 | 171 | $this->lbFactory->waitForReplication(); |
172 | 172 | } |
173 | - $connection->startAtomic( __CLASS__ ); |
|
173 | + $connection->startAtomic(__CLASS__); |
|
174 | 174 | $constraints = []; |
175 | 175 | } |
176 | 176 | } |
177 | - $constraintStore->insertBatch( $constraints ); |
|
177 | + $constraintStore->insertBatch($constraints); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -185,24 +185,24 @@ discard block |
||
185 | 185 | public function run() { |
186 | 186 | // TODO in the future: only touch constraints affected by the edit (requires T163465) |
187 | 187 | |
188 | - $propertyId = new PropertyId( $this->propertyId ); |
|
188 | + $propertyId = new PropertyId($this->propertyId); |
|
189 | 189 | $propertyRevision = $this->entityRevisionLookup->getEntityRevision( |
190 | 190 | $propertyId, |
191 | 191 | 0, // latest |
192 | 192 | LookupConstants::LATEST_FROM_REPLICA |
193 | 193 | ); |
194 | 194 | |
195 | - if ( $this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId ) { |
|
196 | - JobQueueGroup::singleton()->push( $this ); |
|
195 | + if ($this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId) { |
|
196 | + JobQueueGroup::singleton()->push($this); |
|
197 | 197 | return true; |
198 | 198 | } |
199 | 199 | |
200 | - $connection = $this->lbFactory->getMainLB()->getConnection( DB_PRIMARY ); |
|
200 | + $connection = $this->lbFactory->getMainLB()->getConnection(DB_PRIMARY); |
|
201 | 201 | // start transaction (if not started yet) – using __CLASS__, not __METHOD__, |
202 | 202 | // because importConstraintsForProperty() can interrupt the transaction |
203 | - $connection->startAtomic( __CLASS__ ); |
|
203 | + $connection->startAtomic(__CLASS__); |
|
204 | 204 | |
205 | - $this->constraintStore->deleteForProperty( $propertyId ); |
|
205 | + $this->constraintStore->deleteForProperty($propertyId); |
|
206 | 206 | |
207 | 207 | /** @var Property $property */ |
208 | 208 | $property = $propertyRevision->getEntity(); |
@@ -210,10 +210,10 @@ discard block |
||
210 | 210 | $this->importConstraintsForProperty( |
211 | 211 | $property, |
212 | 212 | $this->constraintStore, |
213 | - new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ) |
|
213 | + new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')) |
|
214 | 214 | ); |
215 | 215 | |
216 | - $connection->endAtomic( __CLASS__ ); |
|
216 | + $connection->endAtomic(__CLASS__); |
|
217 | 217 | |
218 | 218 | return true; |
219 | 219 | } |
@@ -24,16 +24,16 @@ discard block |
||
24 | 24 | * then using the main DBLoadBalancer service may be incorrect. |
25 | 25 | * @param string|false $dbName Database name ($domain for ILoadBalancer methods). |
26 | 26 | */ |
27 | - public function __construct( ILoadBalancer $lb, $dbName ) { |
|
27 | + public function __construct(ILoadBalancer $lb, $dbName) { |
|
28 | 28 | $this->lb = $lb; |
29 | 29 | $this->dbName = $dbName; |
30 | 30 | } |
31 | 31 | |
32 | - private function encodeConstraintParameters( array $constraintParameters ) { |
|
33 | - $json = json_encode( $constraintParameters, JSON_FORCE_OBJECT ); |
|
32 | + private function encodeConstraintParameters(array $constraintParameters) { |
|
33 | + $json = json_encode($constraintParameters, JSON_FORCE_OBJECT); |
|
34 | 34 | |
35 | - if ( strlen( $json ) > 50000 ) { |
|
36 | - $json = json_encode( [ '@error' => [ 'toolong' => true ] ] ); |
|
35 | + if (strlen($json) > 50000) { |
|
36 | + $json = json_encode(['@error' => ['toolong' => true]]); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | return $json; |
@@ -45,21 +45,21 @@ discard block |
||
45 | 45 | * @throws DBUnexpectedError |
46 | 46 | * @return bool |
47 | 47 | */ |
48 | - public function insertBatch( array $constraints ) { |
|
48 | + public function insertBatch(array $constraints) { |
|
49 | 49 | $accumulator = array_map( |
50 | - function ( Constraint $constraint ) { |
|
50 | + function(Constraint $constraint) { |
|
51 | 51 | return [ |
52 | 52 | 'constraint_guid' => $constraint->getConstraintId(), |
53 | 53 | 'pid' => $constraint->getPropertyId()->getNumericId(), |
54 | 54 | 'constraint_type_qid' => $constraint->getConstraintTypeItemId(), |
55 | - 'constraint_parameters' => $this->encodeConstraintParameters( $constraint->getConstraintParameters() ) |
|
55 | + 'constraint_parameters' => $this->encodeConstraintParameters($constraint->getConstraintParameters()) |
|
56 | 56 | ]; |
57 | 57 | }, |
58 | 58 | $constraints |
59 | 59 | ); |
60 | 60 | |
61 | - $dbw = $this->lb->getConnection( ILoadBalancer::DB_PRIMARY, [], $this->dbName ); |
|
62 | - return $dbw->insert( 'wbqc_constraints', $accumulator, __METHOD__ ); |
|
61 | + $dbw = $this->lb->getConnection(ILoadBalancer::DB_PRIMARY, [], $this->dbName); |
|
62 | + return $dbw->insert('wbqc_constraints', $accumulator, __METHOD__); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @throws DBUnexpectedError |
71 | 71 | */ |
72 | - public function deleteForProperty( PropertyId $propertyId ) { |
|
73 | - $dbw = $this->lb->getConnection( ILoadBalancer::DB_PRIMARY, [], $this->dbName ); |
|
72 | + public function deleteForProperty(PropertyId $propertyId) { |
|
73 | + $dbw = $this->lb->getConnection(ILoadBalancer::DB_PRIMARY, [], $this->dbName); |
|
74 | 74 | $dbw->delete( |
75 | 75 | 'wbqc_constraints', |
76 | 76 | [ |
@@ -28,46 +28,46 @@ discard block |
||
28 | 28 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResultSerializer; |
29 | 29 | |
30 | 30 | return [ |
31 | - ConstraintsServices::EXPIRY_LOCK => static function ( MediaWikiServices $services ) { |
|
32 | - return new ExpiryLock( ObjectCache::getInstance( CACHE_ANYTHING ) ); |
|
31 | + ConstraintsServices::EXPIRY_LOCK => static function(MediaWikiServices $services) { |
|
32 | + return new ExpiryLock(ObjectCache::getInstance(CACHE_ANYTHING)); |
|
33 | 33 | }, |
34 | 34 | |
35 | - ConstraintsServices::LOGGING_HELPER => static function ( MediaWikiServices $services ) { |
|
35 | + ConstraintsServices::LOGGING_HELPER => static function(MediaWikiServices $services) { |
|
36 | 36 | return new LoggingHelper( |
37 | 37 | $services->getStatsdDataFactory(), |
38 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ), |
|
38 | + LoggerFactory::getInstance('WikibaseQualityConstraints'), |
|
39 | 39 | $services->getMainConfig() |
40 | 40 | ); |
41 | 41 | }, |
42 | 42 | |
43 | - ConstraintsServices::CONSTRAINT_STORE => static function ( MediaWikiServices $services ) { |
|
44 | - $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
45 | - $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType( Property::ENTITY_TYPE ); |
|
43 | + ConstraintsServices::CONSTRAINT_STORE => static function(MediaWikiServices $services) { |
|
44 | + $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
45 | + $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType(Property::ENTITY_TYPE); |
|
46 | 46 | $dbName = $propertySource->getDatabaseName(); |
47 | - $localEntitySourceName = WikibaseRepo::getLocalEntitySource( $services )->getSourceName(); |
|
47 | + $localEntitySourceName = WikibaseRepo::getLocalEntitySource($services)->getSourceName(); |
|
48 | 48 | |
49 | - if ( $propertySource->getSourceName() !== $localEntitySourceName ) { |
|
50 | - throw new \RuntimeException( 'Can\'t get a ConstraintStore for a non local entity source.' ); |
|
49 | + if ($propertySource->getSourceName() !== $localEntitySourceName) { |
|
50 | + throw new \RuntimeException('Can\'t get a ConstraintStore for a non local entity source.'); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | return new ConstraintRepositoryStore( |
54 | - $services->getDBLoadBalancerFactory()->getMainLB( $dbName ), |
|
54 | + $services->getDBLoadBalancerFactory()->getMainLB($dbName), |
|
55 | 55 | $dbName |
56 | 56 | ); |
57 | 57 | }, |
58 | 58 | |
59 | - ConstraintsServices::CONSTRAINT_LOOKUP => static function ( MediaWikiServices $services ) { |
|
60 | - $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
61 | - $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType( Property::ENTITY_TYPE ); |
|
59 | + ConstraintsServices::CONSTRAINT_LOOKUP => static function(MediaWikiServices $services) { |
|
60 | + $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
61 | + $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType(Property::ENTITY_TYPE); |
|
62 | 62 | $dbName = $propertySource->getDatabaseName(); |
63 | 63 | $rawLookup = new ConstraintRepositoryLookup( |
64 | - $services->getDBLoadBalancerFactory()->getMainLB( $dbName ), |
|
64 | + $services->getDBLoadBalancerFactory()->getMainLB($dbName), |
|
65 | 65 | $dbName |
66 | 66 | ); |
67 | - return new CachingConstraintLookup( $rawLookup ); |
|
67 | + return new CachingConstraintLookup($rawLookup); |
|
68 | 68 | }, |
69 | 69 | |
70 | - ConstraintsServices::CHECK_RESULT_SERIALIZER => static function ( MediaWikiServices $services ) { |
|
70 | + ConstraintsServices::CHECK_RESULT_SERIALIZER => static function(MediaWikiServices $services) { |
|
71 | 71 | return new CheckResultSerializer( |
72 | 72 | new ConstraintSerializer( |
73 | 73 | false // constraint parameters are not exposed |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | ); |
79 | 79 | }, |
80 | 80 | |
81 | - ConstraintsServices::CHECK_RESULT_DESERIALIZER => static function ( MediaWikiServices $services ) { |
|
82 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
83 | - $dataValueFactory = WikibaseRepo::getDataValueFactory( $services ); |
|
81 | + ConstraintsServices::CHECK_RESULT_DESERIALIZER => static function(MediaWikiServices $services) { |
|
82 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
83 | + $dataValueFactory = WikibaseRepo::getDataValueFactory($services); |
|
84 | 84 | |
85 | 85 | return new CheckResultDeserializer( |
86 | 86 | new ConstraintDeserializer(), |
@@ -93,13 +93,13 @@ discard block |
||
93 | 93 | ); |
94 | 94 | }, |
95 | 95 | |
96 | - ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => static function ( MediaWikiServices $services ) { |
|
96 | + ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => static function(MediaWikiServices $services) { |
|
97 | 97 | return new ViolationMessageSerializer(); |
98 | 98 | }, |
99 | 99 | |
100 | - ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => static function ( MediaWikiServices $services ) { |
|
101 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
102 | - $dataValueFactory = WikibaseRepo::getDataValueFactory( $services ); |
|
100 | + ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => static function(MediaWikiServices $services) { |
|
101 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
102 | + $dataValueFactory = WikibaseRepo::getDataValueFactory($services); |
|
103 | 103 | |
104 | 104 | return new ViolationMessageDeserializer( |
105 | 105 | $entityIdParser, |
@@ -107,37 +107,37 @@ discard block |
||
107 | 107 | ); |
108 | 108 | }, |
109 | 109 | |
110 | - ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => static function ( MediaWikiServices $services ) { |
|
111 | - $deserializerFactory = WikibaseRepo::getBaseDataModelDeserializerFactory( $services ); |
|
112 | - $entitySourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
110 | + ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => static function(MediaWikiServices $services) { |
|
111 | + $deserializerFactory = WikibaseRepo::getBaseDataModelDeserializerFactory($services); |
|
112 | + $entitySourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
113 | 113 | |
114 | 114 | return new ConstraintParameterParser( |
115 | 115 | $services->getMainConfig(), |
116 | 116 | $deserializerFactory, |
117 | - $entitySourceDefinitions->getDatabaseSourceForEntityType( 'item' )->getConceptBaseUri() |
|
117 | + $entitySourceDefinitions->getDatabaseSourceForEntityType('item')->getConceptBaseUri() |
|
118 | 118 | ); |
119 | 119 | }, |
120 | 120 | |
121 | - ConstraintsServices::CONNECTION_CHECKER_HELPER => static function ( MediaWikiServices $services ) { |
|
121 | + ConstraintsServices::CONNECTION_CHECKER_HELPER => static function(MediaWikiServices $services) { |
|
122 | 122 | return new ConnectionCheckerHelper(); |
123 | 123 | }, |
124 | 124 | |
125 | - ConstraintsServices::RANGE_CHECKER_HELPER => static function ( MediaWikiServices $services ) { |
|
125 | + ConstraintsServices::RANGE_CHECKER_HELPER => static function(MediaWikiServices $services) { |
|
126 | 126 | return new RangeCheckerHelper( |
127 | 127 | $services->getMainConfig(), |
128 | - WikibaseRepo::getUnitConverter( $services ) |
|
128 | + WikibaseRepo::getUnitConverter($services) |
|
129 | 129 | ); |
130 | 130 | }, |
131 | 131 | |
132 | - ConstraintsServices::SPARQL_HELPER => static function ( MediaWikiServices $services ) { |
|
133 | - $endpoint = $services->getMainConfig()->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
134 | - if ( $endpoint === '' ) { |
|
132 | + ConstraintsServices::SPARQL_HELPER => static function(MediaWikiServices $services) { |
|
133 | + $endpoint = $services->getMainConfig()->get('WBQualityConstraintsSparqlEndpoint'); |
|
134 | + if ($endpoint === '') { |
|
135 | 135 | return new DummySparqlHelper(); |
136 | 136 | } |
137 | 137 | |
138 | - $rdfVocabulary = WikibaseRepo::getRdfVocabulary( $services ); |
|
139 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
140 | - $propertyDataTypeLookup = WikibaseRepo::getPropertyDataTypeLookup( $services ); |
|
138 | + $rdfVocabulary = WikibaseRepo::getRdfVocabulary($services); |
|
139 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
140 | + $propertyDataTypeLookup = WikibaseRepo::getPropertyDataTypeLookup($services); |
|
141 | 141 | |
142 | 142 | return new SparqlHelper( |
143 | 143 | $services->getMainConfig(), |
@@ -145,124 +145,124 @@ discard block |
||
145 | 145 | $entityIdParser, |
146 | 146 | $propertyDataTypeLookup, |
147 | 147 | $services->getMainWANObjectCache(), |
148 | - ConstraintsServices::getViolationMessageSerializer( $services ), |
|
149 | - ConstraintsServices::getViolationMessageDeserializer( $services ), |
|
148 | + ConstraintsServices::getViolationMessageSerializer($services), |
|
149 | + ConstraintsServices::getViolationMessageDeserializer($services), |
|
150 | 150 | $services->getStatsdDataFactory(), |
151 | - ConstraintsServices::getExpiryLock( $services ), |
|
152 | - ConstraintsServices::getLoggingHelper( $services ), |
|
153 | - wfWikiID() . ' WikibaseQualityConstraints ' . Http::userAgent(), |
|
151 | + ConstraintsServices::getExpiryLock($services), |
|
152 | + ConstraintsServices::getLoggingHelper($services), |
|
153 | + wfWikiID().' WikibaseQualityConstraints '.Http::userAgent(), |
|
154 | 154 | $services->getHttpRequestFactory() |
155 | 155 | ); |
156 | 156 | }, |
157 | 157 | |
158 | - ConstraintsServices::TYPE_CHECKER_HELPER => static function ( MediaWikiServices $services ) { |
|
158 | + ConstraintsServices::TYPE_CHECKER_HELPER => static function(MediaWikiServices $services) { |
|
159 | 159 | return new TypeCheckerHelper( |
160 | - WikibaseServices::getEntityLookup( $services ), |
|
160 | + WikibaseServices::getEntityLookup($services), |
|
161 | 161 | $services->getMainConfig(), |
162 | - ConstraintsServices::getSparqlHelper( $services ), |
|
162 | + ConstraintsServices::getSparqlHelper($services), |
|
163 | 163 | $services->getStatsdDataFactory() |
164 | 164 | ); |
165 | 165 | }, |
166 | 166 | |
167 | - ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => static function ( MediaWikiServices $services ) { |
|
168 | - $statementGuidParser = WikibaseRepo::getStatementGuidParser( $services ); |
|
167 | + ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => static function(MediaWikiServices $services) { |
|
168 | + $statementGuidParser = WikibaseRepo::getStatementGuidParser($services); |
|
169 | 169 | |
170 | 170 | $config = $services->getMainConfig(); |
171 | 171 | $checkerMap = [ |
172 | - $config->get( 'WBQualityConstraintsConflictsWithConstraintId' ) |
|
173 | - => ConstraintCheckerServices::getConflictsWithChecker( $services ), |
|
174 | - $config->get( 'WBQualityConstraintsItemRequiresClaimConstraintId' ) |
|
175 | - => ConstraintCheckerServices::getItemChecker( $services ), |
|
176 | - $config->get( 'WBQualityConstraintsValueRequiresClaimConstraintId' ) |
|
177 | - => ConstraintCheckerServices::getTargetRequiredClaimChecker( $services ), |
|
178 | - $config->get( 'WBQualityConstraintsSymmetricConstraintId' ) |
|
179 | - => ConstraintCheckerServices::getSymmetricChecker( $services ), |
|
180 | - $config->get( 'WBQualityConstraintsInverseConstraintId' ) |
|
181 | - => ConstraintCheckerServices::getInverseChecker( $services ), |
|
182 | - $config->get( 'WBQualityConstraintsUsedAsQualifierConstraintId' ) |
|
183 | - => ConstraintCheckerServices::getQualifierChecker( $services ), |
|
184 | - $config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' ) |
|
185 | - => ConstraintCheckerServices::getQualifiersChecker( $services ), |
|
186 | - $config->get( 'WBQualityConstraintsMandatoryQualifierConstraintId' ) |
|
187 | - => ConstraintCheckerServices::getMandatoryQualifiersChecker( $services ), |
|
188 | - $config->get( 'WBQualityConstraintsRangeConstraintId' ) |
|
189 | - => ConstraintCheckerServices::getRangeChecker( $services ), |
|
190 | - $config->get( 'WBQualityConstraintsDifferenceWithinRangeConstraintId' ) |
|
191 | - => ConstraintCheckerServices::getDiffWithinRangeChecker( $services ), |
|
192 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ) |
|
193 | - => ConstraintCheckerServices::getTypeChecker( $services ), |
|
194 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ) |
|
195 | - => ConstraintCheckerServices::getValueTypeChecker( $services ), |
|
196 | - $config->get( 'WBQualityConstraintsSingleValueConstraintId' ) |
|
197 | - => ConstraintCheckerServices::getSingleValueChecker( $services ), |
|
198 | - $config->get( 'WBQualityConstraintsMultiValueConstraintId' ) |
|
199 | - => ConstraintCheckerServices::getMultiValueChecker( $services ), |
|
200 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ) |
|
201 | - => ConstraintCheckerServices::getUniqueValueChecker( $services ), |
|
202 | - $config->get( 'WBQualityConstraintsFormatConstraintId' ) |
|
203 | - => ConstraintCheckerServices::getFormatChecker( $services ), |
|
204 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ) |
|
205 | - => ConstraintCheckerServices::getCommonsLinkChecker( $services ), |
|
206 | - $config->get( 'WBQualityConstraintsOneOfConstraintId' ) |
|
207 | - => ConstraintCheckerServices::getOneOfChecker( $services ), |
|
208 | - $config->get( 'WBQualityConstraintsUsedForValuesOnlyConstraintId' ) |
|
209 | - => ConstraintCheckerServices::getValueOnlyChecker( $services ), |
|
210 | - $config->get( 'WBQualityConstraintsUsedAsReferenceConstraintId' ) |
|
211 | - => ConstraintCheckerServices::getReferenceChecker( $services ), |
|
212 | - $config->get( 'WBQualityConstraintsNoBoundsConstraintId' ) |
|
213 | - => ConstraintCheckerServices::getNoBoundsChecker( $services ), |
|
214 | - $config->get( 'WBQualityConstraintsAllowedUnitsConstraintId' ) |
|
215 | - => ConstraintCheckerServices::getAllowedUnitsChecker( $services ), |
|
216 | - $config->get( 'WBQualityConstraintsSingleBestValueConstraintId' ) |
|
217 | - => ConstraintCheckerServices::getSingleBestValueChecker( $services ), |
|
218 | - $config->get( 'WBQualityConstraintsAllowedEntityTypesConstraintId' ) |
|
219 | - => ConstraintCheckerServices::getEntityTypeChecker( $services ), |
|
220 | - $config->get( 'WBQualityConstraintsNoneOfConstraintId' ) |
|
221 | - => ConstraintCheckerServices::getNoneOfChecker( $services ), |
|
222 | - $config->get( 'WBQualityConstraintsIntegerConstraintId' ) |
|
223 | - => ConstraintCheckerServices::getIntegerChecker( $services ), |
|
224 | - $config->get( 'WBQualityConstraintsCitationNeededConstraintId' ) |
|
225 | - => ConstraintCheckerServices::getCitationNeededChecker( $services ), |
|
226 | - $config->get( 'WBQualityConstraintsPropertyScopeConstraintId' ) |
|
227 | - => ConstraintCheckerServices::getPropertyScopeChecker( $services ), |
|
228 | - $config->get( 'WBQualityConstraintsContemporaryConstraintId' ) |
|
229 | - => ConstraintCheckerServices::getContemporaryChecker( $services ), |
|
230 | - $config->get( 'WBQualityConstraintsLexemeLanguageConstraintId' ) |
|
231 | - => ConstraintCheckerServices::getLexemeLanguageChecker( $services ), |
|
172 | + $config->get('WBQualityConstraintsConflictsWithConstraintId') |
|
173 | + => ConstraintCheckerServices::getConflictsWithChecker($services), |
|
174 | + $config->get('WBQualityConstraintsItemRequiresClaimConstraintId') |
|
175 | + => ConstraintCheckerServices::getItemChecker($services), |
|
176 | + $config->get('WBQualityConstraintsValueRequiresClaimConstraintId') |
|
177 | + => ConstraintCheckerServices::getTargetRequiredClaimChecker($services), |
|
178 | + $config->get('WBQualityConstraintsSymmetricConstraintId') |
|
179 | + => ConstraintCheckerServices::getSymmetricChecker($services), |
|
180 | + $config->get('WBQualityConstraintsInverseConstraintId') |
|
181 | + => ConstraintCheckerServices::getInverseChecker($services), |
|
182 | + $config->get('WBQualityConstraintsUsedAsQualifierConstraintId') |
|
183 | + => ConstraintCheckerServices::getQualifierChecker($services), |
|
184 | + $config->get('WBQualityConstraintsAllowedQualifiersConstraintId') |
|
185 | + => ConstraintCheckerServices::getQualifiersChecker($services), |
|
186 | + $config->get('WBQualityConstraintsMandatoryQualifierConstraintId') |
|
187 | + => ConstraintCheckerServices::getMandatoryQualifiersChecker($services), |
|
188 | + $config->get('WBQualityConstraintsRangeConstraintId') |
|
189 | + => ConstraintCheckerServices::getRangeChecker($services), |
|
190 | + $config->get('WBQualityConstraintsDifferenceWithinRangeConstraintId') |
|
191 | + => ConstraintCheckerServices::getDiffWithinRangeChecker($services), |
|
192 | + $config->get('WBQualityConstraintsTypeConstraintId') |
|
193 | + => ConstraintCheckerServices::getTypeChecker($services), |
|
194 | + $config->get('WBQualityConstraintsValueTypeConstraintId') |
|
195 | + => ConstraintCheckerServices::getValueTypeChecker($services), |
|
196 | + $config->get('WBQualityConstraintsSingleValueConstraintId') |
|
197 | + => ConstraintCheckerServices::getSingleValueChecker($services), |
|
198 | + $config->get('WBQualityConstraintsMultiValueConstraintId') |
|
199 | + => ConstraintCheckerServices::getMultiValueChecker($services), |
|
200 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId') |
|
201 | + => ConstraintCheckerServices::getUniqueValueChecker($services), |
|
202 | + $config->get('WBQualityConstraintsFormatConstraintId') |
|
203 | + => ConstraintCheckerServices::getFormatChecker($services), |
|
204 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId') |
|
205 | + => ConstraintCheckerServices::getCommonsLinkChecker($services), |
|
206 | + $config->get('WBQualityConstraintsOneOfConstraintId') |
|
207 | + => ConstraintCheckerServices::getOneOfChecker($services), |
|
208 | + $config->get('WBQualityConstraintsUsedForValuesOnlyConstraintId') |
|
209 | + => ConstraintCheckerServices::getValueOnlyChecker($services), |
|
210 | + $config->get('WBQualityConstraintsUsedAsReferenceConstraintId') |
|
211 | + => ConstraintCheckerServices::getReferenceChecker($services), |
|
212 | + $config->get('WBQualityConstraintsNoBoundsConstraintId') |
|
213 | + => ConstraintCheckerServices::getNoBoundsChecker($services), |
|
214 | + $config->get('WBQualityConstraintsAllowedUnitsConstraintId') |
|
215 | + => ConstraintCheckerServices::getAllowedUnitsChecker($services), |
|
216 | + $config->get('WBQualityConstraintsSingleBestValueConstraintId') |
|
217 | + => ConstraintCheckerServices::getSingleBestValueChecker($services), |
|
218 | + $config->get('WBQualityConstraintsAllowedEntityTypesConstraintId') |
|
219 | + => ConstraintCheckerServices::getEntityTypeChecker($services), |
|
220 | + $config->get('WBQualityConstraintsNoneOfConstraintId') |
|
221 | + => ConstraintCheckerServices::getNoneOfChecker($services), |
|
222 | + $config->get('WBQualityConstraintsIntegerConstraintId') |
|
223 | + => ConstraintCheckerServices::getIntegerChecker($services), |
|
224 | + $config->get('WBQualityConstraintsCitationNeededConstraintId') |
|
225 | + => ConstraintCheckerServices::getCitationNeededChecker($services), |
|
226 | + $config->get('WBQualityConstraintsPropertyScopeConstraintId') |
|
227 | + => ConstraintCheckerServices::getPropertyScopeChecker($services), |
|
228 | + $config->get('WBQualityConstraintsContemporaryConstraintId') |
|
229 | + => ConstraintCheckerServices::getContemporaryChecker($services), |
|
230 | + $config->get('WBQualityConstraintsLexemeLanguageConstraintId') |
|
231 | + => ConstraintCheckerServices::getLexemeLanguageChecker($services), |
|
232 | 232 | ]; |
233 | 233 | |
234 | 234 | return new DelegatingConstraintChecker( |
235 | - WikibaseServices::getEntityLookup( $services ), |
|
235 | + WikibaseServices::getEntityLookup($services), |
|
236 | 236 | $checkerMap, |
237 | - ConstraintsServices::getConstraintLookup( $services ), |
|
238 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
237 | + ConstraintsServices::getConstraintLookup($services), |
|
238 | + ConstraintsServices::getConstraintParameterParser($services), |
|
239 | 239 | $statementGuidParser, |
240 | - ConstraintsServices::getLoggingHelper( $services ), |
|
241 | - $config->get( 'WBQualityConstraintsCheckQualifiers' ), |
|
242 | - $config->get( 'WBQualityConstraintsCheckReferences' ), |
|
243 | - $config->get( 'WBQualityConstraintsPropertiesWithViolatingQualifiers' ) |
|
240 | + ConstraintsServices::getLoggingHelper($services), |
|
241 | + $config->get('WBQualityConstraintsCheckQualifiers'), |
|
242 | + $config->get('WBQualityConstraintsCheckReferences'), |
|
243 | + $config->get('WBQualityConstraintsPropertiesWithViolatingQualifiers') |
|
244 | 244 | ); |
245 | 245 | }, |
246 | 246 | |
247 | - ConstraintsServices::RESULTS_SOURCE => static function ( MediaWikiServices $services ) { |
|
247 | + ConstraintsServices::RESULTS_SOURCE => static function(MediaWikiServices $services) { |
|
248 | 248 | $config = $services->getMainConfig(); |
249 | 249 | $resultsSource = new CheckingResultsSource( |
250 | - ConstraintsServices::getDelegatingConstraintChecker( $services ) |
|
250 | + ConstraintsServices::getDelegatingConstraintChecker($services) |
|
251 | 251 | ); |
252 | 252 | |
253 | 253 | $cacheCheckConstraintsResults = false; |
254 | 254 | |
255 | - if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) { |
|
255 | + if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) { |
|
256 | 256 | $cacheCheckConstraintsResults = true; |
257 | 257 | // check that we can use getLocalRepoWikiPageMetaDataAccessor() |
258 | 258 | // TODO we should always be able to cache constraint check results (T244726) |
259 | - $entitySources = WikibaseRepo::getEntitySourceDefinitions( $services )->getSources(); |
|
260 | - $localEntitySourceName = WikibaseRepo::getLocalEntitySource( $services )->getSourceName(); |
|
259 | + $entitySources = WikibaseRepo::getEntitySourceDefinitions($services)->getSources(); |
|
260 | + $localEntitySourceName = WikibaseRepo::getLocalEntitySource($services)->getSourceName(); |
|
261 | 261 | |
262 | - foreach ( $entitySources as $entitySource ) { |
|
263 | - if ( $entitySource->getSourceName() !== $localEntitySourceName ) { |
|
264 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' )->warning( |
|
265 | - 'Cannot cache constraint check results for non-local source: ' . |
|
262 | + foreach ($entitySources as $entitySource) { |
|
263 | + if ($entitySource->getSourceName() !== $localEntitySourceName) { |
|
264 | + LoggerFactory::getInstance('WikibaseQualityConstraints')->warning( |
|
265 | + 'Cannot cache constraint check results for non-local source: '. |
|
266 | 266 | $entitySource->getSourceName() |
267 | 267 | ); |
268 | 268 | $cacheCheckConstraintsResults = false; |
@@ -271,28 +271,28 @@ discard block |
||
271 | 271 | } |
272 | 272 | } |
273 | 273 | |
274 | - if ( $cacheCheckConstraintsResults ) { |
|
274 | + if ($cacheCheckConstraintsResults) { |
|
275 | 275 | $possiblyStaleConstraintTypes = [ |
276 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ), |
|
277 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ), |
|
278 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ), |
|
279 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ), |
|
276 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId'), |
|
277 | + $config->get('WBQualityConstraintsTypeConstraintId'), |
|
278 | + $config->get('WBQualityConstraintsValueTypeConstraintId'), |
|
279 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId'), |
|
280 | 280 | ]; |
281 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
281 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
282 | 282 | $wikiPageEntityMetaDataAccessor = WikibaseRepo::getLocalRepoWikiPageMetaDataAccessor( |
283 | 283 | $services ); |
284 | 284 | |
285 | 285 | $resultsSource = new CachingResultsSource( |
286 | 286 | $resultsSource, |
287 | 287 | ResultsCache::getDefaultInstance(), |
288 | - ConstraintsServices::getCheckResultSerializer( $services ), |
|
289 | - ConstraintsServices::getCheckResultDeserializer( $services ), |
|
288 | + ConstraintsServices::getCheckResultSerializer($services), |
|
289 | + ConstraintsServices::getCheckResultDeserializer($services), |
|
290 | 290 | $wikiPageEntityMetaDataAccessor, |
291 | 291 | $entityIdParser, |
292 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ), |
|
292 | + $config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'), |
|
293 | 293 | $possiblyStaleConstraintTypes, |
294 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds' ), |
|
295 | - ConstraintsServices::getLoggingHelper( $services ) |
|
294 | + $config->get('WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds'), |
|
295 | + ConstraintsServices::getLoggingHelper($services) |
|
296 | 296 | ); |
297 | 297 | } |
298 | 298 |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | callable $defaultResultsPerEntity = null |
144 | 144 | ) { |
145 | 145 | $checkResults = []; |
146 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
146 | + $entity = $this->entityLookup->getEntity($entityId); |
|
147 | 147 | |
148 | - if ( $entity instanceof StatementListProvidingEntity ) { |
|
149 | - $startTime = microtime( true ); |
|
148 | + if ($entity instanceof StatementListProvidingEntity) { |
|
149 | + $startTime = microtime(true); |
|
150 | 150 | |
151 | 151 | $checkResults = $this->checkEveryStatement( |
152 | 152 | $entity, |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | $defaultResultsPerContext |
155 | 155 | ); |
156 | 156 | |
157 | - $endTime = microtime( true ); |
|
157 | + $endTime = microtime(true); |
|
158 | 158 | |
159 | - if ( $constraintIds === null ) { // only log full constraint checks |
|
159 | + if ($constraintIds === null) { // only log full constraint checks |
|
160 | 160 | $this->loggingHelper->logConstraintCheckOnEntity( |
161 | 161 | $entityId, |
162 | 162 | $checkResults, |
@@ -166,11 +166,11 @@ discard block |
||
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
169 | - if ( $defaultResultsPerEntity !== null ) { |
|
170 | - $checkResults = array_merge( $defaultResultsPerEntity( $entityId ), $checkResults ); |
|
169 | + if ($defaultResultsPerEntity !== null) { |
|
170 | + $checkResults = array_merge($defaultResultsPerEntity($entityId), $checkResults); |
|
171 | 171 | } |
172 | 172 | |
173 | - return $this->sortResult( $checkResults ); |
|
173 | + return $this->sortResult($checkResults); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -192,19 +192,19 @@ discard block |
||
192 | 192 | callable $defaultResults = null |
193 | 193 | ) { |
194 | 194 | |
195 | - $parsedGuid = $this->statementGuidParser->parse( $guid ); |
|
195 | + $parsedGuid = $this->statementGuidParser->parse($guid); |
|
196 | 196 | $entityId = $parsedGuid->getEntityId(); |
197 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
198 | - if ( $entity instanceof StatementListProvidingEntity ) { |
|
199 | - $statement = $entity->getStatements()->getFirstStatementWithGuid( $guid ); |
|
200 | - if ( $statement ) { |
|
197 | + $entity = $this->entityLookup->getEntity($entityId); |
|
198 | + if ($entity instanceof StatementListProvidingEntity) { |
|
199 | + $statement = $entity->getStatements()->getFirstStatementWithGuid($guid); |
|
200 | + if ($statement) { |
|
201 | 201 | $result = $this->checkStatement( |
202 | 202 | $entity, |
203 | 203 | $statement, |
204 | 204 | $constraintIds, |
205 | 205 | $defaultResults |
206 | 206 | ); |
207 | - $output = $this->sortResult( $result ); |
|
207 | + $output = $this->sortResult($result); |
|
208 | 208 | return $output; |
209 | 209 | } |
210 | 210 | } |
@@ -212,8 +212,8 @@ discard block |
||
212 | 212 | return []; |
213 | 213 | } |
214 | 214 | |
215 | - private function getAllowedContextTypes( Constraint $constraint ) { |
|
216 | - if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
215 | + private function getAllowedContextTypes(Constraint $constraint) { |
|
216 | + if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
217 | 217 | return [ |
218 | 218 | Context::TYPE_STATEMENT, |
219 | 219 | Context::TYPE_QUALIFIER, |
@@ -221,12 +221,12 @@ discard block |
||
221 | 221 | ]; |
222 | 222 | } |
223 | 223 | |
224 | - return array_keys( array_filter( |
|
224 | + return array_keys(array_filter( |
|
225 | 225 | $this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedContextTypes(), |
226 | - static function ( $resultStatus ) { |
|
226 | + static function($resultStatus) { |
|
227 | 227 | return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE; |
228 | 228 | } |
229 | - ) ); |
|
229 | + )); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -237,32 +237,32 @@ discard block |
||
237 | 237 | * |
238 | 238 | * @return ConstraintParameterException[] |
239 | 239 | */ |
240 | - private function checkCommonConstraintParameters( Constraint $constraint ) { |
|
240 | + private function checkCommonConstraintParameters(Constraint $constraint) { |
|
241 | 241 | $constraintParameters = $constraint->getConstraintParameters(); |
242 | 242 | try { |
243 | - $this->constraintParameterParser->checkError( $constraintParameters ); |
|
244 | - } catch ( ConstraintParameterException $e ) { |
|
245 | - return [ $e ]; |
|
243 | + $this->constraintParameterParser->checkError($constraintParameters); |
|
244 | + } catch (ConstraintParameterException $e) { |
|
245 | + return [$e]; |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | $problems = []; |
249 | 249 | try { |
250 | - $this->constraintParameterParser->parseExceptionParameter( $constraintParameters ); |
|
251 | - } catch ( ConstraintParameterException $e ) { |
|
250 | + $this->constraintParameterParser->parseExceptionParameter($constraintParameters); |
|
251 | + } catch (ConstraintParameterException $e) { |
|
252 | 252 | $problems[] = $e; |
253 | 253 | } |
254 | 254 | try { |
255 | - $this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters ); |
|
256 | - } catch ( ConstraintParameterException $e ) { |
|
255 | + $this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters); |
|
256 | + } catch (ConstraintParameterException $e) { |
|
257 | 257 | $problems[] = $e; |
258 | 258 | } |
259 | 259 | try { |
260 | 260 | $this->constraintParameterParser->parseConstraintScopeParameter( |
261 | 261 | $constraintParameters, |
262 | 262 | $constraint->getConstraintTypeItemId(), |
263 | - $this->getAllowedContextTypes( $constraint ) |
|
263 | + $this->getAllowedContextTypes($constraint) |
|
264 | 264 | ); |
265 | - } catch ( ConstraintParameterException $e ) { |
|
265 | + } catch (ConstraintParameterException $e) { |
|
266 | 266 | $problems[] = $e; |
267 | 267 | } |
268 | 268 | return $problems; |
@@ -275,16 +275,16 @@ discard block |
||
275 | 275 | * @return ConstraintParameterException[][] first level indexed by constraint ID, |
276 | 276 | * second level like checkConstraintParametersOnConstraintId (but without possibility of null) |
277 | 277 | */ |
278 | - public function checkConstraintParametersOnPropertyId( PropertyId $propertyId ) { |
|
279 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
278 | + public function checkConstraintParametersOnPropertyId(PropertyId $propertyId) { |
|
279 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
280 | 280 | $result = []; |
281 | 281 | |
282 | - foreach ( $constraints as $constraint ) { |
|
283 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
282 | + foreach ($constraints as $constraint) { |
|
283 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
284 | 284 | |
285 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
285 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
286 | 286 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
287 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
287 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | $result[$constraint->getConstraintId()] = $problems; |
@@ -301,18 +301,18 @@ discard block |
||
301 | 301 | * @return ConstraintParameterException[]|null list of constraint parameter exceptions |
302 | 302 | * (empty means all parameters okay), or null if constraint is not found |
303 | 303 | */ |
304 | - public function checkConstraintParametersOnConstraintId( $constraintId ) { |
|
305 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
304 | + public function checkConstraintParametersOnConstraintId($constraintId) { |
|
305 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
306 | 306 | '@phan-var PropertyId $propertyId'; |
307 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
307 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
308 | 308 | |
309 | - foreach ( $constraints as $constraint ) { |
|
310 | - if ( $constraint->getConstraintId() === $constraintId ) { |
|
311 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
309 | + foreach ($constraints as $constraint) { |
|
310 | + if ($constraint->getConstraintId() === $constraintId) { |
|
311 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
312 | 312 | |
313 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
313 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
314 | 314 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
315 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
315 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | return $problems; |
@@ -337,14 +337,14 @@ discard block |
||
337 | 337 | $result = []; |
338 | 338 | |
339 | 339 | /** @var Statement $statement */ |
340 | - foreach ( $entity->getStatements() as $statement ) { |
|
341 | - $result = array_merge( $result, |
|
340 | + foreach ($entity->getStatements() as $statement) { |
|
341 | + $result = array_merge($result, |
|
342 | 342 | $this->checkStatement( |
343 | 343 | $entity, |
344 | 344 | $statement, |
345 | 345 | $constraintIds, |
346 | 346 | $defaultResultsPerContext |
347 | - ) ); |
|
347 | + )); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | return $result; |
@@ -366,32 +366,32 @@ discard block |
||
366 | 366 | ) { |
367 | 367 | $result = []; |
368 | 368 | |
369 | - $result = array_merge( $result, |
|
369 | + $result = array_merge($result, |
|
370 | 370 | $this->checkConstraintsForMainSnak( |
371 | 371 | $entity, |
372 | 372 | $statement, |
373 | 373 | $constraintIds, |
374 | 374 | $defaultResultsPerContext |
375 | - ) ); |
|
375 | + )); |
|
376 | 376 | |
377 | - if ( $this->checkQualifiers ) { |
|
378 | - $result = array_merge( $result, |
|
377 | + if ($this->checkQualifiers) { |
|
378 | + $result = array_merge($result, |
|
379 | 379 | $this->checkConstraintsForQualifiers( |
380 | 380 | $entity, |
381 | 381 | $statement, |
382 | 382 | $constraintIds, |
383 | 383 | $defaultResultsPerContext |
384 | - ) ); |
|
384 | + )); |
|
385 | 385 | } |
386 | 386 | |
387 | - if ( $this->checkReferences ) { |
|
388 | - $result = array_merge( $result, |
|
387 | + if ($this->checkReferences) { |
|
388 | + $result = array_merge($result, |
|
389 | 389 | $this->checkConstraintsForReferences( |
390 | 390 | $entity, |
391 | 391 | $statement, |
392 | 392 | $constraintIds, |
393 | 393 | $defaultResultsPerContext |
394 | - ) ); |
|
394 | + )); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | return $result; |
@@ -406,12 +406,12 @@ discard block |
||
406 | 406 | * @param string[]|null $constraintIds |
407 | 407 | * @return Constraint[] |
408 | 408 | */ |
409 | - private function getConstraintsToUse( PropertyId $propertyId, array $constraintIds = null ) { |
|
410 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
411 | - if ( $constraintIds !== null ) { |
|
409 | + private function getConstraintsToUse(PropertyId $propertyId, array $constraintIds = null) { |
|
410 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
411 | + if ($constraintIds !== null) { |
|
412 | 412 | $constraintsToUse = []; |
413 | - foreach ( $constraints as $constraint ) { |
|
414 | - if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) { |
|
413 | + foreach ($constraints as $constraint) { |
|
414 | + if (in_array($constraint->getConstraintId(), $constraintIds)) { |
|
415 | 415 | $constraintsToUse[] = $constraint; |
416 | 416 | } |
417 | 417 | } |
@@ -435,18 +435,18 @@ discard block |
||
435 | 435 | array $constraintIds = null, |
436 | 436 | callable $defaultResults = null |
437 | 437 | ) { |
438 | - $context = new MainSnakContext( $entity, $statement ); |
|
438 | + $context = new MainSnakContext($entity, $statement); |
|
439 | 439 | $constraints = $this->getConstraintsToUse( |
440 | 440 | $statement->getPropertyId(), |
441 | 441 | $constraintIds |
442 | 442 | ); |
443 | - $result = $defaultResults !== null ? $defaultResults( $context ) : []; |
|
443 | + $result = $defaultResults !== null ? $defaultResults($context) : []; |
|
444 | 444 | |
445 | - foreach ( $constraints as $constraint ) { |
|
445 | + foreach ($constraints as $constraint) { |
|
446 | 446 | $parameters = $constraint->getConstraintParameters(); |
447 | 447 | try { |
448 | - $exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters ); |
|
449 | - } catch ( ConstraintParameterException $e ) { |
|
448 | + $exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters); |
|
449 | + } catch (ConstraintParameterException $e) { |
|
450 | 450 | $result[] = new CheckResult( |
451 | 451 | $context, |
452 | 452 | $constraint, |
@@ -456,13 +456,13 @@ discard block |
||
456 | 456 | continue; |
457 | 457 | } |
458 | 458 | |
459 | - if ( in_array( $entity->getId(), $exceptions ) ) { |
|
460 | - $message = new ViolationMessage( 'wbqc-violation-message-exception' ); |
|
461 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message ); |
|
459 | + if (in_array($entity->getId(), $exceptions)) { |
|
460 | + $message = new ViolationMessage('wbqc-violation-message-exception'); |
|
461 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message); |
|
462 | 462 | continue; |
463 | 463 | } |
464 | 464 | |
465 | - $result[] = $this->getCheckResultFor( $context, $constraint ); |
|
465 | + $result[] = $this->getCheckResultFor($context, $constraint); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | return $result; |
@@ -484,24 +484,24 @@ discard block |
||
484 | 484 | ) { |
485 | 485 | $result = []; |
486 | 486 | |
487 | - if ( in_array( |
|
487 | + if (in_array( |
|
488 | 488 | $statement->getPropertyId()->getSerialization(), |
489 | 489 | $this->propertiesWithViolatingQualifiers |
490 | - ) ) { |
|
490 | + )) { |
|
491 | 491 | return $result; |
492 | 492 | } |
493 | 493 | |
494 | - foreach ( $statement->getQualifiers() as $qualifier ) { |
|
495 | - $qualifierContext = new QualifierContext( $entity, $statement, $qualifier ); |
|
496 | - if ( $defaultResultsPerContext !== null ) { |
|
497 | - $result = array_merge( $result, $defaultResultsPerContext( $qualifierContext ) ); |
|
494 | + foreach ($statement->getQualifiers() as $qualifier) { |
|
495 | + $qualifierContext = new QualifierContext($entity, $statement, $qualifier); |
|
496 | + if ($defaultResultsPerContext !== null) { |
|
497 | + $result = array_merge($result, $defaultResultsPerContext($qualifierContext)); |
|
498 | 498 | } |
499 | 499 | $qualifierConstraints = $this->getConstraintsToUse( |
500 | 500 | $qualifierContext->getSnak()->getPropertyId(), |
501 | 501 | $constraintIds |
502 | 502 | ); |
503 | - foreach ( $qualifierConstraints as $qualifierConstraint ) { |
|
504 | - $result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint ); |
|
503 | + foreach ($qualifierConstraints as $qualifierConstraint) { |
|
504 | + $result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint); |
|
505 | 505 | } |
506 | 506 | } |
507 | 507 | |
@@ -525,19 +525,19 @@ discard block |
||
525 | 525 | $result = []; |
526 | 526 | |
527 | 527 | /** @var Reference $reference */ |
528 | - foreach ( $statement->getReferences() as $reference ) { |
|
529 | - foreach ( $reference->getSnaks() as $snak ) { |
|
528 | + foreach ($statement->getReferences() as $reference) { |
|
529 | + foreach ($reference->getSnaks() as $snak) { |
|
530 | 530 | $referenceContext = new ReferenceContext( |
531 | 531 | $entity, $statement, $reference, $snak |
532 | 532 | ); |
533 | - if ( $defaultResultsPerContext !== null ) { |
|
534 | - $result = array_merge( $result, $defaultResultsPerContext( $referenceContext ) ); |
|
533 | + if ($defaultResultsPerContext !== null) { |
|
534 | + $result = array_merge($result, $defaultResultsPerContext($referenceContext)); |
|
535 | 535 | } |
536 | 536 | $referenceConstraints = $this->getConstraintsToUse( |
537 | 537 | $referenceContext->getSnak()->getPropertyId(), |
538 | 538 | $constraintIds |
539 | 539 | ); |
540 | - foreach ( $referenceConstraints as $referenceConstraint ) { |
|
540 | + foreach ($referenceConstraints as $referenceConstraint) { |
|
541 | 541 | $result[] = $this->getCheckResultFor( |
542 | 542 | $referenceContext, |
543 | 543 | $referenceConstraint |
@@ -556,20 +556,20 @@ discard block |
||
556 | 556 | * @throws InvalidArgumentException |
557 | 557 | * @return CheckResult |
558 | 558 | */ |
559 | - private function getCheckResultFor( Context $context, Constraint $constraint ) { |
|
560 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
559 | + private function getCheckResultFor(Context $context, Constraint $constraint) { |
|
560 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
561 | 561 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
562 | - $result = $this->handleScope( $checker, $context, $constraint ); |
|
562 | + $result = $this->handleScope($checker, $context, $constraint); |
|
563 | 563 | |
564 | - if ( $result !== null ) { |
|
565 | - $this->addMetadata( $context, $result ); |
|
564 | + if ($result !== null) { |
|
565 | + $this->addMetadata($context, $result); |
|
566 | 566 | return $result; |
567 | 567 | } |
568 | 568 | |
569 | - $startTime = microtime( true ); |
|
569 | + $startTime = microtime(true); |
|
570 | 570 | try { |
571 | - $result = $checker->checkConstraint( $context, $constraint ); |
|
572 | - } catch ( ConstraintParameterException $e ) { |
|
571 | + $result = $checker->checkConstraint($context, $constraint); |
|
572 | + } catch (ConstraintParameterException $e) { |
|
573 | 573 | $result = new CheckResult( |
574 | 574 | $context, |
575 | 575 | $constraint, |
@@ -577,28 +577,28 @@ discard block |
||
577 | 577 | CheckResult::STATUS_BAD_PARAMETERS, |
578 | 578 | $e->getViolationMessage() |
579 | 579 | ); |
580 | - } catch ( SparqlHelperException $e ) { |
|
581 | - $message = new ViolationMessage( 'wbqc-violation-message-sparql-error' ); |
|
582 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, $message ); |
|
580 | + } catch (SparqlHelperException $e) { |
|
581 | + $message = new ViolationMessage('wbqc-violation-message-sparql-error'); |
|
582 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, $message); |
|
583 | 583 | } |
584 | - $endTime = microtime( true ); |
|
584 | + $endTime = microtime(true); |
|
585 | 585 | |
586 | - $this->addMetadata( $context, $result ); |
|
586 | + $this->addMetadata($context, $result); |
|
587 | 587 | |
588 | - $this->downgradeResultStatus( $context, $result ); |
|
588 | + $this->downgradeResultStatus($context, $result); |
|
589 | 589 | |
590 | 590 | $this->loggingHelper->logConstraintCheck( |
591 | 591 | $context, |
592 | 592 | $constraint, |
593 | 593 | $result, |
594 | - get_class( $checker ), |
|
594 | + get_class($checker), |
|
595 | 595 | $endTime - $startTime, |
596 | 596 | __METHOD__ |
597 | 597 | ); |
598 | 598 | |
599 | 599 | return $result; |
600 | 600 | } else { |
601 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
601 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
602 | 602 | } |
603 | 603 | } |
604 | 604 | |
@@ -611,63 +611,63 @@ discard block |
||
611 | 611 | $checkedContextTypes = $this->constraintParameterParser->parseConstraintScopeParameter( |
612 | 612 | $constraint->getConstraintParameters(), |
613 | 613 | $constraint->getConstraintTypeItemId(), |
614 | - $this->getAllowedContextTypes( $constraint ) |
|
614 | + $this->getAllowedContextTypes($constraint) |
|
615 | 615 | ); |
616 | - } catch ( ConstraintParameterException $e ) { |
|
617 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
616 | + } catch (ConstraintParameterException $e) { |
|
617 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
618 | 618 | } |
619 | - if ( $checkedContextTypes === null ) { |
|
619 | + if ($checkedContextTypes === null) { |
|
620 | 620 | $checkedContextTypes = $checker->getDefaultContextTypes(); |
621 | 621 | } |
622 | - if ( !in_array( $context->getType(), $checkedContextTypes ) ) { |
|
623 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null ); |
|
622 | + if (!in_array($context->getType(), $checkedContextTypes)) { |
|
623 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null); |
|
624 | 624 | } |
625 | - if ( $checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO ) { |
|
626 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
625 | + if ($checker->getSupportedContextTypes()[$context->getType()] === CheckResult::STATUS_TODO) { |
|
626 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
627 | 627 | } |
628 | 628 | return null; |
629 | 629 | } |
630 | 630 | |
631 | - private function addMetadata( Context $context, CheckResult $result ) { |
|
632 | - $result->withMetadata( Metadata::merge( [ |
|
631 | + private function addMetadata(Context $context, CheckResult $result) { |
|
632 | + $result->withMetadata(Metadata::merge([ |
|
633 | 633 | $result->getMetadata(), |
634 | - Metadata::ofDependencyMetadata( DependencyMetadata::merge( [ |
|
635 | - DependencyMetadata::ofEntityId( $context->getEntity()->getId() ), |
|
636 | - DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ), |
|
637 | - ] ) ), |
|
638 | - ] ) ); |
|
634 | + Metadata::ofDependencyMetadata(DependencyMetadata::merge([ |
|
635 | + DependencyMetadata::ofEntityId($context->getEntity()->getId()), |
|
636 | + DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()), |
|
637 | + ])), |
|
638 | + ])); |
|
639 | 639 | } |
640 | 640 | |
641 | - private function downgradeResultStatus( Context $context, CheckResult &$result ) { |
|
641 | + private function downgradeResultStatus(Context $context, CheckResult &$result) { |
|
642 | 642 | $constraint = $result->getConstraint(); |
643 | 643 | try { |
644 | 644 | $constraintStatus = $this->constraintParameterParser |
645 | - ->parseConstraintStatusParameter( $constraint->getConstraintParameters() ); |
|
646 | - } catch ( ConstraintParameterException $e ) { |
|
647 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
645 | + ->parseConstraintStatusParameter($constraint->getConstraintParameters()); |
|
646 | + } catch (ConstraintParameterException $e) { |
|
647 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
648 | 648 | $constraintStatus = null; |
649 | 649 | } |
650 | - if ( $constraintStatus === null ) { |
|
650 | + if ($constraintStatus === null) { |
|
651 | 651 | // downgrade violation to warning |
652 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
653 | - $result->setStatus( CheckResult::STATUS_WARNING ); |
|
652 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
653 | + $result->setStatus(CheckResult::STATUS_WARNING); |
|
654 | 654 | } |
655 | - } elseif ( $constraintStatus === 'suggestion' ) { |
|
655 | + } elseif ($constraintStatus === 'suggestion') { |
|
656 | 656 | // downgrade violation to suggestion |
657 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
658 | - $result->setStatus( CheckResult::STATUS_SUGGESTION ); |
|
657 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
658 | + $result->setStatus(CheckResult::STATUS_SUGGESTION); |
|
659 | 659 | } |
660 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
660 | + $result->addParameter('constraint_status', $constraintStatus); |
|
661 | 661 | } else { |
662 | - if ( $constraintStatus !== 'mandatory' ) { |
|
662 | + if ($constraintStatus !== 'mandatory') { |
|
663 | 663 | // @codeCoverageIgnoreStart |
664 | 664 | throw new LogicException( |
665 | - "Unknown constraint status '$constraintStatus', " . |
|
665 | + "Unknown constraint status '$constraintStatus', ". |
|
666 | 666 | "only known statuses are 'mandatory' and 'suggestion'" |
667 | 667 | ); |
668 | 668 | // @codeCoverageIgnoreEnd |
669 | 669 | } |
670 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
670 | + $result->addParameter('constraint_status', $constraintStatus); |
|
671 | 671 | } |
672 | 672 | } |
673 | 673 | |
@@ -676,12 +676,12 @@ discard block |
||
676 | 676 | * |
677 | 677 | * @return CheckResult[] |
678 | 678 | */ |
679 | - private function sortResult( array $result ) { |
|
680 | - if ( count( $result ) < 2 ) { |
|
679 | + private function sortResult(array $result) { |
|
680 | + if (count($result) < 2) { |
|
681 | 681 | return $result; |
682 | 682 | } |
683 | 683 | |
684 | - $sortFunction = static function ( CheckResult $a, CheckResult $b ) { |
|
684 | + $sortFunction = static function(CheckResult $a, CheckResult $b) { |
|
685 | 685 | $orderNum = 0; |
686 | 686 | $order = [ |
687 | 687 | CheckResult::STATUS_BAD_PARAMETERS => $orderNum++, |
@@ -698,55 +698,55 @@ discard block |
||
698 | 698 | $statusA = $a->getStatus(); |
699 | 699 | $statusB = $b->getStatus(); |
700 | 700 | |
701 | - $orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ]; |
|
702 | - $orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ]; |
|
701 | + $orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other']; |
|
702 | + $orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other']; |
|
703 | 703 | |
704 | - if ( $orderA === $orderB ) { |
|
704 | + if ($orderA === $orderB) { |
|
705 | 705 | $cursorA = $a->getContextCursor(); |
706 | 706 | $cursorB = $b->getContextCursor(); |
707 | 707 | |
708 | - if ( $cursorA instanceof EntityContextCursor ) { |
|
708 | + if ($cursorA instanceof EntityContextCursor) { |
|
709 | 709 | return $cursorB instanceof EntityContextCursor ? 0 : -1; |
710 | 710 | } |
711 | - if ( $cursorB instanceof EntityContextCursor ) { |
|
711 | + if ($cursorB instanceof EntityContextCursor) { |
|
712 | 712 | return $cursorA instanceof EntityContextCursor ? 0 : 1; |
713 | 713 | } |
714 | 714 | |
715 | 715 | $pidA = $cursorA->getSnakPropertyId(); |
716 | 716 | $pidB = $cursorB->getSnakPropertyId(); |
717 | 717 | |
718 | - if ( $pidA === $pidB ) { |
|
718 | + if ($pidA === $pidB) { |
|
719 | 719 | $hashA = $cursorA->getSnakHash(); |
720 | 720 | $hashB = $cursorB->getSnakHash(); |
721 | 721 | |
722 | - if ( $hashA === $hashB ) { |
|
723 | - if ( $a instanceof NullResult ) { |
|
722 | + if ($hashA === $hashB) { |
|
723 | + if ($a instanceof NullResult) { |
|
724 | 724 | return $b instanceof NullResult ? 0 : -1; |
725 | 725 | } |
726 | - if ( $b instanceof NullResult ) { |
|
726 | + if ($b instanceof NullResult) { |
|
727 | 727 | return $a instanceof NullResult ? 0 : 1; |
728 | 728 | } |
729 | 729 | |
730 | 730 | $typeA = $a->getConstraint()->getConstraintTypeItemId(); |
731 | 731 | $typeB = $b->getConstraint()->getConstraintTypeItemId(); |
732 | 732 | |
733 | - if ( $typeA == $typeB ) { |
|
733 | + if ($typeA == $typeB) { |
|
734 | 734 | return 0; |
735 | 735 | } else { |
736 | - return ( $typeA > $typeB ) ? 1 : -1; |
|
736 | + return ($typeA > $typeB) ? 1 : -1; |
|
737 | 737 | } |
738 | 738 | } else { |
739 | - return ( $hashA > $hashB ) ? 1 : -1; |
|
739 | + return ($hashA > $hashB) ? 1 : -1; |
|
740 | 740 | } |
741 | 741 | } else { |
742 | - return ( $pidA > $pidB ) ? 1 : -1; |
|
742 | + return ($pidA > $pidB) ? 1 : -1; |
|
743 | 743 | } |
744 | 744 | } else { |
745 | - return ( $orderA > $orderB ) ? 1 : -1; |
|
745 | + return ($orderA > $orderB) ? 1 : -1; |
|
746 | 746 | } |
747 | 747 | }; |
748 | 748 | |
749 | - uasort( $result, $sortFunction ); |
|
749 | + uasort($result, $sortFunction); |
|
750 | 750 | |
751 | 751 | return $result; |
752 | 752 | } |
@@ -77,15 +77,15 @@ discard block |
||
77 | 77 | * @param array $parameters |
78 | 78 | * @throws ConstraintParameterException |
79 | 79 | */ |
80 | - public function checkError( array $parameters ) { |
|
81 | - if ( array_key_exists( '@error', $parameters ) ) { |
|
80 | + public function checkError(array $parameters) { |
|
81 | + if (array_key_exists('@error', $parameters)) { |
|
82 | 82 | $error = $parameters['@error']; |
83 | - if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) { |
|
83 | + if (array_key_exists('toolong', $error) && $error['toolong']) { |
|
84 | 84 | $msg = 'wbqc-violation-message-parameters-error-toolong'; |
85 | 85 | } else { |
86 | 86 | $msg = 'wbqc-violation-message-parameters-error-unknown'; |
87 | 87 | } |
88 | - throw new ConstraintParameterException( new ViolationMessage( $msg ) ); |
|
88 | + throw new ConstraintParameterException(new ViolationMessage($msg)); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
@@ -95,11 +95,11 @@ discard block |
||
95 | 95 | * @param string $parameterId |
96 | 96 | * @throws ConstraintParameterException |
97 | 97 | */ |
98 | - private function requireSingleParameter( array $parameters, $parameterId ) { |
|
99 | - if ( count( $parameters[$parameterId] ) !== 1 ) { |
|
98 | + private function requireSingleParameter(array $parameters, $parameterId) { |
|
99 | + if (count($parameters[$parameterId]) !== 1) { |
|
100 | 100 | throw new ConstraintParameterException( |
101 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single' ) ) |
|
102 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
101 | + (new ViolationMessage('wbqc-violation-message-parameter-single')) |
|
102 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
103 | 103 | ); |
104 | 104 | } |
105 | 105 | } |
@@ -111,11 +111,11 @@ discard block |
||
111 | 111 | * @return void |
112 | 112 | * @throws ConstraintParameterException |
113 | 113 | */ |
114 | - private function requireValueParameter( Snak $snak, $parameterId ) { |
|
115 | - if ( !( $snak instanceof PropertyValueSnak ) ) { |
|
114 | + private function requireValueParameter(Snak $snak, $parameterId) { |
|
115 | + if (!($snak instanceof PropertyValueSnak)) { |
|
116 | 116 | throw new ConstraintParameterException( |
117 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
118 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
117 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
118 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
119 | 119 | ); |
120 | 120 | } |
121 | 121 | } |
@@ -127,17 +127,17 @@ 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 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-entity' ) ) |
|
139 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
140 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
138 | + (new ViolationMessage('wbqc-violation-message-parameter-entity')) |
|
139 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
140 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
141 | 141 | ); |
142 | 142 | } |
143 | 143 | } |
@@ -148,20 +148,20 @@ discard block |
||
148 | 148 | * @throws ConstraintParameterException if the parameter is invalid or missing |
149 | 149 | * @return string[] class entity ID serializations |
150 | 150 | */ |
151 | - public function parseClassParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
152 | - $this->checkError( $constraintParameters ); |
|
153 | - $classId = $this->config->get( 'WBQualityConstraintsClassId' ); |
|
154 | - if ( !array_key_exists( $classId, $constraintParameters ) ) { |
|
151 | + public function parseClassParameter(array $constraintParameters, $constraintTypeItemId) { |
|
152 | + $this->checkError($constraintParameters); |
|
153 | + $classId = $this->config->get('WBQualityConstraintsClassId'); |
|
154 | + if (!array_key_exists($classId, $constraintParameters)) { |
|
155 | 155 | throw new ConstraintParameterException( |
156 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
157 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
158 | - ->withEntityId( new PropertyId( $classId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
156 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
157 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
158 | + ->withEntityId(new PropertyId($classId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
159 | 159 | ); |
160 | 160 | } |
161 | 161 | |
162 | 162 | $classes = []; |
163 | - foreach ( $constraintParameters[$classId] as $class ) { |
|
164 | - $classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization(); |
|
163 | + foreach ($constraintParameters[$classId] as $class) { |
|
164 | + $classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization(); |
|
165 | 165 | } |
166 | 166 | return $classes; |
167 | 167 | } |
@@ -172,23 +172,23 @@ discard block |
||
172 | 172 | * @throws ConstraintParameterException if the parameter is invalid or missing |
173 | 173 | * @return string 'instance', 'subclass', or 'instanceOrSubclass' |
174 | 174 | */ |
175 | - public function parseRelationParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
176 | - $this->checkError( $constraintParameters ); |
|
177 | - $relationId = $this->config->get( 'WBQualityConstraintsRelationId' ); |
|
178 | - if ( !array_key_exists( $relationId, $constraintParameters ) ) { |
|
175 | + public function parseRelationParameter(array $constraintParameters, $constraintTypeItemId) { |
|
176 | + $this->checkError($constraintParameters); |
|
177 | + $relationId = $this->config->get('WBQualityConstraintsRelationId'); |
|
178 | + if (!array_key_exists($relationId, $constraintParameters)) { |
|
179 | 179 | throw new ConstraintParameterException( |
180 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
181 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
182 | - ->withEntityId( new PropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
180 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
181 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
182 | + ->withEntityId(new PropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
183 | 183 | ); |
184 | 184 | } |
185 | 185 | |
186 | - $this->requireSingleParameter( $constraintParameters, $relationId ); |
|
187 | - $relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId ); |
|
188 | - $instanceId = $this->config->get( 'WBQualityConstraintsInstanceOfRelationId' ); |
|
189 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfRelationId' ); |
|
190 | - $instanceOrSubclassId = $this->config->get( 'WBQualityConstraintsInstanceOrSubclassOfRelationId' ); |
|
191 | - switch ( $relationEntityId->getSerialization() ) { |
|
186 | + $this->requireSingleParameter($constraintParameters, $relationId); |
|
187 | + $relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId); |
|
188 | + $instanceId = $this->config->get('WBQualityConstraintsInstanceOfRelationId'); |
|
189 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfRelationId'); |
|
190 | + $instanceOrSubclassId = $this->config->get('WBQualityConstraintsInstanceOrSubclassOfRelationId'); |
|
191 | + switch ($relationEntityId->getSerialization()) { |
|
192 | 192 | case $instanceId: |
193 | 193 | return 'instance'; |
194 | 194 | case $subclassId: |
@@ -197,13 +197,13 @@ discard block |
||
197 | 197 | return 'instanceOrSubclass'; |
198 | 198 | default: |
199 | 199 | throw new ConstraintParameterException( |
200 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
201 | - ->withEntityId( new PropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
200 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
201 | + ->withEntityId(new PropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
202 | 202 | ->withEntityIdList( |
203 | 203 | [ |
204 | - new ItemId( $instanceId ), |
|
205 | - new ItemId( $subclassId ), |
|
206 | - new ItemId( $instanceOrSubclassId ), |
|
204 | + new ItemId($instanceId), |
|
205 | + new ItemId($subclassId), |
|
206 | + new ItemId($instanceOrSubclassId), |
|
207 | 207 | ], |
208 | 208 | Role::CONSTRAINT_PARAMETER_VALUE |
209 | 209 | ) |
@@ -218,20 +218,20 @@ discard block |
||
218 | 218 | * @throws ConstraintParameterException |
219 | 219 | * @return PropertyId |
220 | 220 | */ |
221 | - private function parsePropertyIdParameter( array $snakSerialization, $parameterId ) { |
|
222 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
223 | - $this->requireValueParameter( $snak, $parameterId ); |
|
221 | + private function parsePropertyIdParameter(array $snakSerialization, $parameterId) { |
|
222 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
223 | + $this->requireValueParameter($snak, $parameterId); |
|
224 | 224 | $value = $snak->getDataValue(); |
225 | - if ( $value instanceof EntityIdValue ) { |
|
225 | + if ($value instanceof EntityIdValue) { |
|
226 | 226 | $id = $value->getEntityId(); |
227 | - if ( $id instanceof PropertyId ) { |
|
227 | + if ($id instanceof PropertyId) { |
|
228 | 228 | return $id; |
229 | 229 | } |
230 | 230 | } |
231 | 231 | throw new ConstraintParameterException( |
232 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-property' ) ) |
|
233 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
234 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
232 | + (new ViolationMessage('wbqc-violation-message-parameter-property')) |
|
233 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
234 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
235 | 235 | ); |
236 | 236 | } |
237 | 237 | |
@@ -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 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
251 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
252 | - ->withEntityId( new PropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
250 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
251 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
252 | + ->withEntityId(new PropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
253 | 253 | ); |
254 | 254 | } |
255 | 255 | |
256 | - $this->requireSingleParameter( $constraintParameters, $propertyId ); |
|
257 | - return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId ); |
|
256 | + $this->requireSingleParameter($constraintParameters, $propertyId); |
|
257 | + return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId); |
|
258 | 258 | } |
259 | 259 | |
260 | - private function parseItemIdParameter( PropertyValueSnak $snak, $parameterId ) { |
|
260 | + private function parseItemIdParameter(PropertyValueSnak $snak, $parameterId) { |
|
261 | 261 | $dataValue = $snak->getDataValue(); |
262 | - if ( $dataValue instanceof EntityIdValue ) { |
|
262 | + if ($dataValue instanceof EntityIdValue) { |
|
263 | 263 | $entityId = $dataValue->getEntityId(); |
264 | - if ( $entityId instanceof ItemId ) { |
|
265 | - return ItemIdSnakValue::fromItemId( $entityId ); |
|
264 | + if ($entityId instanceof ItemId) { |
|
265 | + return ItemIdSnakValue::fromItemId($entityId); |
|
266 | 266 | } |
267 | 267 | } |
268 | 268 | throw new ConstraintParameterException( |
269 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) ) |
|
270 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
271 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
269 | + (new ViolationMessage('wbqc-violation-message-parameter-item')) |
|
270 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
271 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
272 | 272 | ); |
273 | 273 | } |
274 | 274 | |
@@ -286,16 +286,16 @@ discard block |
||
286 | 286 | $required, |
287 | 287 | $parameterId = null |
288 | 288 | ) { |
289 | - $this->checkError( $constraintParameters ); |
|
290 | - if ( $parameterId === null ) { |
|
291 | - $parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
289 | + $this->checkError($constraintParameters); |
|
290 | + if ($parameterId === null) { |
|
291 | + $parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
292 | 292 | } |
293 | - if ( !array_key_exists( $parameterId, $constraintParameters ) ) { |
|
294 | - if ( $required ) { |
|
293 | + if (!array_key_exists($parameterId, $constraintParameters)) { |
|
294 | + if ($required) { |
|
295 | 295 | throw new ConstraintParameterException( |
296 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
297 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
298 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
296 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
297 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
298 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
299 | 299 | ); |
300 | 300 | } else { |
301 | 301 | return []; |
@@ -303,11 +303,11 @@ discard block |
||
303 | 303 | } |
304 | 304 | |
305 | 305 | $values = []; |
306 | - foreach ( $constraintParameters[$parameterId] as $parameter ) { |
|
307 | - $snak = $this->snakDeserializer->deserialize( $parameter ); |
|
308 | - switch ( true ) { |
|
306 | + foreach ($constraintParameters[$parameterId] as $parameter) { |
|
307 | + $snak = $this->snakDeserializer->deserialize($parameter); |
|
308 | + switch (true) { |
|
309 | 309 | case $snak instanceof PropertyValueSnak: |
310 | - $values[] = $this->parseItemIdParameter( $snak, $parameterId ); |
|
310 | + $values[] = $this->parseItemIdParameter($snak, $parameterId); |
|
311 | 311 | break; |
312 | 312 | case $snak instanceof PropertySomeValueSnak: |
313 | 313 | $values[] = ItemIdSnakValue::someValue(); |
@@ -326,27 +326,27 @@ discard block |
||
326 | 326 | * @throws ConstraintParameterException if the parameter is invalid or missing |
327 | 327 | * @return PropertyId[] |
328 | 328 | */ |
329 | - public function parsePropertiesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
330 | - $this->checkError( $constraintParameters ); |
|
331 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
332 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
329 | + public function parsePropertiesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
330 | + $this->checkError($constraintParameters); |
|
331 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
332 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
333 | 333 | throw new ConstraintParameterException( |
334 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
335 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
336 | - ->withEntityId( new PropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
334 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
335 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
336 | + ->withEntityId(new PropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
337 | 337 | ); |
338 | 338 | } |
339 | 339 | |
340 | 340 | $parameters = $constraintParameters[$propertyId]; |
341 | - if ( count( $parameters ) === 1 && |
|
342 | - $this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak |
|
341 | + if (count($parameters) === 1 && |
|
342 | + $this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak |
|
343 | 343 | ) { |
344 | 344 | return []; |
345 | 345 | } |
346 | 346 | |
347 | 347 | $properties = []; |
348 | - foreach ( $parameters as $parameter ) { |
|
349 | - $properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId ); |
|
348 | + foreach ($parameters as $parameter) { |
|
349 | + $properties[] = $this->parsePropertyIdParameter($parameter, $propertyId); |
|
350 | 350 | } |
351 | 351 | return $properties; |
352 | 352 | } |
@@ -357,16 +357,16 @@ discard block |
||
357 | 357 | * @throws ConstraintParameterException |
358 | 358 | * @return DataValue|null |
359 | 359 | */ |
360 | - private function parseValueOrNoValueParameter( array $snakSerialization, $parameterId ) { |
|
361 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
362 | - if ( $snak instanceof PropertyValueSnak ) { |
|
360 | + private function parseValueOrNoValueParameter(array $snakSerialization, $parameterId) { |
|
361 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
362 | + if ($snak instanceof PropertyValueSnak) { |
|
363 | 363 | return $snak->getDataValue(); |
364 | - } elseif ( $snak instanceof PropertyNoValueSnak ) { |
|
364 | + } elseif ($snak instanceof PropertyNoValueSnak) { |
|
365 | 365 | return null; |
366 | 366 | } else { |
367 | 367 | throw new ConstraintParameterException( |
368 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
369 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
368 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
369 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
370 | 370 | ); |
371 | 371 | } |
372 | 372 | } |
@@ -376,10 +376,10 @@ discard block |
||
376 | 376 | * @param string $parameterId |
377 | 377 | * @return DataValue|null |
378 | 378 | */ |
379 | - private function parseValueOrNoValueOrNowParameter( array $snakSerialization, $parameterId ) { |
|
379 | + private function parseValueOrNoValueOrNowParameter(array $snakSerialization, $parameterId) { |
|
380 | 380 | try { |
381 | - return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId ); |
|
382 | - } catch ( ConstraintParameterException $e ) { |
|
381 | + return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId); |
|
382 | + } catch (ConstraintParameterException $e) { |
|
383 | 383 | // unknown value means “now” |
384 | 384 | return new NowValue(); |
385 | 385 | } |
@@ -392,14 +392,14 @@ discard block |
||
392 | 392 | * @param string $unit |
393 | 393 | * @return bool |
394 | 394 | */ |
395 | - private function exactlyOneQuantityWithUnit( ?DataValue $min, ?DataValue $max, $unit ) { |
|
396 | - if ( !( $min instanceof UnboundedQuantityValue ) || |
|
397 | - !( $max instanceof UnboundedQuantityValue ) |
|
395 | + private function exactlyOneQuantityWithUnit(?DataValue $min, ?DataValue $max, $unit) { |
|
396 | + if (!($min instanceof UnboundedQuantityValue) || |
|
397 | + !($max instanceof UnboundedQuantityValue) |
|
398 | 398 | ) { |
399 | 399 | return false; |
400 | 400 | } |
401 | 401 | |
402 | - return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit ); |
|
402 | + return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
@@ -412,42 +412,42 @@ discard block |
||
412 | 412 | * @throws ConstraintParameterException if the parameter is invalid or missing |
413 | 413 | * @return DataValue[] if the parameter is invalid or missing |
414 | 414 | */ |
415 | - private function parseRangeParameter( array $constraintParameters, $minimumId, $maximumId, $constraintTypeItemId, $type ) { |
|
416 | - $this->checkError( $constraintParameters ); |
|
417 | - if ( !array_key_exists( $minimumId, $constraintParameters ) || |
|
418 | - !array_key_exists( $maximumId, $constraintParameters ) |
|
415 | + private function parseRangeParameter(array $constraintParameters, $minimumId, $maximumId, $constraintTypeItemId, $type) { |
|
416 | + $this->checkError($constraintParameters); |
|
417 | + if (!array_key_exists($minimumId, $constraintParameters) || |
|
418 | + !array_key_exists($maximumId, $constraintParameters) |
|
419 | 419 | ) { |
420 | 420 | throw new ConstraintParameterException( |
421 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-needed' ) ) |
|
422 | - ->withDataValueType( $type ) |
|
423 | - ->withEntityId( new PropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
424 | - ->withEntityId( new PropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
425 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
421 | + (new ViolationMessage('wbqc-violation-message-range-parameters-needed')) |
|
422 | + ->withDataValueType($type) |
|
423 | + ->withEntityId(new PropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
424 | + ->withEntityId(new PropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
425 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
426 | 426 | ); |
427 | 427 | } |
428 | 428 | |
429 | - $this->requireSingleParameter( $constraintParameters, $minimumId ); |
|
430 | - $this->requireSingleParameter( $constraintParameters, $maximumId ); |
|
429 | + $this->requireSingleParameter($constraintParameters, $minimumId); |
|
430 | + $this->requireSingleParameter($constraintParameters, $maximumId); |
|
431 | 431 | $parseFunction = $type === 'time' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter'; |
432 | - $min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId ); |
|
433 | - $max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId ); |
|
432 | + $min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId); |
|
433 | + $max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId); |
|
434 | 434 | |
435 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
436 | - if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) { |
|
435 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
436 | + if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) { |
|
437 | 437 | throw new ConstraintParameterException( |
438 | - new ViolationMessage( 'wbqc-violation-message-range-parameters-one-year' ) |
|
438 | + new ViolationMessage('wbqc-violation-message-range-parameters-one-year') |
|
439 | 439 | ); |
440 | 440 | } |
441 | - if ( $min === null && $max === null || |
|
442 | - $min !== null && $max !== null && $min->equals( $max ) ) { |
|
441 | + if ($min === null && $max === null || |
|
442 | + $min !== null && $max !== null && $min->equals($max)) { |
|
443 | 443 | throw new ConstraintParameterException( |
444 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-same' ) ) |
|
445 | - ->withEntityId( new PropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
446 | - ->withEntityId( new PropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
444 | + (new ViolationMessage('wbqc-violation-message-range-parameters-same')) |
|
445 | + ->withEntityId(new PropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
446 | + ->withEntityId(new PropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
447 | 447 | ); |
448 | 448 | } |
449 | 449 | |
450 | - return [ $min, $max ]; |
|
450 | + return [$min, $max]; |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | /** |
@@ -457,11 +457,11 @@ discard block |
||
457 | 457 | * @throws ConstraintParameterException if the parameter is invalid or missing |
458 | 458 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
459 | 459 | */ |
460 | - public function parseQuantityRangeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
460 | + public function parseQuantityRangeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
461 | 461 | return $this->parseRangeParameter( |
462 | 462 | $constraintParameters, |
463 | - $this->config->get( 'WBQualityConstraintsMinimumQuantityId' ), |
|
464 | - $this->config->get( 'WBQualityConstraintsMaximumQuantityId' ), |
|
463 | + $this->config->get('WBQualityConstraintsMinimumQuantityId'), |
|
464 | + $this->config->get('WBQualityConstraintsMaximumQuantityId'), |
|
465 | 465 | $constraintTypeItemId, |
466 | 466 | 'quantity' |
467 | 467 | ); |
@@ -474,11 +474,11 @@ discard block |
||
474 | 474 | * @throws ConstraintParameterException if the parameter is invalid or missing |
475 | 475 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
476 | 476 | */ |
477 | - public function parseTimeRangeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
477 | + public function parseTimeRangeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
478 | 478 | return $this->parseRangeParameter( |
479 | 479 | $constraintParameters, |
480 | - $this->config->get( 'WBQualityConstraintsMinimumDateId' ), |
|
481 | - $this->config->get( 'WBQualityConstraintsMaximumDateId' ), |
|
480 | + $this->config->get('WBQualityConstraintsMinimumDateId'), |
|
481 | + $this->config->get('WBQualityConstraintsMaximumDateId'), |
|
482 | 482 | $constraintTypeItemId, |
483 | 483 | 'time' |
484 | 484 | ); |
@@ -491,17 +491,17 @@ discard block |
||
491 | 491 | * @throws ConstraintParameterException |
492 | 492 | * @return string |
493 | 493 | */ |
494 | - private function parseStringParameter( array $snakSerialization, $parameterId ) { |
|
495 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
496 | - $this->requireValueParameter( $snak, $parameterId ); |
|
494 | + private function parseStringParameter(array $snakSerialization, $parameterId) { |
|
495 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
496 | + $this->requireValueParameter($snak, $parameterId); |
|
497 | 497 | $value = $snak->getDataValue(); |
498 | - if ( $value instanceof StringValue ) { |
|
498 | + if ($value instanceof StringValue) { |
|
499 | 499 | return $value->getValue(); |
500 | 500 | } else { |
501 | 501 | throw new ConstraintParameterException( |
502 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-string' ) ) |
|
503 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
504 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
502 | + (new ViolationMessage('wbqc-violation-message-parameter-string')) |
|
503 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
504 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
505 | 505 | ); |
506 | 506 | } |
507 | 507 | } |
@@ -512,15 +512,15 @@ discard block |
||
512 | 512 | * @throws ConstraintParameterException if the parameter is invalid or missing |
513 | 513 | * @return string |
514 | 514 | */ |
515 | - public function parseNamespaceParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
516 | - $this->checkError( $constraintParameters ); |
|
517 | - $namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' ); |
|
518 | - if ( !array_key_exists( $namespaceId, $constraintParameters ) ) { |
|
515 | + public function parseNamespaceParameter(array $constraintParameters, $constraintTypeItemId) { |
|
516 | + $this->checkError($constraintParameters); |
|
517 | + $namespaceId = $this->config->get('WBQualityConstraintsNamespaceId'); |
|
518 | + if (!array_key_exists($namespaceId, $constraintParameters)) { |
|
519 | 519 | return ''; |
520 | 520 | } |
521 | 521 | |
522 | - $this->requireSingleParameter( $constraintParameters, $namespaceId ); |
|
523 | - return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId ); |
|
522 | + $this->requireSingleParameter($constraintParameters, $namespaceId); |
|
523 | + return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId); |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | /** |
@@ -529,19 +529,19 @@ discard block |
||
529 | 529 | * @throws ConstraintParameterException if the parameter is invalid or missing |
530 | 530 | * @return string |
531 | 531 | */ |
532 | - public function parseFormatParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
533 | - $this->checkError( $constraintParameters ); |
|
534 | - $formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' ); |
|
535 | - if ( !array_key_exists( $formatId, $constraintParameters ) ) { |
|
532 | + public function parseFormatParameter(array $constraintParameters, $constraintTypeItemId) { |
|
533 | + $this->checkError($constraintParameters); |
|
534 | + $formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId'); |
|
535 | + if (!array_key_exists($formatId, $constraintParameters)) { |
|
536 | 536 | throw new ConstraintParameterException( |
537 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
538 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
539 | - ->withEntityId( new PropertyId( $formatId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
537 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
538 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
539 | + ->withEntityId(new PropertyId($formatId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
540 | 540 | ); |
541 | 541 | } |
542 | 542 | |
543 | - $this->requireSingleParameter( $constraintParameters, $formatId ); |
|
544 | - return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId ); |
|
543 | + $this->requireSingleParameter($constraintParameters, $formatId); |
|
544 | + return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
@@ -549,16 +549,16 @@ discard block |
||
549 | 549 | * @throws ConstraintParameterException if the parameter is invalid |
550 | 550 | * @return EntityId[] |
551 | 551 | */ |
552 | - public function parseExceptionParameter( array $constraintParameters ) { |
|
553 | - $this->checkError( $constraintParameters ); |
|
554 | - $exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' ); |
|
555 | - if ( !array_key_exists( $exceptionId, $constraintParameters ) ) { |
|
552 | + public function parseExceptionParameter(array $constraintParameters) { |
|
553 | + $this->checkError($constraintParameters); |
|
554 | + $exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId'); |
|
555 | + if (!array_key_exists($exceptionId, $constraintParameters)) { |
|
556 | 556 | return []; |
557 | 557 | } |
558 | 558 | |
559 | 559 | return array_map( |
560 | - function ( $snakSerialization ) use ( $exceptionId ) { |
|
561 | - return $this->parseEntityIdParameter( $snakSerialization, $exceptionId ); |
|
560 | + function($snakSerialization) use ($exceptionId) { |
|
561 | + return $this->parseEntityIdParameter($snakSerialization, $exceptionId); |
|
562 | 562 | }, |
563 | 563 | $constraintParameters[$exceptionId] |
564 | 564 | ); |
@@ -569,39 +569,39 @@ discard block |
||
569 | 569 | * @throws ConstraintParameterException if the parameter is invalid |
570 | 570 | * @return string|null 'mandatory', 'suggestion' or null |
571 | 571 | */ |
572 | - public function parseConstraintStatusParameter( array $constraintParameters ) { |
|
573 | - $this->checkError( $constraintParameters ); |
|
574 | - $constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' ); |
|
575 | - if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) { |
|
572 | + public function parseConstraintStatusParameter(array $constraintParameters) { |
|
573 | + $this->checkError($constraintParameters); |
|
574 | + $constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId'); |
|
575 | + if (!array_key_exists($constraintStatusId, $constraintParameters)) { |
|
576 | 576 | return null; |
577 | 577 | } |
578 | 578 | |
579 | - $mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' ); |
|
580 | - $supportedStatuses = [ new ItemId( $mandatoryId ) ]; |
|
581 | - if ( $this->config->get( 'WBQualityConstraintsEnableSuggestionConstraintStatus' ) ) { |
|
582 | - $suggestionId = $this->config->get( 'WBQualityConstraintsSuggestionConstraintId' ); |
|
583 | - $supportedStatuses[] = new ItemId( $suggestionId ); |
|
579 | + $mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId'); |
|
580 | + $supportedStatuses = [new ItemId($mandatoryId)]; |
|
581 | + if ($this->config->get('WBQualityConstraintsEnableSuggestionConstraintStatus')) { |
|
582 | + $suggestionId = $this->config->get('WBQualityConstraintsSuggestionConstraintId'); |
|
583 | + $supportedStatuses[] = new ItemId($suggestionId); |
|
584 | 584 | } else { |
585 | 585 | $suggestionId = null; |
586 | 586 | } |
587 | 587 | |
588 | - $this->requireSingleParameter( $constraintParameters, $constraintStatusId ); |
|
589 | - $snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] ); |
|
590 | - $this->requireValueParameter( $snak, $constraintStatusId ); |
|
588 | + $this->requireSingleParameter($constraintParameters, $constraintStatusId); |
|
589 | + $snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]); |
|
590 | + $this->requireValueParameter($snak, $constraintStatusId); |
|
591 | 591 | '@phan-var \Wikibase\DataModel\Snak\PropertyValueSnak $snak'; |
592 | 592 | $dataValue = $snak->getDataValue(); |
593 | 593 | '@phan-var EntityIdValue $dataValue'; |
594 | 594 | $entityId = $dataValue->getEntityId(); |
595 | 595 | $statusId = $entityId->getSerialization(); |
596 | 596 | |
597 | - if ( $statusId === $mandatoryId ) { |
|
597 | + if ($statusId === $mandatoryId) { |
|
598 | 598 | return 'mandatory'; |
599 | - } elseif ( $statusId === $suggestionId ) { |
|
599 | + } elseif ($statusId === $suggestionId) { |
|
600 | 600 | return 'suggestion'; |
601 | 601 | } else { |
602 | 602 | throw new ConstraintParameterException( |
603 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
604 | - ->withEntityId( new PropertyId( $constraintStatusId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
603 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
604 | + ->withEntityId(new PropertyId($constraintStatusId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
605 | 605 | ->withEntityIdList( |
606 | 606 | $supportedStatuses, |
607 | 607 | Role::CONSTRAINT_PARAMETER_VALUE |
@@ -617,12 +617,12 @@ discard block |
||
617 | 617 | * @return void |
618 | 618 | * @throws ConstraintParameterException |
619 | 619 | */ |
620 | - private function requireMonolingualTextParameter( DataValue $dataValue, $parameterId ) { |
|
621 | - if ( !( $dataValue instanceof MonolingualTextValue ) ) { |
|
620 | + private function requireMonolingualTextParameter(DataValue $dataValue, $parameterId) { |
|
621 | + if (!($dataValue instanceof MonolingualTextValue)) { |
|
622 | 622 | throw new ConstraintParameterException( |
623 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-monolingualtext' ) ) |
|
624 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
625 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
623 | + (new ViolationMessage('wbqc-violation-message-parameter-monolingualtext')) |
|
624 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
625 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
626 | 626 | ); |
627 | 627 | } |
628 | 628 | } |
@@ -635,31 +635,31 @@ discard block |
||
635 | 635 | * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts |
636 | 636 | * @return MultilingualTextValue |
637 | 637 | */ |
638 | - private function parseMultilingualTextParameter( array $snakSerializations, $parameterId ) { |
|
638 | + private function parseMultilingualTextParameter(array $snakSerializations, $parameterId) { |
|
639 | 639 | $result = []; |
640 | 640 | |
641 | - foreach ( $snakSerializations as $snakSerialization ) { |
|
642 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
643 | - $this->requireValueParameter( $snak, $parameterId ); |
|
641 | + foreach ($snakSerializations as $snakSerialization) { |
|
642 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
643 | + $this->requireValueParameter($snak, $parameterId); |
|
644 | 644 | |
645 | 645 | $value = $snak->getDataValue(); |
646 | - $this->requireMonolingualTextParameter( $value, $parameterId ); |
|
646 | + $this->requireMonolingualTextParameter($value, $parameterId); |
|
647 | 647 | /** @var MonolingualTextValue $value */ |
648 | 648 | '@phan-var MonolingualTextValue $value'; |
649 | 649 | |
650 | 650 | $code = $value->getLanguageCode(); |
651 | - if ( array_key_exists( $code, $result ) ) { |
|
651 | + if (array_key_exists($code, $result)) { |
|
652 | 652 | throw new ConstraintParameterException( |
653 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single-per-language' ) ) |
|
654 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
655 | - ->withLanguage( $code ) |
|
653 | + (new ViolationMessage('wbqc-violation-message-parameter-single-per-language')) |
|
654 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
655 | + ->withLanguage($code) |
|
656 | 656 | ); |
657 | 657 | } |
658 | 658 | |
659 | 659 | $result[$code] = $value; |
660 | 660 | } |
661 | 661 | |
662 | - return new MultilingualTextValue( $result ); |
|
662 | + return new MultilingualTextValue($result); |
|
663 | 663 | } |
664 | 664 | |
665 | 665 | /** |
@@ -667,11 +667,11 @@ discard block |
||
667 | 667 | * @throws ConstraintParameterException if the parameter is invalid |
668 | 668 | * @return MultilingualTextValue |
669 | 669 | */ |
670 | - public function parseSyntaxClarificationParameter( array $constraintParameters ) { |
|
671 | - $syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' ); |
|
670 | + public function parseSyntaxClarificationParameter(array $constraintParameters) { |
|
671 | + $syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId'); |
|
672 | 672 | |
673 | - if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) { |
|
674 | - return new MultilingualTextValue( [] ); |
|
673 | + if (!array_key_exists($syntaxClarificationId, $constraintParameters)) { |
|
674 | + return new MultilingualTextValue([]); |
|
675 | 675 | } |
676 | 676 | |
677 | 677 | $syntaxClarifications = $this->parseMultilingualTextParameter( |
@@ -696,7 +696,7 @@ discard block |
||
696 | 696 | array $validScopes |
697 | 697 | ) { |
698 | 698 | $contextTypes = []; |
699 | - $parameterId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' ); |
|
699 | + $parameterId = $this->config->get('WBQualityConstraintsConstraintScopeId'); |
|
700 | 700 | $items = $this->parseItemsParameter( |
701 | 701 | $constraintParameters, |
702 | 702 | $constraintTypeItemId, |
@@ -704,22 +704,22 @@ discard block |
||
704 | 704 | $parameterId |
705 | 705 | ); |
706 | 706 | |
707 | - if ( $items === [] ) { |
|
707 | + if ($items === []) { |
|
708 | 708 | return null; |
709 | 709 | } |
710 | 710 | |
711 | - foreach ( $items as $item ) { |
|
712 | - $contextTypes[] = $this->parseContextTypeItem( $item, 'constraint scope', $parameterId ); |
|
711 | + foreach ($items as $item) { |
|
712 | + $contextTypes[] = $this->parseContextTypeItem($item, 'constraint scope', $parameterId); |
|
713 | 713 | } |
714 | 714 | |
715 | - $invalidScopes = array_diff( $contextTypes, $validScopes ); |
|
716 | - if ( $invalidScopes !== [] ) { |
|
717 | - $invalidScope = array_pop( $invalidScopes ); |
|
715 | + $invalidScopes = array_diff($contextTypes, $validScopes); |
|
716 | + if ($invalidScopes !== []) { |
|
717 | + $invalidScope = array_pop($invalidScopes); |
|
718 | 718 | throw new ConstraintParameterException( |
719 | - ( new ViolationMessage( 'wbqc-violation-message-invalid-scope' ) ) |
|
720 | - ->withConstraintScope( $invalidScope, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
721 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
722 | - ->withConstraintScopeList( $validScopes, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
719 | + (new ViolationMessage('wbqc-violation-message-invalid-scope')) |
|
720 | + ->withConstraintScope($invalidScope, Role::CONSTRAINT_PARAMETER_VALUE) |
|
721 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
722 | + ->withConstraintScopeList($validScopes, Role::CONSTRAINT_PARAMETER_VALUE) |
|
723 | 723 | ); |
724 | 724 | } |
725 | 725 | |
@@ -732,8 +732,8 @@ discard block |
||
732 | 732 | * @param ItemId $unitId |
733 | 733 | * @return string unit |
734 | 734 | */ |
735 | - private function parseUnitParameter( ItemId $unitId ) { |
|
736 | - return $this->unitItemConceptBaseUri . $unitId->getSerialization(); |
|
735 | + private function parseUnitParameter(ItemId $unitId) { |
|
736 | + return $this->unitItemConceptBaseUri.$unitId->getSerialization(); |
|
737 | 737 | } |
738 | 738 | |
739 | 739 | /** |
@@ -743,23 +743,23 @@ discard block |
||
743 | 743 | * @return UnitsParameter |
744 | 744 | * @throws ConstraintParameterException |
745 | 745 | */ |
746 | - private function parseUnitItem( ItemIdSnakValue $item ) { |
|
747 | - switch ( true ) { |
|
746 | + private function parseUnitItem(ItemIdSnakValue $item) { |
|
747 | + switch (true) { |
|
748 | 748 | case $item->isValue(): |
749 | - $unit = $this->parseUnitParameter( $item->getItemId() ); |
|
749 | + $unit = $this->parseUnitParameter($item->getItemId()); |
|
750 | 750 | return new UnitsParameter( |
751 | - [ $item->getItemId() ], |
|
752 | - [ UnboundedQuantityValue::newFromNumber( 1, $unit ) ], |
|
751 | + [$item->getItemId()], |
|
752 | + [UnboundedQuantityValue::newFromNumber(1, $unit)], |
|
753 | 753 | false |
754 | 754 | ); |
755 | 755 | case $item->isSomeValue(): |
756 | - $qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
756 | + $qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
757 | 757 | throw new ConstraintParameterException( |
758 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
759 | - ->withEntityId( new PropertyId( $qualifierId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
758 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
759 | + ->withEntityId(new PropertyId($qualifierId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
760 | 760 | ); |
761 | 761 | case $item->isNoValue(): |
762 | - return new UnitsParameter( [], [], true ); |
|
762 | + return new UnitsParameter([], [], true); |
|
763 | 763 | } |
764 | 764 | } |
765 | 765 | |
@@ -769,26 +769,26 @@ discard block |
||
769 | 769 | * @throws ConstraintParameterException if the parameter is invalid or missing |
770 | 770 | * @return UnitsParameter |
771 | 771 | */ |
772 | - public function parseUnitsParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
773 | - $items = $this->parseItemsParameter( $constraintParameters, $constraintTypeItemId, true ); |
|
772 | + public function parseUnitsParameter(array $constraintParameters, $constraintTypeItemId) { |
|
773 | + $items = $this->parseItemsParameter($constraintParameters, $constraintTypeItemId, true); |
|
774 | 774 | $unitItems = []; |
775 | 775 | $unitQuantities = []; |
776 | 776 | $unitlessAllowed = false; |
777 | 777 | |
778 | - foreach ( $items as $item ) { |
|
779 | - $unit = $this->parseUnitItem( $item ); |
|
780 | - $unitItems = array_merge( $unitItems, $unit->getUnitItemIds() ); |
|
781 | - $unitQuantities = array_merge( $unitQuantities, $unit->getUnitQuantities() ); |
|
778 | + foreach ($items as $item) { |
|
779 | + $unit = $this->parseUnitItem($item); |
|
780 | + $unitItems = array_merge($unitItems, $unit->getUnitItemIds()); |
|
781 | + $unitQuantities = array_merge($unitQuantities, $unit->getUnitQuantities()); |
|
782 | 782 | $unitlessAllowed = $unitlessAllowed || $unit->getUnitlessAllowed(); |
783 | 783 | } |
784 | 784 | |
785 | - if ( $unitQuantities === [] && !$unitlessAllowed ) { |
|
785 | + if ($unitQuantities === [] && !$unitlessAllowed) { |
|
786 | 786 | throw new LogicException( |
787 | 787 | 'The "units" parameter is required, and yet we seem to be missing any allowed unit' |
788 | 788 | ); |
789 | 789 | } |
790 | 790 | |
791 | - return new UnitsParameter( $unitItems, $unitQuantities, $unitlessAllowed ); |
|
791 | + return new UnitsParameter($unitItems, $unitQuantities, $unitlessAllowed); |
|
792 | 792 | } |
793 | 793 | |
794 | 794 | /** |
@@ -798,53 +798,53 @@ discard block |
||
798 | 798 | * @return EntityTypesParameter |
799 | 799 | * @throws ConstraintParameterException |
800 | 800 | */ |
801 | - private function parseEntityTypeItem( ItemIdSnakValue $item ) { |
|
802 | - $parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
801 | + private function parseEntityTypeItem(ItemIdSnakValue $item) { |
|
802 | + $parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
803 | 803 | |
804 | - if ( !$item->isValue() ) { |
|
804 | + if (!$item->isValue()) { |
|
805 | 805 | throw new ConstraintParameterException( |
806 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
807 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
806 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
807 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
808 | 808 | ); |
809 | 809 | } |
810 | 810 | |
811 | 811 | $itemId = $item->getItemId(); |
812 | - switch ( $itemId->getSerialization() ) { |
|
813 | - case $this->config->get( 'WBQualityConstraintsWikibaseItemId' ): |
|
812 | + switch ($itemId->getSerialization()) { |
|
813 | + case $this->config->get('WBQualityConstraintsWikibaseItemId'): |
|
814 | 814 | $entityType = 'item'; |
815 | 815 | break; |
816 | - case $this->config->get( 'WBQualityConstraintsWikibasePropertyId' ): |
|
816 | + case $this->config->get('WBQualityConstraintsWikibasePropertyId'): |
|
817 | 817 | $entityType = 'property'; |
818 | 818 | break; |
819 | - case $this->config->get( 'WBQualityConstraintsWikibaseLexemeId' ): |
|
819 | + case $this->config->get('WBQualityConstraintsWikibaseLexemeId'): |
|
820 | 820 | $entityType = 'lexeme'; |
821 | 821 | break; |
822 | - case $this->config->get( 'WBQualityConstraintsWikibaseFormId' ): |
|
822 | + case $this->config->get('WBQualityConstraintsWikibaseFormId'): |
|
823 | 823 | $entityType = 'form'; |
824 | 824 | break; |
825 | - case $this->config->get( 'WBQualityConstraintsWikibaseSenseId' ): |
|
825 | + case $this->config->get('WBQualityConstraintsWikibaseSenseId'): |
|
826 | 826 | $entityType = 'sense'; |
827 | 827 | break; |
828 | - case $this->config->get( 'WBQualityConstraintsWikibaseMediaInfoId' ): |
|
828 | + case $this->config->get('WBQualityConstraintsWikibaseMediaInfoId'): |
|
829 | 829 | $entityType = 'mediainfo'; |
830 | 830 | break; |
831 | 831 | default: |
832 | 832 | $allowed = [ |
833 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseItemId' ) ), |
|
834 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibasePropertyId' ) ), |
|
835 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseLexemeId' ) ), |
|
836 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseFormId' ) ), |
|
837 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseSenseId' ) ), |
|
838 | - new ItemId( $this->config->get( 'WBQualityConstraintsWikibaseMediaInfoId' ) ), |
|
833 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseItemId')), |
|
834 | + new ItemId($this->config->get('WBQualityConstraintsWikibasePropertyId')), |
|
835 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseLexemeId')), |
|
836 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseFormId')), |
|
837 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseSenseId')), |
|
838 | + new ItemId($this->config->get('WBQualityConstraintsWikibaseMediaInfoId')), |
|
839 | 839 | ]; |
840 | 840 | throw new ConstraintParameterException( |
841 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
842 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
843 | - ->withEntityIdList( $allowed, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
841 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
842 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
843 | + ->withEntityIdList($allowed, Role::CONSTRAINT_PARAMETER_VALUE) |
|
844 | 844 | ); |
845 | 845 | } |
846 | 846 | |
847 | - return new EntityTypesParameter( [ $entityType ], [ $itemId ] ); |
|
847 | + return new EntityTypesParameter([$entityType], [$itemId]); |
|
848 | 848 | } |
849 | 849 | |
850 | 850 | /** |
@@ -853,27 +853,27 @@ discard block |
||
853 | 853 | * @throws ConstraintParameterException if the parameter is invalid or missing |
854 | 854 | * @return EntityTypesParameter |
855 | 855 | */ |
856 | - public function parseEntityTypesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
856 | + public function parseEntityTypesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
857 | 857 | $entityTypes = []; |
858 | 858 | $entityTypeItemIds = []; |
859 | - $items = $this->parseItemsParameter( $constraintParameters, $constraintTypeItemId, true ); |
|
859 | + $items = $this->parseItemsParameter($constraintParameters, $constraintTypeItemId, true); |
|
860 | 860 | |
861 | - foreach ( $items as $item ) { |
|
862 | - $entityType = $this->parseEntityTypeItem( $item ); |
|
863 | - $entityTypes = array_merge( $entityTypes, $entityType->getEntityTypes() ); |
|
864 | - $entityTypeItemIds = array_merge( $entityTypeItemIds, $entityType->getEntityTypeItemIds() ); |
|
861 | + foreach ($items as $item) { |
|
862 | + $entityType = $this->parseEntityTypeItem($item); |
|
863 | + $entityTypes = array_merge($entityTypes, $entityType->getEntityTypes()); |
|
864 | + $entityTypeItemIds = array_merge($entityTypeItemIds, $entityType->getEntityTypeItemIds()); |
|
865 | 865 | } |
866 | 866 | |
867 | - if ( empty( $entityTypes ) ) { |
|
867 | + if (empty($entityTypes)) { |
|
868 | 868 | // @codeCoverageIgnoreStart |
869 | 869 | throw new LogicException( |
870 | - 'The "entity types" parameter is required, ' . |
|
870 | + 'The "entity types" parameter is required, '. |
|
871 | 871 | 'and yet we seem to be missing any allowed entity type' |
872 | 872 | ); |
873 | 873 | // @codeCoverageIgnoreEnd |
874 | 874 | } |
875 | 875 | |
876 | - return new EntityTypesParameter( $entityTypes, $entityTypeItemIds ); |
|
876 | + return new EntityTypesParameter($entityTypes, $entityTypeItemIds); |
|
877 | 877 | } |
878 | 878 | |
879 | 879 | /** |
@@ -881,18 +881,18 @@ discard block |
||
881 | 881 | * @throws ConstraintParameterException if the parameter is invalid |
882 | 882 | * @return PropertyId[] |
883 | 883 | */ |
884 | - public function parseSeparatorsParameter( array $constraintParameters ) { |
|
885 | - $separatorId = $this->config->get( 'WBQualityConstraintsSeparatorId' ); |
|
884 | + public function parseSeparatorsParameter(array $constraintParameters) { |
|
885 | + $separatorId = $this->config->get('WBQualityConstraintsSeparatorId'); |
|
886 | 886 | |
887 | - if ( !array_key_exists( $separatorId, $constraintParameters ) ) { |
|
887 | + if (!array_key_exists($separatorId, $constraintParameters)) { |
|
888 | 888 | return []; |
889 | 889 | } |
890 | 890 | |
891 | 891 | $parameters = $constraintParameters[$separatorId]; |
892 | 892 | $separators = []; |
893 | 893 | |
894 | - foreach ( $parameters as $parameter ) { |
|
895 | - $separators[] = $this->parsePropertyIdParameter( $parameter, $separatorId ); |
|
894 | + foreach ($parameters as $parameter) { |
|
895 | + $separators[] = $this->parsePropertyIdParameter($parameter, $separatorId); |
|
896 | 896 | } |
897 | 897 | |
898 | 898 | return $separators; |
@@ -907,26 +907,26 @@ discard block |
||
907 | 907 | * @return string one of the Context::TYPE_* constants |
908 | 908 | * @throws ConstraintParameterException |
909 | 909 | */ |
910 | - private function parseContextTypeItem( ItemIdSnakValue $item, $use, $parameterId ) { |
|
911 | - if ( !$item->isValue() ) { |
|
910 | + private function parseContextTypeItem(ItemIdSnakValue $item, $use, $parameterId) { |
|
911 | + if (!$item->isValue()) { |
|
912 | 912 | throw new ConstraintParameterException( |
913 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
914 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
913 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
914 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
915 | 915 | ); |
916 | 916 | } |
917 | 917 | |
918 | - if ( $use === 'constraint scope' ) { |
|
919 | - $mainSnakId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' ); |
|
920 | - $qualifiersId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' ); |
|
921 | - $referencesId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' ); |
|
918 | + if ($use === 'constraint scope') { |
|
919 | + $mainSnakId = $this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId'); |
|
920 | + $qualifiersId = $this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId'); |
|
921 | + $referencesId = $this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId'); |
|
922 | 922 | } else { |
923 | - $mainSnakId = $this->config->get( 'WBQualityConstraintsAsMainValueId' ); |
|
924 | - $qualifiersId = $this->config->get( 'WBQualityConstraintsAsQualifiersId' ); |
|
925 | - $referencesId = $this->config->get( 'WBQualityConstraintsAsReferencesId' ); |
|
923 | + $mainSnakId = $this->config->get('WBQualityConstraintsAsMainValueId'); |
|
924 | + $qualifiersId = $this->config->get('WBQualityConstraintsAsQualifiersId'); |
|
925 | + $referencesId = $this->config->get('WBQualityConstraintsAsReferencesId'); |
|
926 | 926 | } |
927 | 927 | |
928 | 928 | $itemId = $item->getItemId(); |
929 | - switch ( $itemId->getSerialization() ) { |
|
929 | + switch ($itemId->getSerialization()) { |
|
930 | 930 | case $mainSnakId: |
931 | 931 | return Context::TYPE_STATEMENT; |
932 | 932 | case $qualifiersId: |
@@ -935,14 +935,14 @@ discard block |
||
935 | 935 | return Context::TYPE_REFERENCE; |
936 | 936 | default: |
937 | 937 | $allowed = [ |
938 | - new ItemId( $mainSnakId ), |
|
939 | - new ItemId( $qualifiersId ), |
|
940 | - new ItemId( $referencesId ), |
|
938 | + new ItemId($mainSnakId), |
|
939 | + new ItemId($qualifiersId), |
|
940 | + new ItemId($referencesId), |
|
941 | 941 | ]; |
942 | 942 | throw new ConstraintParameterException( |
943 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
944 | - ->withEntityId( new PropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
945 | - ->withEntityIdList( $allowed, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
943 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
944 | + ->withEntityId(new PropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
945 | + ->withEntityIdList($allowed, Role::CONSTRAINT_PARAMETER_VALUE) |
|
946 | 946 | ); |
947 | 947 | } |
948 | 948 | } |
@@ -953,9 +953,9 @@ discard block |
||
953 | 953 | * @throws ConstraintParameterException if the parameter is invalid or missing |
954 | 954 | * @return string[] list of Context::TYPE_* constants |
955 | 955 | */ |
956 | - public function parsePropertyScopeParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
956 | + public function parsePropertyScopeParameter(array $constraintParameters, $constraintTypeItemId) { |
|
957 | 957 | $contextTypes = []; |
958 | - $parameterId = $this->config->get( 'WBQualityConstraintsPropertyScopeId' ); |
|
958 | + $parameterId = $this->config->get('WBQualityConstraintsPropertyScopeId'); |
|
959 | 959 | $items = $this->parseItemsParameter( |
960 | 960 | $constraintParameters, |
961 | 961 | $constraintTypeItemId, |
@@ -963,14 +963,14 @@ discard block |
||
963 | 963 | $parameterId |
964 | 964 | ); |
965 | 965 | |
966 | - foreach ( $items as $item ) { |
|
967 | - $contextTypes[] = $this->parseContextTypeItem( $item, 'property scope', $parameterId ); |
|
966 | + foreach ($items as $item) { |
|
967 | + $contextTypes[] = $this->parseContextTypeItem($item, 'property scope', $parameterId); |
|
968 | 968 | } |
969 | 969 | |
970 | - if ( empty( $contextTypes ) ) { |
|
970 | + if (empty($contextTypes)) { |
|
971 | 971 | // @codeCoverageIgnoreStart |
972 | 972 | throw new LogicException( |
973 | - 'The "property scope" parameter is required, ' . |
|
973 | + 'The "property scope" parameter is required, '. |
|
974 | 974 | 'and yet we seem to be missing any allowed scope' |
975 | 975 | ); |
976 | 976 | // @codeCoverageIgnoreEnd |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * @throws ConstraintParameterException |
98 | 98 | * @return CheckResult |
99 | 99 | */ |
100 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
100 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
101 | 101 | $parameters = []; |
102 | 102 | $constraintParameters = $constraint->getConstraintParameters(); |
103 | 103 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | $constraintParameters, |
107 | 107 | $constraintTypeItemId |
108 | 108 | ); |
109 | - $parameters['pattern'] = [ $format ]; |
|
109 | + $parameters['pattern'] = [$format]; |
|
110 | 110 | |
111 | 111 | $syntaxClarifications = $this->constraintParameterParser->parseSyntaxClarificationParameter( |
112 | 112 | $constraintParameters |
@@ -114,9 +114,9 @@ discard block |
||
114 | 114 | |
115 | 115 | $snak = $context->getSnak(); |
116 | 116 | |
117 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
117 | + if (!$snak instanceof PropertyValueSnak) { |
|
118 | 118 | // nothing to check |
119 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
119 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | $dataValue = $snak->getDataValue(); |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * error handling: |
126 | 126 | * type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext' |
127 | 127 | */ |
128 | - switch ( $dataValue->getType() ) { |
|
128 | + switch ($dataValue->getType()) { |
|
129 | 129 | case 'string': |
130 | 130 | $text = $dataValue->getValue(); |
131 | 131 | break; |
@@ -135,13 +135,13 @@ discard block |
||
135 | 135 | $text = $dataValue->getText(); |
136 | 136 | break; |
137 | 137 | default: |
138 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-types-2' ) ) |
|
139 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
140 | - ->withDataValueType( 'string' ) |
|
141 | - ->withDataValueType( 'monolingualtext' ); |
|
142 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
138 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-types-2')) |
|
139 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
140 | + ->withDataValueType('string') |
|
141 | + ->withDataValueType('monolingualtext'); |
|
142 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
143 | 143 | } |
144 | - $status = $this->runRegexCheck( $text, $format ); |
|
144 | + $status = $this->runRegexCheck($text, $format); |
|
145 | 145 | $message = $this->formatMessage( |
146 | 146 | $status, |
147 | 147 | $text, |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | $syntaxClarifications, |
151 | 151 | $constraintTypeItemId |
152 | 152 | ); |
153 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
153 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | private function formatMessage( |
@@ -162,74 +162,74 @@ discard block |
||
162 | 162 | string $constraintTypeItemId |
163 | 163 | ): ?ViolationMessage { |
164 | 164 | $message = null; |
165 | - if ( $status === CheckResult::STATUS_VIOLATION ) { |
|
166 | - $message = ( new ViolationMessage( 'wbqc-violation-message-format-clarification' ) ) |
|
167 | - ->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ) |
|
168 | - ->withDataValue( new StringValue( $text ), Role::OBJECT ) |
|
169 | - ->withInlineCode( $format, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
170 | - ->withMultilingualText( $syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE ); |
|
171 | - } elseif ( $status === CheckResult::STATUS_TODO ) { |
|
172 | - $message = ( new ViolationMessage( 'wbqc-violation-message-security-reason' ) ) |
|
173 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ); |
|
165 | + if ($status === CheckResult::STATUS_VIOLATION) { |
|
166 | + $message = (new ViolationMessage('wbqc-violation-message-format-clarification')) |
|
167 | + ->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY) |
|
168 | + ->withDataValue(new StringValue($text), Role::OBJECT) |
|
169 | + ->withInlineCode($format, Role::CONSTRAINT_PARAMETER_VALUE) |
|
170 | + ->withMultilingualText($syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE); |
|
171 | + } elseif ($status === CheckResult::STATUS_TODO) { |
|
172 | + $message = (new ViolationMessage('wbqc-violation-message-security-reason')) |
|
173 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | return $message; |
177 | 177 | } |
178 | 178 | |
179 | - private function runRegexCheck( string $text, string $format ): string { |
|
180 | - if ( !$this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) ) { |
|
179 | + private function runRegexCheck(string $text, string $format): string { |
|
180 | + if (!$this->config->get('WBQualityConstraintsCheckFormatConstraint')) { |
|
181 | 181 | return CheckResult::STATUS_TODO; |
182 | 182 | } |
183 | 183 | if ( |
184 | - $this->config->get( 'WBQualityConstraintsFormatCheckerShellboxRatio' ) > (float)wfRandom() |
|
184 | + $this->config->get('WBQualityConstraintsFormatCheckerShellboxRatio') > (float) wfRandom() |
|
185 | 185 | ) { |
186 | - return $this->runRegexCheckUsingShellbox( $text, $format ); |
|
186 | + return $this->runRegexCheckUsingShellbox($text, $format); |
|
187 | 187 | } |
188 | 188 | |
189 | - return $this->runRegexCheckUsingSparql( $text, $format ); |
|
189 | + return $this->runRegexCheckUsingSparql($text, $format); |
|
190 | 190 | } |
191 | 191 | |
192 | - private function runRegexCheckUsingShellbox( string $text, string $format ): string { |
|
193 | - if ( !$this->shellboxClientFactory->isEnabled( 'constraint-regex-checker' ) ) { |
|
192 | + private function runRegexCheckUsingShellbox(string $text, string $format): string { |
|
193 | + if (!$this->shellboxClientFactory->isEnabled('constraint-regex-checker')) { |
|
194 | 194 | return CheckResult::STATUS_TODO; |
195 | 195 | } |
196 | 196 | try { |
197 | - $pattern = '/^(?:' . str_replace( '/', '\/', $format ) . ')$/u'; |
|
198 | - $shellboxResponse = $this->shellboxClientFactory->getClient( [ |
|
199 | - 'timeout' => $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' ) / 1000, |
|
197 | + $pattern = '/^(?:'.str_replace('/', '\/', $format).')$/u'; |
|
198 | + $shellboxResponse = $this->shellboxClientFactory->getClient([ |
|
199 | + 'timeout' => $this->config->get('WBQualityConstraintsSparqlMaxMillis') / 1000, |
|
200 | 200 | 'service' => 'constraint-regex-checker', |
201 | - ] )->call( |
|
201 | + ])->call( |
|
202 | 202 | 'constraint-regex-checker', |
203 | 203 | 'preg_match', |
204 | - [ $pattern, $text ] |
|
204 | + [$pattern, $text] |
|
205 | 205 | ); |
206 | - } catch ( ShellboxError $exception ) { |
|
206 | + } catch (ShellboxError $exception) { |
|
207 | 207 | throw new ConstraintParameterException( |
208 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
209 | - ->withInlineCode( $pattern, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
208 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
209 | + ->withInlineCode($pattern, Role::CONSTRAINT_PARAMETER_VALUE) |
|
210 | 210 | ); |
211 | 211 | } |
212 | 212 | |
213 | - if ( $shellboxResponse ) { |
|
213 | + if ($shellboxResponse) { |
|
214 | 214 | return CheckResult::STATUS_COMPLIANCE; |
215 | 215 | } else { |
216 | 216 | return CheckResult::STATUS_VIOLATION; |
217 | 217 | } |
218 | 218 | } |
219 | 219 | |
220 | - private function runRegexCheckUsingSparql( string $text, string $format ): string { |
|
221 | - if ( $this->sparqlHelper instanceof DummySparqlHelper ) { |
|
220 | + private function runRegexCheckUsingSparql(string $text, string $format): string { |
|
221 | + if ($this->sparqlHelper instanceof DummySparqlHelper) { |
|
222 | 222 | return CheckResult::STATUS_TODO; |
223 | 223 | } |
224 | 224 | |
225 | - if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) { |
|
225 | + if ($this->sparqlHelper->matchesRegularExpression($text, $format)) { |
|
226 | 226 | return CheckResult::STATUS_COMPLIANCE; |
227 | 227 | } else { |
228 | 228 | return CheckResult::STATUS_VIOLATION; |
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
232 | + public function checkConstraintParameters(Constraint $constraint) { |
|
233 | 233 | $constraintParameters = $constraint->getConstraintParameters(); |
234 | 234 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
235 | 235 | $exceptions = []; |
@@ -238,14 +238,14 @@ discard block |
||
238 | 238 | $constraintParameters, |
239 | 239 | $constraintTypeItemId |
240 | 240 | ); |
241 | - } catch ( ConstraintParameterException $e ) { |
|
241 | + } catch (ConstraintParameterException $e) { |
|
242 | 242 | $exceptions[] = $e; |
243 | 243 | } |
244 | 244 | try { |
245 | 245 | $this->constraintParameterParser->parseSyntaxClarificationParameter( |
246 | 246 | $constraintParameters |
247 | 247 | ); |
248 | - } catch ( ConstraintParameterException $e ) { |
|
248 | + } catch (ConstraintParameterException $e) { |
|
249 | 249 | $exceptions[] = $e; |
250 | 250 | } |
251 | 251 | return $exceptions; |