@@ -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 | } |