@@ -89,23 +89,23 @@ discard block |
||
89 | 89 | * @return bool |
90 | 90 | * @throws OverflowException if $entitiesChecked exceeds the configured limit |
91 | 91 | */ |
92 | - private function isSubclassOf( EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0 ) { |
|
93 | - $maxEntities = $this->config->get( 'WBQualityConstraintsTypeCheckMaxEntities' ); |
|
92 | + private function isSubclassOf(EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0) { |
|
93 | + $maxEntities = $this->config->get('WBQualityConstraintsTypeCheckMaxEntities'); |
|
94 | 94 | if ( ++$entitiesChecked > $maxEntities ) { |
95 | - throw new OverflowException( 'Too many entities to check' ); |
|
95 | + throw new OverflowException('Too many entities to check'); |
|
96 | 96 | } |
97 | 97 | |
98 | - $item = $this->entityLookup->getEntity( $comparativeClass ); |
|
99 | - if ( !( $item instanceof StatementListProvider ) ) { |
|
98 | + $item = $this->entityLookup->getEntity($comparativeClass); |
|
99 | + if (!($item instanceof StatementListProvider)) { |
|
100 | 100 | return false; // lookup failed, probably because item doesn't exist |
101 | 101 | } |
102 | 102 | |
103 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
103 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
104 | 104 | /** @var Statement $statement */ |
105 | - foreach ( $item->getStatements()->getByPropertyId( new PropertyId( $subclassId ) ) as $statement ) { |
|
105 | + foreach ($item->getStatements()->getByPropertyId(new PropertyId($subclassId)) as $statement) { |
|
106 | 106 | $mainSnak = $statement->getMainSnak(); |
107 | 107 | |
108 | - if ( !( $this->hasCorrectType( $mainSnak ) ) ) { |
|
108 | + if (!($this->hasCorrectType($mainSnak))) { |
|
109 | 109 | continue; |
110 | 110 | } |
111 | 111 | /** @var PropertyValueSnak $mainSnak */ |
@@ -114,11 +114,11 @@ discard block |
||
114 | 114 | $dataValue = $mainSnak->getDataValue(); |
115 | 115 | $comparativeClass = $dataValue->getEntityId(); |
116 | 116 | |
117 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
117 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
118 | 118 | return true; |
119 | 119 | } |
120 | 120 | |
121 | - if ( $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ) ) { |
|
121 | + if ($this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked)) { |
|
122 | 122 | return true; |
123 | 123 | } |
124 | 124 | } |
@@ -139,14 +139,14 @@ discard block |
||
139 | 139 | * @return CachedBool |
140 | 140 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
141 | 141 | */ |
142 | - public function isSubclassOfWithSparqlFallback( EntityId $comparativeClass, array $classesToCheck ) { |
|
142 | + public function isSubclassOfWithSparqlFallback(EntityId $comparativeClass, array $classesToCheck) { |
|
143 | 143 | try { |
144 | 144 | return new CachedBool( |
145 | - $this->isSubclassOf( $comparativeClass, $classesToCheck ), |
|
145 | + $this->isSubclassOf($comparativeClass, $classesToCheck), |
|
146 | 146 | Metadata::blank() |
147 | 147 | ); |
148 | - } catch ( OverflowException $e ) { |
|
149 | - if ( $this->sparqlHelper !== null ) { |
|
148 | + } catch (OverflowException $e) { |
|
149 | + if ($this->sparqlHelper !== null) { |
|
150 | 150 | $this->dataFactory->increment( |
151 | 151 | 'wikibase.quality.constraints.sparql.typeFallback' |
152 | 152 | ); |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | /* withInstance = */ false |
157 | 157 | ); |
158 | 158 | } else { |
159 | - return new CachedBool( false, Metadata::blank() ); |
|
159 | + return new CachedBool(false, Metadata::blank()); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | } |
@@ -174,13 +174,13 @@ discard block |
||
174 | 174 | * @return CachedBool |
175 | 175 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
176 | 176 | */ |
177 | - public function hasClassInRelation( StatementList $statements, array $relationIds, array $classesToCheck ) { |
|
177 | + public function hasClassInRelation(StatementList $statements, array $relationIds, array $classesToCheck) { |
|
178 | 178 | $metadatas = []; |
179 | 179 | |
180 | - foreach ( $this->getStatementsByPropertyIds( $statements, $relationIds ) as $statement ) { |
|
180 | + foreach ($this->getStatementsByPropertyIds($statements, $relationIds) as $statement) { |
|
181 | 181 | $mainSnak = $statement->getMainSnak(); |
182 | 182 | |
183 | - if ( !$this->hasCorrectType( $mainSnak ) ) { |
|
183 | + if (!$this->hasCorrectType($mainSnak)) { |
|
184 | 184 | continue; |
185 | 185 | } |
186 | 186 | /** @var PropertyValueSnak $mainSnak */ |
@@ -189,28 +189,28 @@ discard block |
||
189 | 189 | $dataValue = $mainSnak->getDataValue(); |
190 | 190 | $comparativeClass = $dataValue->getEntityId(); |
191 | 191 | |
192 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
192 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
193 | 193 | // discard $metadatas, we know this is fresh |
194 | - return new CachedBool( true, Metadata::blank() ); |
|
194 | + return new CachedBool(true, Metadata::blank()); |
|
195 | 195 | } |
196 | 196 | |
197 | - $result = $this->isSubclassOfWithSparqlFallback( $comparativeClass, $classesToCheck ); |
|
197 | + $result = $this->isSubclassOfWithSparqlFallback($comparativeClass, $classesToCheck); |
|
198 | 198 | $metadatas[] = $result->getMetadata(); |
199 | - if ( $result->getBool() ) { |
|
199 | + if ($result->getBool()) { |
|
200 | 200 | return new CachedBool( |
201 | 201 | true, |
202 | - Metadata::merge( $metadatas ) |
|
202 | + Metadata::merge($metadatas) |
|
203 | 203 | ); |
204 | 204 | } |
205 | 205 | } |
206 | 206 | |
207 | 207 | return new CachedBool( |
208 | 208 | false, |
209 | - Metadata::merge( $metadatas ) |
|
209 | + Metadata::merge($metadatas) |
|
210 | 210 | ); |
211 | 211 | } |
212 | 212 | |
213 | - private function hasCorrectType( Snak $mainSnak ) { |
|
213 | + private function hasCorrectType(Snak $mainSnak) { |
|
214 | 214 | return $mainSnak instanceof PropertyValueSnak |
215 | 215 | && $mainSnak->getDataValue()->getType() === 'wikibase-entityid'; |
216 | 216 | } |
@@ -227,12 +227,12 @@ discard block |
||
227 | 227 | ) { |
228 | 228 | $statementArrays = []; |
229 | 229 | |
230 | - foreach ( $propertyIdSerializations as $propertyIdSerialization ) { |
|
231 | - $propertyId = new PropertyId( $propertyIdSerialization ); |
|
232 | - $statementArrays[] = $statements->getByPropertyId( $propertyId )->toArray(); |
|
230 | + foreach ($propertyIdSerializations as $propertyIdSerialization) { |
|
231 | + $propertyId = new PropertyId($propertyIdSerialization); |
|
232 | + $statementArrays[] = $statements->getByPropertyId($propertyId)->toArray(); |
|
233 | 233 | } |
234 | 234 | |
235 | - return call_user_func_array( 'array_merge', $statementArrays ); |
|
235 | + return call_user_func_array('array_merge', $statementArrays); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -244,10 +244,10 @@ discard block |
||
244 | 244 | * |
245 | 245 | * @return ViolationMessage |
246 | 246 | */ |
247 | - public function getViolationMessage( PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation ) { |
|
247 | + public function getViolationMessage(PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation) { |
|
248 | 248 | $classes = array_map( |
249 | - function( $itemIdSerialization ) { |
|
250 | - return new ItemId( $itemIdSerialization ); |
|
249 | + function($itemIdSerialization) { |
|
250 | + return new ItemId($itemIdSerialization); |
|
251 | 251 | }, |
252 | 252 | $classes |
253 | 253 | ); |
@@ -259,10 +259,10 @@ discard block |
||
259 | 259 | // wbqc-violation-message-valueType-instance |
260 | 260 | // wbqc-violation-message-valueType-subclass |
261 | 261 | // wbqc-violation-message-valueType-instanceOrSubclass |
262 | - return ( new ViolationMessage( 'wbqc-violation-message-' . $checker . '-' . $relation ) ) |
|
263 | - ->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ) |
|
264 | - ->withEntityId( $entityId, Role::SUBJECT ) |
|
265 | - ->withEntityIdList( $classes, Role::OBJECT ); |
|
262 | + return (new ViolationMessage('wbqc-violation-message-'.$checker.'-'.$relation)) |
|
263 | + ->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY) |
|
264 | + ->withEntityId($entityId, Role::SUBJECT) |
|
265 | + ->withEntityIdList($classes, Role::OBJECT); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | } |