@@ -80,23 +80,23 @@ 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 | /** @var Statement $statement */ |
96 | - foreach ( $item->getStatements()->getByPropertyId( new PropertyId( $subclassId ) ) as $statement ) { |
|
96 | + foreach ($item->getStatements()->getByPropertyId(new PropertyId($subclassId)) as $statement) { |
|
97 | 97 | $mainSnak = $statement->getMainSnak(); |
98 | 98 | |
99 | - if ( !( $this->hasCorrectType( $mainSnak ) ) ) { |
|
99 | + if (!($this->hasCorrectType($mainSnak))) { |
|
100 | 100 | continue; |
101 | 101 | } |
102 | 102 | /** @var PropertyValueSnak $mainSnak */ |
@@ -105,11 +105,11 @@ discard block |
||
105 | 105 | $dataValue = $mainSnak->getDataValue(); |
106 | 106 | $comparativeClass = $dataValue->getEntityId(); |
107 | 107 | |
108 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
108 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
109 | 109 | return true; |
110 | 110 | } |
111 | 111 | |
112 | - if ( $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ) ) { |
|
112 | + if ($this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked)) { |
|
113 | 113 | return true; |
114 | 114 | } |
115 | 115 | } |
@@ -130,44 +130,44 @@ discard block |
||
130 | 130 | * @return CachedBool |
131 | 131 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
132 | 132 | */ |
133 | - public function isSubclassOfWithSparqlFallback( EntityId $comparativeClass, array $classesToCheck ) { |
|
133 | + public function isSubclassOfWithSparqlFallback(EntityId $comparativeClass, array $classesToCheck) { |
|
134 | 134 | try { |
135 | - $start1 = microtime( true ); |
|
136 | - $isSubclass = $this->isSubclassOf( $comparativeClass, $classesToCheck ); |
|
137 | - $end1 = microtime( true ); |
|
135 | + $start1 = microtime(true); |
|
136 | + $isSubclass = $this->isSubclassOf($comparativeClass, $classesToCheck); |
|
137 | + $end1 = microtime(true); |
|
138 | 138 | $this->dataFactory->timing( |
139 | 139 | 'wikibase.quality.constraints.type.php.success.timing', |
140 | - ( $end1 - $start1 ) * 1000 |
|
140 | + ($end1 - $start1) * 1000 |
|
141 | 141 | ); |
142 | 142 | |
143 | - return new CachedBool( $isSubclass, Metadata::blank() ); |
|
144 | - } catch ( OverflowException $e ) { |
|
145 | - $end1 = microtime( true ); |
|
143 | + return new CachedBool($isSubclass, Metadata::blank()); |
|
144 | + } catch (OverflowException $e) { |
|
145 | + $end1 = microtime(true); |
|
146 | 146 | $this->dataFactory->timing( |
147 | 147 | 'wikibase.quality.constraints.type.php.overflow.timing', |
148 | - ( $end1 - $start1 ) * 1000 |
|
148 | + ($end1 - $start1) * 1000 |
|
149 | 149 | ); |
150 | 150 | |
151 | - if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) { |
|
151 | + if (!($this->sparqlHelper instanceof DummySparqlHelper)) { |
|
152 | 152 | $this->dataFactory->increment( |
153 | 153 | 'wikibase.quality.constraints.sparql.typeFallback' |
154 | 154 | ); |
155 | 155 | |
156 | - $start2 = microtime( true ); |
|
156 | + $start2 = microtime(true); |
|
157 | 157 | $hasType = $this->sparqlHelper->hasType( |
158 | 158 | $comparativeClass->getSerialization(), |
159 | 159 | $classesToCheck, |
160 | 160 | /* withInstance = */ false |
161 | 161 | ); |
162 | - $end2 = microtime( true ); |
|
162 | + $end2 = microtime(true); |
|
163 | 163 | $this->dataFactory->timing( |
164 | 164 | 'wikibase.quality.constraints.type.sparql.success.timing', |
165 | - ( $end2 - $start2 ) * 1000 |
|
165 | + ($end2 - $start2) * 1000 |
|
166 | 166 | ); |
167 | 167 | |
168 | 168 | return $hasType; |
169 | 169 | } else { |
170 | - return new CachedBool( false, Metadata::blank() ); |
|
170 | + return new CachedBool(false, Metadata::blank()); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | } |
@@ -185,13 +185,13 @@ discard block |
||
185 | 185 | * @return CachedBool |
186 | 186 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
187 | 187 | */ |
188 | - public function hasClassInRelation( StatementList $statements, array $relationIds, array $classesToCheck ) { |
|
188 | + public function hasClassInRelation(StatementList $statements, array $relationIds, array $classesToCheck) { |
|
189 | 189 | $metadatas = []; |
190 | 190 | |
191 | - foreach ( $this->getStatementsByPropertyIds( $statements, $relationIds ) as $statement ) { |
|
191 | + foreach ($this->getStatementsByPropertyIds($statements, $relationIds) as $statement) { |
|
192 | 192 | $mainSnak = $statement->getMainSnak(); |
193 | 193 | |
194 | - if ( !$this->hasCorrectType( $mainSnak ) ) { |
|
194 | + if (!$this->hasCorrectType($mainSnak)) { |
|
195 | 195 | continue; |
196 | 196 | } |
197 | 197 | /** @var PropertyValueSnak $mainSnak */ |
@@ -200,28 +200,28 @@ discard block |
||
200 | 200 | $dataValue = $mainSnak->getDataValue(); |
201 | 201 | $comparativeClass = $dataValue->getEntityId(); |
202 | 202 | |
203 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
203 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
204 | 204 | // discard $metadatas, we know this is fresh |
205 | - return new CachedBool( true, Metadata::blank() ); |
|
205 | + return new CachedBool(true, Metadata::blank()); |
|
206 | 206 | } |
207 | 207 | |
208 | - $result = $this->isSubclassOfWithSparqlFallback( $comparativeClass, $classesToCheck ); |
|
208 | + $result = $this->isSubclassOfWithSparqlFallback($comparativeClass, $classesToCheck); |
|
209 | 209 | $metadatas[] = $result->getMetadata(); |
210 | - if ( $result->getBool() ) { |
|
210 | + if ($result->getBool()) { |
|
211 | 211 | return new CachedBool( |
212 | 212 | true, |
213 | - Metadata::merge( $metadatas ) |
|
213 | + Metadata::merge($metadatas) |
|
214 | 214 | ); |
215 | 215 | } |
216 | 216 | } |
217 | 217 | |
218 | 218 | return new CachedBool( |
219 | 219 | false, |
220 | - Metadata::merge( $metadatas ) |
|
220 | + Metadata::merge($metadatas) |
|
221 | 221 | ); |
222 | 222 | } |
223 | 223 | |
224 | - private function hasCorrectType( Snak $mainSnak ) { |
|
224 | + private function hasCorrectType(Snak $mainSnak) { |
|
225 | 225 | return $mainSnak instanceof PropertyValueSnak |
226 | 226 | && $mainSnak->getDataValue()->getType() === 'wikibase-entityid'; |
227 | 227 | } |
@@ -238,12 +238,12 @@ discard block |
||
238 | 238 | ) { |
239 | 239 | $statementArrays = []; |
240 | 240 | |
241 | - foreach ( $propertyIdSerializations as $propertyIdSerialization ) { |
|
242 | - $propertyId = new PropertyId( $propertyIdSerialization ); |
|
243 | - $statementArrays[] = $statements->getByPropertyId( $propertyId )->toArray(); |
|
241 | + foreach ($propertyIdSerializations as $propertyIdSerialization) { |
|
242 | + $propertyId = new PropertyId($propertyIdSerialization); |
|
243 | + $statementArrays[] = $statements->getByPropertyId($propertyId)->toArray(); |
|
244 | 244 | } |
245 | 245 | |
246 | - return call_user_func_array( 'array_merge', $statementArrays ); |
|
246 | + return call_user_func_array('array_merge', $statementArrays); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
@@ -255,10 +255,10 @@ discard block |
||
255 | 255 | * |
256 | 256 | * @return ViolationMessage |
257 | 257 | */ |
258 | - public function getViolationMessage( PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation ) { |
|
258 | + public function getViolationMessage(PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation) { |
|
259 | 259 | $classes = array_map( |
260 | - function( $itemIdSerialization ) { |
|
261 | - return new ItemId( $itemIdSerialization ); |
|
260 | + function($itemIdSerialization) { |
|
261 | + return new ItemId($itemIdSerialization); |
|
262 | 262 | }, |
263 | 263 | $classes |
264 | 264 | ); |
@@ -270,10 +270,10 @@ discard block |
||
270 | 270 | // wbqc-violation-message-valueType-instance |
271 | 271 | // wbqc-violation-message-valueType-subclass |
272 | 272 | // wbqc-violation-message-valueType-instanceOrSubclass |
273 | - return ( new ViolationMessage( 'wbqc-violation-message-' . $checker . '-' . $relation ) ) |
|
274 | - ->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ) |
|
275 | - ->withEntityId( $entityId, Role::SUBJECT ) |
|
276 | - ->withEntityIdList( $classes, Role::OBJECT ); |
|
273 | + return (new ViolationMessage('wbqc-violation-message-'.$checker.'-'.$relation)) |
|
274 | + ->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY) |
|
275 | + ->withEntityId($entityId, Role::SUBJECT) |
|
276 | + ->withEntityIdList($classes, Role::OBJECT); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | } |