@@ -65,6 +65,7 @@ discard block |
||
65 | 65 | * and return it along with the associated log level. |
66 | 66 | * |
67 | 67 | * @param float $durationSeconds |
68 | + * @param double[] $limits |
|
68 | 69 | * @return array [ $limitSeconds, $logLevel ] |
69 | 70 | */ |
70 | 71 | private function findLimit( $limits, $durationSeconds ) { |
@@ -174,6 +175,7 @@ discard block |
||
174 | 175 | * @param EntityId $entityId |
175 | 176 | * @param CheckResult[] $checkResults |
176 | 177 | * @param float $durationSeconds |
178 | + * @param string $method |
|
177 | 179 | */ |
178 | 180 | public function logConstraintCheckOnEntity( |
179 | 181 | EntityId $entityId, |
@@ -51,12 +51,12 @@ discard block |
||
51 | 51 | $this->dataFactory = $dataFactory; |
52 | 52 | $this->logger = $logger; |
53 | 53 | $this->constraintCheckDurationLimits = [ |
54 | - 'info' => $config->get( 'WBQualityConstraintsCheckDurationInfoSeconds' ), |
|
55 | - 'warning' => $config->get( 'WBQualityConstraintsCheckDurationWarningSeconds' ), |
|
54 | + 'info' => $config->get('WBQualityConstraintsCheckDurationInfoSeconds'), |
|
55 | + 'warning' => $config->get('WBQualityConstraintsCheckDurationWarningSeconds'), |
|
56 | 56 | ]; |
57 | 57 | $this->constraintCheckOnEntityDurationLimits = [ |
58 | - 'info' => $config->get( 'WBQualityConstraintsCheckOnEntityDurationInfoSeconds' ), |
|
59 | - 'warning' => $config->get( 'WBQualityConstraintsCheckOnEntityDurationWarningSeconds' ), |
|
58 | + 'info' => $config->get('WBQualityConstraintsCheckOnEntityDurationInfoSeconds'), |
|
59 | + 'warning' => $config->get('WBQualityConstraintsCheckOnEntityDurationWarningSeconds'), |
|
60 | 60 | ]; |
61 | 61 | } |
62 | 62 | |
@@ -67,23 +67,23 @@ discard block |
||
67 | 67 | * @param float $durationSeconds |
68 | 68 | * @return array [ $limitSeconds, $logLevel ] |
69 | 69 | */ |
70 | - private function findLimit( $limits, $durationSeconds ) { |
|
70 | + private function findLimit($limits, $durationSeconds) { |
|
71 | 71 | $limitSeconds = null; |
72 | 72 | $logLevel = null; |
73 | 73 | |
74 | - foreach ( $limits as $level => $limit ) { |
|
74 | + foreach ($limits as $level => $limit) { |
|
75 | 75 | if ( |
76 | 76 | // duration exceeds this limit |
77 | - isset( $limit ) && $durationSeconds > $limit && |
|
77 | + isset($limit) && $durationSeconds > $limit && |
|
78 | 78 | // this limit is longer than previous longest limit |
79 | - ( $limitSeconds === null || $limit > $limitSeconds ) |
|
79 | + ($limitSeconds === null || $limit > $limitSeconds) |
|
80 | 80 | ) { |
81 | 81 | $limitSeconds = $limit; |
82 | 82 | $logLevel = $level; |
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
86 | - return [ $limitSeconds, $logLevel ]; |
|
86 | + return [$limitSeconds, $logLevel]; |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -108,31 +108,31 @@ discard block |
||
108 | 108 | $durationSeconds, |
109 | 109 | $method |
110 | 110 | ) { |
111 | - $constraintCheckerClassShortName = substr( strrchr( $constraintCheckerClass, '\\' ), 1 ); |
|
111 | + $constraintCheckerClassShortName = substr(strrchr($constraintCheckerClass, '\\'), 1); |
|
112 | 112 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
113 | 113 | |
114 | 114 | $this->dataFactory->timing( |
115 | - 'wikibase.quality.constraints.check.timing.' . |
|
116 | - $constraintTypeItemId . '-' . |
|
115 | + 'wikibase.quality.constraints.check.timing.'. |
|
116 | + $constraintTypeItemId.'-'. |
|
117 | 117 | $constraintCheckerClassShortName, |
118 | 118 | $durationSeconds * 1000 |
119 | 119 | ); |
120 | 120 | |
121 | 121 | // find the longest limit (and associated log level) that the duration exceeds |
122 | - list( $limitSeconds, $logLevel ) = $this->findLimit( |
|
122 | + list($limitSeconds, $logLevel) = $this->findLimit( |
|
123 | 123 | $this->constraintCheckDurationLimits, |
124 | 124 | $durationSeconds |
125 | 125 | ); |
126 | - if ( $limitSeconds === null ) { |
|
126 | + if ($limitSeconds === null) { |
|
127 | 127 | return; |
128 | 128 | } |
129 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
129 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
130 | 130 | // TODO log less details but still log something |
131 | 131 | return; |
132 | 132 | } |
133 | 133 | |
134 | 134 | $resultMessage = $result->getMessage(); |
135 | - if ( $resultMessage !== null ) { |
|
135 | + if ($resultMessage !== null) { |
|
136 | 136 | $resultMessageKey = $resultMessage->getMessageKey(); |
137 | 137 | } else { |
138 | 138 | $resultMessageKey = null; |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | |
141 | 141 | $this->logger->log( |
142 | 142 | $logLevel, |
143 | - 'Constraint check with {constraintCheckerClassShortName} ' . |
|
144 | - 'took longer than {limitSeconds} second(s) ' . |
|
143 | + 'Constraint check with {constraintCheckerClassShortName} '. |
|
144 | + 'took longer than {limitSeconds} second(s) '. |
|
145 | 145 | '(duration: {durationSeconds} seconds).', |
146 | 146 | [ |
147 | 147 | 'method' => $method, |
@@ -151,13 +151,13 @@ discard block |
||
151 | 151 | 'constraintId' => $constraint->getConstraintId(), |
152 | 152 | 'constraintPropertyId' => $constraint->getPropertyId()->getSerialization(), |
153 | 153 | 'constraintTypeItemId' => $constraintTypeItemId, |
154 | - 'constraintParameters' => json_encode( $constraint->getConstraintParameters() ), |
|
154 | + 'constraintParameters' => json_encode($constraint->getConstraintParameters()), |
|
155 | 155 | 'constraintCheckerClass' => $constraintCheckerClass, |
156 | 156 | 'constraintCheckerClassShortName' => $constraintCheckerClassShortName, |
157 | 157 | 'entityId' => $context->getEntity()->getId()->getSerialization(), |
158 | 158 | 'statementGuid' => $context->getSnakStatement()->getGuid(), |
159 | 159 | 'resultStatus' => $result->getStatus(), |
160 | - 'resultParameters' => json_encode( $result->getParameters() ), |
|
160 | + 'resultParameters' => json_encode($result->getParameters()), |
|
161 | 161 | 'resultMessage' => $resultMessageKey, |
162 | 162 | ] |
163 | 163 | ); |
@@ -187,18 +187,18 @@ discard block |
||
187 | 187 | ); |
188 | 188 | |
189 | 189 | // find the longest limit (and associated log level) that the duration exceeds |
190 | - list( $limitSeconds, $logLevel ) = $this->findLimit( |
|
190 | + list($limitSeconds, $logLevel) = $this->findLimit( |
|
191 | 191 | $this->constraintCheckOnEntityDurationLimits, |
192 | 192 | $durationSeconds |
193 | 193 | ); |
194 | - if ( $limitSeconds === null ) { |
|
194 | + if ($limitSeconds === null) { |
|
195 | 195 | return; |
196 | 196 | } |
197 | 197 | |
198 | 198 | $this->logger->log( |
199 | 199 | $logLevel, |
200 | - 'Full constraint check on {entityId} ' . |
|
201 | - 'took longer than {limitSeconds} second(s) ' . |
|
200 | + 'Full constraint check on {entityId} '. |
|
201 | + 'took longer than {limitSeconds} second(s) '. |
|
202 | 202 | '(duration: {durationSeconds} seconds).', |
203 | 203 | [ |
204 | 204 | 'method' => $method, |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | * |
217 | 217 | * @param EntityId $entityId |
218 | 218 | */ |
219 | - public function logCheckConstraintsCacheHit( EntityId $entityId ) { |
|
219 | + public function logCheckConstraintsCacheHit(EntityId $entityId) { |
|
220 | 220 | $this->dataFactory->increment( |
221 | 221 | 'wikibase.quality.constraints.cache.entity.hit' |
222 | 222 | ); |
@@ -227,10 +227,10 @@ discard block |
||
227 | 227 | * |
228 | 228 | * @param EntityId[] $entityIds |
229 | 229 | */ |
230 | - public function logCheckConstraintsCacheMisses( array $entityIds ) { |
|
230 | + public function logCheckConstraintsCacheMisses(array $entityIds) { |
|
231 | 231 | $this->dataFactory->updateCount( |
232 | 232 | 'wikibase.quality.constraints.cache.entity.miss', |
233 | - count( $entityIds ) |
|
233 | + count($entityIds) |
|
234 | 234 | ); |
235 | 235 | } |
236 | 236 | |
@@ -257,17 +257,17 @@ discard block |
||
257 | 257 | * @param EntityId[] $entityIds |
258 | 258 | * @param int $maxRevisionIds |
259 | 259 | */ |
260 | - public function logHugeDependencyMetadata( array $entityIds, $maxRevisionIds ) { |
|
260 | + public function logHugeDependencyMetadata(array $entityIds, $maxRevisionIds) { |
|
261 | 261 | $this->logger->log( |
262 | 262 | 'warning', |
263 | - 'Dependency metadata for constraint check result has huge set of entity IDs ' . |
|
264 | - '(count ' . count( $entityIds ) . ', limit ' . $maxRevisionIds . '); ' . |
|
263 | + 'Dependency metadata for constraint check result has huge set of entity IDs '. |
|
264 | + '(count '.count($entityIds).', limit '.$maxRevisionIds.'); '. |
|
265 | 265 | 'caching disabled for this check result.', |
266 | 266 | [ |
267 | 267 | 'loggingMethod' => __METHOD__, |
268 | 268 | 'entityIds' => json_encode( |
269 | 269 | array_map( |
270 | - function ( EntityId $entityId ) { |
|
270 | + function(EntityId $entityId) { |
|
271 | 271 | return $entityId->getSerialization(); |
272 | 272 | }, |
273 | 273 | $entityIds |
@@ -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 | } |