Completed
Push — master ( bfc2d5...959f5f )
by
unknown
02:07
created
src/ConstraintCheck/Helper/TypeCheckerHelper.php 1 patch
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -80,23 +80,23 @@  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 ) ) ) {
99
+			if (!($this->hasCorrectType($mainSnak))) {
100 100
 				continue;
101 101
 			}
102 102
 			/** @var PropertyValueSnak $mainSnak */
@@ -105,11 +105,11 @@  discard block
 block discarded – undo
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,48 +130,48 @@  discard block
 block discarded – undo
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 135
 			$entitiesChecked = 0;
136
-			$start1 = microtime( true );
137
-			$isSubclass = $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked );
138
-			$end1 = microtime( true );
136
+			$start1 = microtime(true);
137
+			$isSubclass = $this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked);
138
+			$end1 = microtime(true);
139 139
 			$this->dataFactory->timing(
140 140
 				'wikibase.quality.constraints.type.php.success.timing',
141
-				( $end1 - $start1 ) * 1000
141
+				($end1 - $start1) * 1000
142 142
 			);
143 143
 			$this->dataFactory->timing( // not really a timing, but works like one (we want percentiles etc.)
144 144
 				'wikibase.quality.constraints.type.php.success.entities',
145 145
 				$entitiesChecked
146 146
 			);
147 147
 
148
-			return new CachedBool( $isSubclass, Metadata::blank() );
149
-		} catch ( OverflowException $e ) {
150
-			$end1 = microtime( true );
148
+			return new CachedBool($isSubclass, Metadata::blank());
149
+		} catch (OverflowException $e) {
150
+			$end1 = microtime(true);
151 151
 			$this->dataFactory->timing(
152 152
 				'wikibase.quality.constraints.type.php.overflow.timing',
153
-				( $end1 - $start1 ) * 1000
153
+				($end1 - $start1) * 1000
154 154
 			);
155 155
 
156
-			if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) {
156
+			if (!($this->sparqlHelper instanceof DummySparqlHelper)) {
157 157
 				$this->dataFactory->increment(
158 158
 					'wikibase.quality.constraints.sparql.typeFallback'
159 159
 				);
160 160
 
161
-				$start2 = microtime( true );
161
+				$start2 = microtime(true);
162 162
 				$hasType = $this->sparqlHelper->hasType(
163 163
 					$comparativeClass->getSerialization(),
164 164
 					$classesToCheck
165 165
 				);
166
-				$end2 = microtime( true );
166
+				$end2 = microtime(true);
167 167
 				$this->dataFactory->timing(
168 168
 					'wikibase.quality.constraints.type.sparql.success.timing',
169
-					( $end2 - $start2 ) * 1000
169
+					($end2 - $start2) * 1000
170 170
 				);
171 171
 
172 172
 				return $hasType;
173 173
 			} else {
174
-				return new CachedBool( false, Metadata::blank() );
174
+				return new CachedBool(false, Metadata::blank());
175 175
 			}
176 176
 		}
177 177
 	}
@@ -189,13 +189,13 @@  discard block
 block discarded – undo
189 189
 	 * @return CachedBool
190 190
 	 * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs
191 191
 	 */
