Completed
Push — master ( 259f04...bf13aa )
by
unknown
02:02
created
src/ConstraintCheck/Helper/TypeCheckerHelper.php 1 patch
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -80,24 +80,24 @@  discard block
 block discarded – undo
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 ) ||
100
-				$statement->getRank() === Statement::RANK_DEPRECATED ) {
99
+			if (!$this->hasCorrectType($mainSnak) ||
100
+				$statement->getRank() === Statement::RANK_DEPRECATED) {
101 101
 				continue;
102 102
 			}
103 103
 			/** @var PropertyValueSnak $mainSnak */
@@ -107,11 +107,11 @@  discard block
 block discarded – undo
107 107
 			'@phan-var EntityIdValue $dataValue';
108 108
 			$comparativeClass = $dataValue->getEntityId();
109 109
 
110
-			if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) {
110
+			if (in_array($comparativeClass->getSerialization(), $classesToCheck)) {
111 111
 				return true;
112 112
 			}
113 113
 
114
-			if ( $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ) ) {
114
+			if ($this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked)) {
115 115
 				return true;
116 116
 			}
117 117
 		}
@@ -132,48 +132,48 @@  discard block
 block discarded – undo
132 132
 	 * @return CachedBool
133 133
 	 * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs
134 134
 	 */
135
-	public function isSubclassOfWithSparqlFallback( EntityId $comparativeClass, array $classesToCheck ) {
135
+	public function isSubclassOfWithSparqlFallback(EntityId $comparativeClass, array $classesToCheck) {
136 136
 		try {
137 137
 			$entitiesChecked = 0;
138
-			$start1 = microtime( true );
139
-			$isSubclass = $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked );
140
-			$end1 = microtime( true );
138
+			$start1 = microtime(true);
139
+			$isSubclass = $this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked);
140
+			$end1 = microtime(true);
141 141
 			$this->dataFactory->timing(
142 142
 				'wikibase.quality.constraints.type.php.success.timing',
143
-				( $end1 - $start1 ) * 1000
143
+				($end1 - $start1) * 1000
144 144
 			);
145 145
 			$this->dataFactory->timing( // not really a timing, but works like one (we want percentiles etc.)
146 146
 				'wikibase.quality.constraints.type.php.success.entities',
147 147
 				$entitiesChecked
148 148
 			);
149 149
 
150
-			return new CachedBool( $isSubclass, Metadata::blank() );
151
-		} catch ( OverflowException $e ) {
152
-			$end1 = microtime( true );
150
+			return new CachedBool($isSubclass, Metadata::blank());
151
+		} catch (OverflowException $e) {
152
+			$end1 = microtime(true);
153 153
 			$this->dataFactory->timing(
154 154
 				'wikibase.quality.constraints.type.php.overflow.timing',
155
-				( $end1 - $start1 ) * 1000
155
+				($end1 - $start1) * 1000
156 156
 			);
157 157
 
158
-			if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) {
158
+			if (!($this->sparqlHelper instanceof DummySparqlHelper)) {
159 159
 				$this->dataFactory->increment(
160 160
 					'wikibase.quality.constraints.sparql.typeFallback'
161 161
 				);
162 162
 
163
-				$start2 = microtime( true );
163
+				$start2 = microtime(true);
164 164
 				$hasType = $this->sparqlHelper->hasType(
165 165
 					$comparativeClass->getSerialization(),
166 166
 					$classesToCheck
167 167
 				);
168
-				$end2 = microtime( true );
168
+				$end2 = microtime(true);
169 169
 				$this->dataFactory->timing(
170 170
 					'wikibase.quality.constraints.type.sparql.success.timing',
171
-					( $end2 - $start2 ) * 1000
171
+					($end2 - $start2) * 1000
172 172
 				);
173 173
 
174 174
 				return $hasType;
175 175
 			} else {
176
-				return new CachedBool( false, Metadata::blank() );
176
+				return new CachedBool(false, Metadata::blank());
177 177
 			}
178 178
 		}
179 179
 	}
@@ -191,14 +191,14 @@  discard block
 block discarded – undo
191 191
 	 * @return CachedBool
192 192
 	 * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs
193 193
 	 */
194
-	public function hasClassInRelation( StatementList $statements, array $relationIds, array $classesToCheck ) {
194
+	public function hasClassInRelation(StatementList $statements, array $relationIds, array $classesToCheck) {
195 195
 		$metadatas = [];
196 196
 
197
-		foreach ( $this->getStatementsByPropertyIds( $statements, $relationIds ) as $statement ) {
197
+		foreach ($this->getStatementsByPropertyIds($statements, $relationIds) as $statement) {
198 198
 			$mainSnak = $statement->getMainSnak();
199 199
 
200
-			if ( !$this->hasCorrectType( $mainSnak ) ||
201
-				$statement->getRank() === Statement::RANK_DEPRECATED ) {
200
+			if (!$this->hasCorrectType($mainSnak) ||
201
+				$statement->getRank() === Statement::RANK_DEPRECATED) {
202 202
 				continue;
203 203
 			}
204 204
 			/** @var PropertyValueSnak $mainSnak */
@@ -208,24 +208,24 @@  discard block
 block discarded – undo
208 208
 			'@phan-var EntityIdValue $dataValue';
209 209
 			$comparativeClass = $dataValue->getEntityId();
210 210
 
211
-			if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) {
211
+			if (in_array($comparativeClass->getSerialization(), $classesToCheck)) {
212 212
 				// discard $metadatas, we know this is fresh
213
-				return new CachedBool( true, Metadata::blank() );
213
+				return new CachedBool(true, Metadata::blank());
214 214
 			}
215 215
 
216
-			$result = $this->isSubclassOfWithSparqlFallback( $comparativeClass, $classesToCheck );
216
+			$result = $this->isSubclassOfWithSparqlFallback($comparativeClass, $classesToCheck);
217 217
 			$metadatas[] = $result->getMetadata();
218
-			if ( $result->getBool() ) {
218
+			if ($result->getBool()) {
219 219
 				return new CachedBool(
220 220
 					true,
221
-					Metadata::merge( $metadatas )
221
+					Metadata::merge($metadatas)
222 222
 				);
223 223
 			}
224 224
 		}
225 225
 
226 226
 		return new CachedBool(
227 227
 			false,
228
-			Metadata::merge( $metadatas )
228
+			Metadata::merge($metadatas)
229 229
 		);
230 230
 	}
231 231
 
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 	 * @return bool
235 235
 	 * @phan-assert PropertyValueSnak $mainSnak
236 236
 	 */
237
-	private function hasCorrectType( Snak $mainSnak ) {
237
+	private function hasCorrectType(Snak $mainSnak) {
238 238
 		return $mainSnak instanceof PropertyValueSnak
239 239
 			&& $mainSnak->getDataValue()->getType() === 'wikibase-entityid';
240 240
 	}
@@ -251,12 +251,12 @@  discard block
 block discarded – undo
251 251
 	) {
252 252
 		$statementArrays = [];
253 253
 
254
-		foreach ( $propertyIdSerializations as $propertyIdSerialization ) {
255
-			$propertyId = new PropertyId( $propertyIdSerialization );
256
-			$statementArrays[] = $statements->getByPropertyId( $propertyId )->toArray();
254
+		foreach ($propertyIdSerializations as $propertyIdSerialization) {
255
+			$propertyId = new PropertyId($propertyIdSerialization);
256
+			$statementArrays[] = $statements->getByPropertyId($propertyId)->toArray();
257 257
 		}
258 258
 
259
-		return call_user_func_array( 'array_merge', $statementArrays );
259
+		return call_user_func_array('array_merge', $statementArrays);
260 260
 	}
261 261
 
262 262
 	/**
@@ -268,10 +268,10 @@  discard block
 block discarded – undo
268 268
 	 *
269 269
 	 * @return ViolationMessage
270 270
 	 */
271
-	public function getViolationMessage( PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation ) {
271
+	public function getViolationMessage(PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation) {
272 272
 		$classes = array_map(
273
-			function ( $itemIdSerialization ) {
274
-				return new ItemId( $itemIdSerialization );
273
+			function($itemIdSerialization) {
274
+				return new ItemId($itemIdSerialization);
275 275
 			},
276 276
 			$classes
277 277
 		);
@@ -283,10 +283,10 @@  discard block
 block discarded – undo
283 283
 		// wbqc-violation-message-valueType-instance
284 284
 		// wbqc-violation-message-valueType-subclass
285 285
 		// wbqc-violation-message-valueType-instanceOrSubclass
286
-		return ( new ViolationMessage( 'wbqc-violation-message-' . $checker . '-' . $relation ) )
287
-			->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY )
288
-			->withEntityId( $entityId, Role::SUBJECT )
289
-			->withEntityIdList( $classes, Role::OBJECT );
286
+		return (new ViolationMessage('wbqc-violation-message-'.$checker.'-'.$relation))
287
+			->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY)
288
+			->withEntityId($entityId, Role::SUBJECT)
289
+			->withEntityIdList($classes, Role::OBJECT);
290 290
 	}
291 291
 
292 292
 }
Please login to merge, or discard this patch.