192
-	public function hasClassInRelation( StatementList $statements, array $relationIds, array $classesToCheck ) {
192
+	public function hasClassInRelation(StatementList $statements, array $relationIds, array $classesToCheck) {
193 193
 		$metadatas = [];
194 194
 
195
-		foreach ( $this->getStatementsByPropertyIds( $statements, $relationIds ) as $statement ) {
195
+		foreach ($this->getStatementsByPropertyIds($statements, $relationIds) as $statement) {
196 196
 			$mainSnak = $statement->getMainSnak();
197 197
 
198
-			if ( !$this->hasCorrectType( $mainSnak ) ) {
198
+			if (!$this->hasCorrectType($mainSnak)) {
199 199
 				continue;
200 200
 			}
201 201
 			/** @var PropertyValueSnak $mainSnak */
@@ -204,28 +204,28 @@  discard block
 block discarded – undo
204 204
 			$dataValue = $mainSnak->getDataValue();
205 205
 			$comparativeClass = $dataValue->getEntityId();
206 206
 
207
-			if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) {
207
+			if (in_array($comparativeClass->getSerialization(), $classesToCheck)) {
208 208
 				// discard $metadatas, we know this is fresh
209
-				return new CachedBool( true, Metadata::blank() );
209
+				return new CachedBool(true, Metadata::blank());
210 210
 			}
211 211
 
212
-			$result = $this->isSubclassOfWithSparqlFallback( $comparativeClass, $classesToCheck );
212
+			$result = $this->isSubclassOfWithSparqlFallback($comparativeClass, $classesToCheck);
213 213
 			$metadatas[] = $result->getMetadata();
214
-			if ( $result->getBool() ) {
214
+			if ($result->getBool()) {
215 215
 				return new CachedBool(
216 216
 					true,
217
-					Metadata::merge( $metadatas )
217
+					Metadata::merge($metadatas)
218 218
 				);
219 219
 			}
220 220
 		}
221 221
 
222 222
 		return new CachedBool(
223 223
 			false,
224
-			Metadata::merge( $metadatas )
224
+			Metadata::merge($metadatas)
225 225
 		);
226 226
 	}
227 227
 
228
-	private function hasCorrectType( Snak $mainSnak ) {
228
+	private function hasCorrectType(Snak $mainSnak) {
229 229
 		return $mainSnak instanceof PropertyValueSnak
230 230
 			&& $mainSnak->getDataValue()->getType() === 'wikibase-entityid';
231 231
 	}
@@ -242,12 +242,12 @@  discard block
 block discarded – undo
242 242
 	) {
243 243
 		$statementArrays = [];
244 244
 
245
-		foreach ( $propertyIdSerializations as $propertyIdSerialization ) {
246
-			$propertyId = new PropertyId( $propertyIdSerialization );
247
-			$statementArrays[] = $statements->getByPropertyId( $propertyId )->toArray();
245
+		foreach ($propertyIdSerializations as $propertyIdSerialization) {
246
+			$propertyId = new PropertyId($propertyIdSerialization);
247
+			$statementArrays[] = $statements->getByPropertyId($propertyId)->toArray();
248 248
 		}
249 249
 
250
-		return call_user_func_array( 'array_merge', $statementArrays );
250
+		return call_user_func_array('array_merge', $statementArrays);
251 251
 	}
252 252
 
253 253
 	/**
@@ -259,10 +259,10 @@  discard block
 block discarded – undo
259 259
 	 *
260 260
 	 * @return ViolationMessage
261 261
 	 */
262
-	public function getViolationMessage( PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation ) {
262
+	public function getViolationMessage(PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation) {
263 263
 		$classes = array_map(
264
-			function( $itemIdSerialization ) {
265
-				return new ItemId( $itemIdSerialization );
264
+			function($itemIdSerialization) {
265
+				return new ItemId($itemIdSerialization);
266 266
 			},
267 267
 			$classes
268 268
 		);
@@ -274,10 +274,10 @@  discard block
 block discarded – undo
274 274
 		// wbqc-violation-message-valueType-instance
275 275
 		// wbqc-violation-message-valueType-subclass
276 276
 		// wbqc-violation-message-valueType-instanceOrSubclass
277
-		return ( new ViolationMessage( 'wbqc-violation-message-' . $checker . '-' . $relation ) )
278
-			->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY )
279
-			->withEntityId( $entityId, Role::SUBJECT )
280
-			->withEntityIdList( $classes, Role::OBJECT );
277
+		return (new ViolationMessage('wbqc-violation-message-'.$checker.'-'.$relation))
278
+			->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY)
279
+			->withEntityId($entityId, Role::SUBJECT)
280
+			->withEntityIdList($classes, Role::OBJECT);
281 281
 	}
282 282
 
283 283
 }
Please login to merge, or discard this patch.