Completed
Push — master ( b13dcc...ece800 )
by
unknown
50s
created
src/ServiceWiring-Wikibase.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -8,20 +8,20 @@
 block discarded – undo
8 8
 use Wikibase\Repo\WikibaseRepo;
9 9
 
10 10
 return [
11
-	WikibaseServices::ENTITY_LOOKUP => static function ( MediaWikiServices $services ) {
11
+	WikibaseServices::ENTITY_LOOKUP => static function(MediaWikiServices $services) {
12 12
 		return new ExceptionIgnoringEntityLookup(
13
-			WikibaseRepo::getEntityLookup( $services )
13
+			WikibaseRepo::getEntityLookup($services)
14 14
 		);
15 15
 	},
16 16
 
17
-	WikibaseServices::ENTITY_LOOKUP_WITHOUT_CACHE => static function ( MediaWikiServices $services ) {
17
+	WikibaseServices::ENTITY_LOOKUP_WITHOUT_CACHE => static function(MediaWikiServices $services) {
18 18
 		return new ExceptionIgnoringEntityLookup(
19
-			WikibaseRepo::getStore( $services )
20
-				->getEntityLookup( Store::LOOKUP_CACHING_RETRIEVE_ONLY )
19
+			WikibaseRepo::getStore($services)
20
+				->getEntityLookup(Store::LOOKUP_CACHING_RETRIEVE_ONLY)
21 21
 		);
22 22
 	},
23 23
 
24
-	WikibaseServices::PROPERTY_DATA_TYPE_LOOKUP => static function ( MediaWikiServices $services ) {
25
-		return WikibaseRepo::getPropertyDataTypeLookup( $services );
24
+	WikibaseServices::PROPERTY_DATA_TYPE_LOOKUP => static function(MediaWikiServices $services) {
25
+		return WikibaseRepo::getPropertyDataTypeLookup($services);
26 26
 	},
27 27
 ];
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/CommonsLinkChecker.php 1 patch
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare( strict_types = 1 );
3
+declare(strict_types=1);
4 4
 
5 5
 namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Checker;
6 6
 
@@ -77,26 +77,26 @@  discard block
 block discarded – undo
77 77
 	 * @return array first element is the namespace number (default namespace for TitleParser),
78 78
 	 * second element is a string to prepend to the title before giving it to the TitleParser
79 79
 	 */
80
-	private function getCommonsNamespace( string $namespace ): array {
81
-		switch ( $namespace ) {
80
+	private function getCommonsNamespace(string $namespace): array {
81
+		switch ($namespace) {
82 82
 			case '':
83
-				return [ NS_MAIN, '' ];
83
+				return [NS_MAIN, ''];
84 84
 			// extra namespaces, see operations/mediawiki-config.git,
85 85
 			// wmf-config/InitialiseSettings.php, 'wgExtraNamespaces' key, 'commonswiki' subkey
86 86
 			case 'Creator':
87
-				return [ 100, '' ];
87
+				return [100, ''];
88 88
 			case 'TimedText':
89
-				return [ 102, '' ];
89
+				return [102, ''];
90 90
 			case 'Sequence':
91
-				return [ 104, '' ];
91
+				return [104, ''];
92 92
 			case 'Institution':
93
-				return [ 106, '' ];
93
+				return [106, ''];
94 94
 			// extension namespace, see mediawiki/extensions/JsonConfig.git,
95 95
 			// extension.json, 'namespaces' key, third element
96 96
 			case 'Data':
97
-				return [ 486, '' ];
97
+				return [486, ''];
98 98
 			default:
99
-				return [ NS_MAIN, $namespace . ':' ];
99
+				return [NS_MAIN, $namespace.':'];
100 100
 		}
101 101
 	}
102 102
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 *
106 106
 	 * @throws ConstraintParameterException
107 107
 	 */
108
-	public function checkConstraint( Context $context, Constraint $constraint ): CheckResult {
108
+	public function checkConstraint(Context $context, Constraint $constraint): CheckResult {
109 109
 		$parameters = [];
110 110
 		$constraintParameters = $constraint->getConstraintParameters();
111 111
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
@@ -114,13 +114,13 @@  discard block
 block discarded – undo
114 114
 			$constraintParameters,
115 115
 			$constraintTypeItemId
116 116
 		);
117
-		$parameters['namespace'] = [ $namespace ];
117
+		$parameters['namespace'] = [$namespace];
118 118
 
119 119
 		$snak = $context->getSnak();
120 120
 
121
-		if ( !$snak instanceof PropertyValueSnak ) {
121
+		if (!$snak instanceof PropertyValueSnak) {
122 122
 			// nothing to check
123
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE );
123
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE);
124 124
 		}
125 125
 
126 126
 		$dataValue = $snak->getDataValue();
@@ -130,52 +130,52 @@  discard block
 block discarded – undo
130 130
 		 *   type of $dataValue for properties with 'Commons link' constraint has to be 'string'
131 131
 		 *   parameter $namespace can be null, works for commons galleries
132 132
 		 */
133
-		if ( $dataValue->getType() !== 'string' ) {
134
-			$message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) )
135
-				->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
136
-				->withDataValueType( 'string' );
137
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
133
+		if ($dataValue->getType() !== 'string') {
134
+			$message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type'))
135
+				->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
136
+				->withDataValueType('string');
137
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message);
138 138
 		}
139 139
 
140 140
 		$commonsLink = $dataValue->getValue();
141
-		if ( !$this->commonsLinkIsWellFormed( $commonsLink ) ) {
142
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION,
143
-				new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ) );
141
+		if (!$this->commonsLinkIsWellFormed($commonsLink)) {
142
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION,
143
+				new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed'));
144 144
 		}
145 145
 
146
-		$dataType = $this->propertyDatatypeLookup->getDataTypeIdForProperty( $snak->getPropertyId() );
147
-		switch ( $dataType ) {
146
+		$dataType = $this->propertyDatatypeLookup->getDataTypeIdForProperty($snak->getPropertyId());
147
+		switch ($dataType) {
148 148
 			case 'geo-shape':
149 149
 			case 'tabular-data':
150
-				if ( strpos( $commonsLink, $namespace . ':' ) !== 0 ) {
151
-					return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION,
152
-						new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ) );
150
+				if (strpos($commonsLink, $namespace.':') !== 0) {
151
+					return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION,
152
+						new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed'));
153 153
 				}
154 154
 				$pageName = $commonsLink;
155 155
 				break;
156 156
 			default:
157
-				$pageName = $namespace ? $namespace . ':' . $commonsLink : $commonsLink;
157
+				$pageName = $namespace ? $namespace.':'.$commonsLink : $commonsLink;
158 158
 				break;
159 159
 		}
160 160
 
161
-		$prefix = $this->getCommonsNamespace( $namespace )[1];
161
+		$prefix = $this->getCommonsNamespace($namespace)[1];
162 162
 		$normalizedTitle = $this->pageNameNormalizer->normalizePageName(
163 163
 			$pageName,
164 164
 			'https://commons.wikimedia.org/w/api.php'
165 165
 		);
166
-		if ( $normalizedTitle === false ) {
167
-			if ( $this->valueIncludesNamespace( $commonsLink, $namespace ) ) {
168
-				return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION,
169
-					new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ) );
166
+		if ($normalizedTitle === false) {
167
+			if ($this->valueIncludesNamespace($commonsLink, $namespace)) {
168
+				return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION,
169
+					new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed'));
170 170
 			}
171
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION,
172
-				new ViolationMessage( 'wbqc-violation-message-commons-link-no-existent' ) );
171
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION,
172
+				new ViolationMessage('wbqc-violation-message-commons-link-no-existent'));
173 173
 		}
174 174
 
175
-		return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, null );
175
+		return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, null);
176 176
 	}
177 177
 
178
-	public function checkConstraintParameters( Constraint $constraint ): array {
178
+	public function checkConstraintParameters(Constraint $constraint): array {
179 179
 		$constraintParameters = $constraint->getConstraintParameters();
180 180
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
181 181
 		$exceptions = [];
@@ -184,15 +184,15 @@  discard block
 block discarded – undo
184 184
 				$constraintParameters,
185 185
 				$constraintTypeItemId
186 186
 			);
187
-		} catch ( ConstraintParameterException $e ) {
187
+		} catch (ConstraintParameterException $e) {
188 188
 			$exceptions[] = $e;
189 189
 		}
190 190
 		return $exceptions;
191 191
 	}
192 192
 
193
-	private function commonsLinkIsWellFormed( string $commonsLink ): bool {
194
-		$toReplace = [ "_", "%20" ];
195
-		$compareString = trim( str_replace( $toReplace, '', $commonsLink ) );
193
+	private function commonsLinkIsWellFormed(string $commonsLink): bool {
194
+		$toReplace = ["_", "%20"];
195
+		$compareString = trim(str_replace($toReplace, '', $commonsLink));
196 196
 
197 197
 		return $commonsLink === $compareString;
198 198
 	}
@@ -201,9 +201,9 @@  discard block
 block discarded – undo
201 201
 	 * Checks whether the value of the statement already includes the namespace.
202 202
 	 * This special case should be reported as “malformed title” instead of “title does not exist”.
203 203
 	 */
204
-	private function valueIncludesNamespace( string $value, string $namespace ): bool {
204
+	private function valueIncludesNamespace(string $value, string $namespace): bool {
205 205
 		return $namespace !== '' &&
206
-			strncasecmp( $value, $namespace . ':', strlen( $namespace ) + 1 ) === 0;
206
+			strncasecmp($value, $namespace.':', strlen($namespace) + 1) === 0;
207 207
 	}
208 208
 
209 209
 }
Please login to merge, or discard this patch.
src/ConstraintCheck/Helper/TypeCheckerHelper.php 1 patch
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -80,26 +80,26 @@  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
 		$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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/Job/UpdateConstraintsTableJob.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -38,8 +38,8 @@  discard block
 block discarded – undo
38 38
 	 */
39 39
 	private const BATCH_SIZE = 50;
40 40
 
41
-	public static function newFromGlobalState( Title $title, array $params ) {
42
-		Assert::parameterType( 'string', $params['propertyId'], '$params["propertyId"]' );
41
+	public static function newFromGlobalState(Title $title, array $params) {
42
+		Assert::parameterType('string', $params['propertyId'], '$params["propertyId"]');
43 43
 		$services = MediaWikiServices::getInstance();
44 44
 		return new UpdateConstraintsTableJob(
45 45
 			$title,
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 			$services->getMainConfig(),
50 50
 			ConstraintsServices::getConstraintStore(),
51 51
 			$services->getDBLoadBalancerFactory(),
52
-			WikibaseRepo::getStore()->getEntityRevisionLookup( Store::LOOKUP_CACHING_DISABLED ),
53
-			WikibaseRepo::getBaseDataModelSerializerFactory( $services )
52
+			WikibaseRepo::getStore()->getEntityRevisionLookup(Store::LOOKUP_CACHING_DISABLED),
53
+			WikibaseRepo::getBaseDataModelSerializerFactory($services)
54 54
 				->newSnakSerializer()
55 55
 		);
56 56
 	}
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 		EntityRevisionLookup $entityRevisionLookup,
111 111
 		Serializer $snakSerializer
112 112
 	) {
113
-		parent::__construct( 'constraintsTableUpdate', $title, $params );
113
+		parent::__construct('constraintsTableUpdate', $title, $params);
114 114
 
115 115
 		$this->propertyId = $propertyId;
116 116
 		$this->revisionId = $revisionId;
@@ -121,11 +121,11 @@  discard block
 block discarded – undo
121 121
 		$this->snakSerializer = $snakSerializer;
122 122
 	}
123 123
 
124
-	public function extractParametersFromQualifiers( SnakList $qualifiers ) {
124
+	public function extractParametersFromQualifiers(SnakList $qualifiers) {
125 125
 		$parameters = [];
126
-		foreach ( $qualifiers as $qualifier ) {
126
+		foreach ($qualifiers as $qualifier) {
127 127
 			$qualifierId = $qualifier->getPropertyId()->getSerialization();
128
-			$paramSerialization = $this->snakSerializer->serialize( $qualifier );
128
+			$paramSerialization = $this->snakSerializer->serialize($qualifier);
129 129
 			$parameters[$qualifierId][] = $paramSerialization;
130 130
 		}
131 131
 		return $parameters;
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 		'@phan-var \Wikibase\DataModel\Entity\EntityIdValue $dataValue';
143 143
 		$entityId = $dataValue->getEntityId();
144 144
 		$constraintTypeQid = $entityId->getSerialization();
145
-		$parameters = $this->extractParametersFromQualifiers( $constraintStatement->getQualifiers() );
145
+		$parameters = $this->extractParametersFromQualifiers($constraintStatement->getQualifiers());
146 146
 		return new Constraint(
147 147
 			$constraintId,
148 148
 			$propertyId,
@@ -157,24 +157,24 @@  discard block
 block discarded – undo
157 157
 		PropertyId $propertyConstraintPropertyId
158 158
 	) {
159 159
 		$constraintsStatements = $property->getStatements()
160
-			->getByPropertyId( $propertyConstraintPropertyId )
161
-			->getByRank( [ Statement::RANK_PREFERRED, Statement::RANK_NORMAL ] );
160
+			->getByPropertyId($propertyConstraintPropertyId)
161
+			->getByRank([Statement::RANK_PREFERRED, Statement::RANK_NORMAL]);
162 162
 		$constraints = [];
163
-		foreach ( $constraintsStatements->getIterator() as $constraintStatement ) {
164
-			$constraints[] = $this->extractConstraintFromStatement( $property->getId(), $constraintStatement );
165
-			if ( count( $constraints ) >= self::BATCH_SIZE ) {
166
-				$constraintStore->insertBatch( $constraints );
163
+		foreach ($constraintsStatements->getIterator() as $constraintStatement) {
164
+			$constraints[] = $this->extractConstraintFromStatement($property->getId(), $constraintStatement);
165
+			if (count($constraints) >= self::BATCH_SIZE) {
166
+				$constraintStore->insertBatch($constraints);
167 167
 				// interrupt transaction and wait for replication
168
-				$connection = $this->lbFactory->getMainLB()->getConnection( DB_PRIMARY );
169
-				$connection->endAtomic( __CLASS__ );
170
-				if ( !$connection->explicitTrxActive() ) {
168
+				$connection = $this->lbFactory->getMainLB()->getConnection(DB_PRIMARY);
169
+				$connection->endAtomic(__CLASS__);
170
+				if (!$connection->explicitTrxActive()) {
171 171
 					$this->lbFactory->waitForReplication();
172 172
 				}
173
-				$connection->startAtomic( __CLASS__ );
173
+				$connection->startAtomic(__CLASS__);
174 174
 				$constraints = [];
175 175
 			}
176 176
 		}
177
-		$constraintStore->insertBatch( $constraints );
177
+		$constraintStore->insertBatch($constraints);
178 178
 	}
179 179
 
180 180
 	/**
@@ -185,24 +185,24 @@  discard block
 block discarded – undo
185 185
 	public function run() {
186 186
 		// TODO in the future: only touch constraints affected by the edit (requires T163465)
187 187
 
188
-		$propertyId = new PropertyId( $this->propertyId );
188
+		$propertyId = new PropertyId($this->propertyId);
189 189
 		$propertyRevision = $this->entityRevisionLookup->getEntityRevision(
190 190
 			$propertyId,
191 191
 			0, // latest
192 192
 			LookupConstants::LATEST_FROM_REPLICA
193 193
 		);
194 194
 
195
-		if ( $this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId ) {
196
-			JobQueueGroup::singleton()->push( $this );
195
+		if ($this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId) {
196
+			JobQueueGroup::singleton()->push($this);
197 197
 			return true;
198 198
 		}
199 199
 
200
-		$connection = $this->lbFactory->getMainLB()->getConnection( DB_PRIMARY );
200
+		$connection = $this->lbFactory->getMainLB()->getConnection(DB_PRIMARY);
201 201
 		// start transaction (if not started yet) – using __CLASS__, not __METHOD__,
202 202
 		// because importConstraintsForProperty() can interrupt the transaction
203
-		$connection->startAtomic( __CLASS__ );
203
+		$connection->startAtomic(__CLASS__);
204 204
 
205
-		$this->constraintStore->deleteForProperty( $propertyId );
205
+		$this->constraintStore->deleteForProperty($propertyId);
206 206
 
207 207
 		/** @var Property $property */
208 208
 		$property = $propertyRevision->getEntity();
@@ -210,10 +210,10 @@  discard block
 block discarded – undo
210 210
 		$this->importConstraintsForProperty(
211 211
 			$property,
212 212
 			$this->constraintStore,
213
-			new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) )
213
+			new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId'))
214 214
 		);
215 215
 
216
-		$connection->endAtomic( __CLASS__ );
216
+		$connection->endAtomic(__CLASS__);
217 217
 
218 218
 		return true;
219 219
 	}
Please login to merge, or discard this patch.
src/ConstraintRepositoryStore.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -24,16 +24,16 @@  discard block
 block discarded – undo
24 24
 	 * then using the main DBLoadBalancer service may be incorrect.
25 25
 	 * @param string|false $dbName Database name ($domain for ILoadBalancer methods).
26 26
 	 */
27
-	public function __construct( ILoadBalancer $lb, $dbName ) {
27
+	public function __construct(ILoadBalancer $lb, $dbName) {
28 28
 		$this->lb = $lb;
29 29
 		$this->dbName = $dbName;
30 30
 	}
31 31
 
32
-	private function encodeConstraintParameters( array $constraintParameters ) {
33
-		$json = json_encode( $constraintParameters, JSON_FORCE_OBJECT );
32
+	private function encodeConstraintParameters(array $constraintParameters) {
33
+		$json = json_encode($constraintParameters, JSON_FORCE_OBJECT);
34 34
 
35
-		if ( strlen( $json ) > 50000 ) {
36
-			$json = json_encode( [ '@error' => [ 'toolong' => true ] ] );
35
+		if (strlen($json) > 50000) {
36
+			$json = json_encode(['@error' => ['toolong' => true]]);
37 37
 		}
38 38
 
39 39
 		return $json;
@@ -45,21 +45,21 @@  discard block
 block discarded – undo
45 45
 	 * @throws DBUnexpectedError
46 46
 	 * @return bool
47 47
 	 */
48
-	public function insertBatch( array $constraints ) {
48
+	public function insertBatch(array $constraints) {
49 49
 		$accumulator = array_map(
50
-			function ( Constraint $constraint ) {
50
+			function(Constraint $constraint) {
51 51
 				return [
52 52
 					'constraint_guid' => $constraint->getConstraintId(),
53 53
 					'pid' => $constraint->getPropertyId()->getNumericId(),
54 54
 					'constraint_type_qid' => $constraint->getConstraintTypeItemId(),
55
-					'constraint_parameters' => $this->encodeConstraintParameters( $constraint->getConstraintParameters() )
55
+					'constraint_parameters' => $this->encodeConstraintParameters($constraint->getConstraintParameters())
56 56
 				];
57 57
 			},
58 58
 			$constraints
59 59
 		);
60 60
 
61
-		$dbw = $this->lb->getConnection( ILoadBalancer::DB_PRIMARY, [], $this->dbName );
62
-		return $dbw->insert( 'wbqc_constraints', $accumulator, __METHOD__ );
61
+		$dbw = $this->lb->getConnection(ILoadBalancer::DB_PRIMARY, [], $this->dbName);
62
+		return $dbw->insert('wbqc_constraints', $accumulator, __METHOD__);
63 63
 	}
64 64
 
65 65
 	/**
@@ -69,8 +69,8 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @throws DBUnexpectedError
71 71
 	 */
72
-	public function deleteForProperty( PropertyId $propertyId ) {
73
-		$dbw = $this->lb->getConnection( ILoadBalancer::DB_PRIMARY, [], $this->dbName );
72
+	public function deleteForProperty(PropertyId $propertyId) {
73
+		$dbw = $this->lb->getConnection(ILoadBalancer::DB_PRIMARY, [], $this->dbName);
74 74
 		$dbw->delete(
75 75
 			'wbqc_constraints',
76 76
 			[
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/FormatChecker.php 1 patch
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	 * @throws ConstraintParameterException
98 98
 	 * @return CheckResult
99 99
 	 */
100
-	public function checkConstraint( Context $context, Constraint $constraint ) {
100
+	public function checkConstraint(Context $context, Constraint $constraint) {
101 101
 		$parameters = [];
102 102
 		$constraintParameters = $constraint->getConstraintParameters();
103 103
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 			$constraintParameters,
107 107
 			$constraintTypeItemId
108 108
 		);
109
-		$parameters['pattern'] = [ $format ];
109
+		$parameters['pattern'] = [$format];
110 110
 
111 111
 		$syntaxClarifications = $this->constraintParameterParser->parseSyntaxClarificationParameter(
112 112
 			$constraintParameters
@@ -114,9 +114,9 @@  discard block
 block discarded – undo
114 114
 
115 115
 		$snak = $context->getSnak();
116 116
 
117
-		if ( !$snak instanceof PropertyValueSnak ) {
117
+		if (!$snak instanceof PropertyValueSnak) {
118 118
 			// nothing to check
119
-			return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE );
119
+			return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE);
120 120
 		}
121 121
 
122 122
 		$dataValue = $snak->getDataValue();
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 		 * error handling:
126 126
 		 *   type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext'
127 127
 		 */
128
-		switch ( $dataValue->getType() ) {
128
+		switch ($dataValue->getType()) {
129 129
 			case 'string':
130 130
 				$text = $dataValue->getValue();
131 131
 				break;
@@ -135,13 +135,13 @@  discard block
 block discarded – undo
135 135
 				$text = $dataValue->getText();
136 136
 				break;
137 137
 			default:
138
-				$message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-types-2' ) )
139
-					->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
140
-					->withDataValueType( 'string' )
141
-					->withDataValueType( 'monolingualtext' );
142
-				return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
138
+				$message = (new ViolationMessage('wbqc-violation-message-value-needed-of-types-2'))
139
+					->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
140
+					->withDataValueType('string')
141
+					->withDataValueType('monolingualtext');
142
+				return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message);
143 143
 		}
144
-		$status = $this->runRegexCheck( $text, $format );
144
+		$status = $this->runRegexCheck($text, $format);
145 145
 		$message = $this->formatMessage(
146 146
 			$status,
147 147
 			$text,
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 			$syntaxClarifications,
151 151
 			$constraintTypeItemId
152 152
 		);
153
-		return new CheckResult( $context, $constraint, $parameters, $status, $message );
153
+		return new CheckResult($context, $constraint, $parameters, $status, $message);
154 154
 	}
155 155
 
156 156
 	private function formatMessage(
@@ -162,74 +162,74 @@  discard block
 block discarded – undo
162 162
 		string $constraintTypeItemId
163 163
 	): ?ViolationMessage {
164 164
 		$message = null;
165
-		if ( $status === CheckResult::STATUS_VIOLATION ) {
166
-			$message = ( new ViolationMessage( 'wbqc-violation-message-format-clarification' ) )
167
-				->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY )
168
-				->withDataValue( new StringValue( $text ), Role::OBJECT )
169
-				->withInlineCode( $format, Role::CONSTRAINT_PARAMETER_VALUE )
170
-				->withMultilingualText( $syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE );
171
-		} elseif ( $status === CheckResult::STATUS_TODO ) {
172
-			$message = ( new ViolationMessage( 'wbqc-violation-message-security-reason' ) )
173
-				->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM );
165
+		if ($status === CheckResult::STATUS_VIOLATION) {
166
+			$message = (new ViolationMessage('wbqc-violation-message-format-clarification'))
167
+				->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY)
168
+				->withDataValue(new StringValue($text), Role::OBJECT)
169
+				->withInlineCode($format, Role::CONSTRAINT_PARAMETER_VALUE)
170
+				->withMultilingualText($syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE);
171
+		} elseif ($status === CheckResult::STATUS_TODO) {
172
+			$message = (new ViolationMessage('wbqc-violation-message-security-reason'))
173
+				->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM);
174 174
 		}
175 175
 
176 176
 		return $message;
177 177
 	}
178 178
 
179
-	private function runRegexCheck( string $text, string $format ): string {
180
-		if ( !$this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) ) {
179
+	private function runRegexCheck(string $text, string $format): string {
180
+		if (!$this->config->get('WBQualityConstraintsCheckFormatConstraint')) {
181 181
 			return CheckResult::STATUS_TODO;
182 182
 		}
183 183
 		if (
184
-			$this->config->get( 'WBQualityConstraintsFormatCheckerShellboxRatio' ) > (float)wfRandom()
184
+			$this->config->get('WBQualityConstraintsFormatCheckerShellboxRatio') > (float) wfRandom()
185 185
 		) {
186
-			return $this->runRegexCheckUsingShellbox( $text, $format );
186
+			return $this->runRegexCheckUsingShellbox($text, $format);
187 187
 		}
188 188
 
189
-		return $this->runRegexCheckUsingSparql( $text, $format );
189
+		return $this->runRegexCheckUsingSparql($text, $format);
190 190
 	}
191 191
 
192
-	private function runRegexCheckUsingShellbox( string $text, string $format ): string {
193
-		if ( !$this->shellboxClientFactory->isEnabled( 'constraint-regex-checker' ) ) {
192
+	private function runRegexCheckUsingShellbox(string $text, string $format): string {
193
+		if (!$this->shellboxClientFactory->isEnabled('constraint-regex-checker')) {
194 194
 			return CheckResult::STATUS_TODO;
195 195
 		}
196 196
 		try {
197
-			$pattern = '/^(?:' . str_replace( '/', '\/', $format ) . ')$/u';
198
-			$shellboxResponse = $this->shellboxClientFactory->getClient( [
199
-				'timeout' => $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' ) / 1000,
197
+			$pattern = '/^(?:'.str_replace('/', '\/', $format).')$/u';
198
+			$shellboxResponse = $this->shellboxClientFactory->getClient([
199
+				'timeout' => $this->config->get('WBQualityConstraintsSparqlMaxMillis') / 1000,
200 200
 				'service' => 'constraint-regex-checker',
201
-			] )->call(
201
+			])->call(
202 202
 				'constraint-regex-checker',
203 203
 				'preg_match',
204
-				[ $pattern, $text ]
204
+				[$pattern, $text]
205 205
 			);
206
-		} catch ( ShellboxError $exception ) {
206
+		} catch (ShellboxError $exception) {
207 207
 			throw new ConstraintParameterException(
208
-				( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) )
209
-					->withInlineCode( $pattern, Role::CONSTRAINT_PARAMETER_VALUE )
208
+				(new ViolationMessage('wbqc-violation-message-parameter-regex'))
209
+					->withInlineCode($pattern, Role::CONSTRAINT_PARAMETER_VALUE)
210 210
 			);
211 211
 		}
212 212
 
213
-		if ( $shellboxResponse ) {
213
+		if ($shellboxResponse) {
214 214
 			return CheckResult::STATUS_COMPLIANCE;
215 215
 		} else {
216 216
 			return CheckResult::STATUS_VIOLATION;
217 217
 		}
218 218
 	}
219 219
 
220
-	private function runRegexCheckUsingSparql( string $text, string $format ): string {
221
-		if ( $this->sparqlHelper instanceof DummySparqlHelper ) {
220
+	private function runRegexCheckUsingSparql(string $text, string $format): string {
221
+		if ($this->sparqlHelper instanceof DummySparqlHelper) {
222 222
 			return CheckResult::STATUS_TODO;
223 223
 		}
224 224
 
225
-		if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) {
225
+		if ($this->sparqlHelper->matchesRegularExpression($text, $format)) {
226 226
 			return CheckResult::STATUS_COMPLIANCE;
227 227
 		} else {
228 228
 			return CheckResult::STATUS_VIOLATION;
229 229
 		}
230 230
 	}
231 231
 
232
-	public function checkConstraintParameters( Constraint $constraint ) {
232
+	public function checkConstraintParameters(Constraint $constraint) {
233 233
 		$constraintParameters = $constraint->getConstraintParameters();
234 234
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
235 235
 		$exceptions = [];
@@ -238,14 +238,14 @@  discard block
 block discarded – undo
238 238
 				$constraintParameters,
239 239
 				$constraintTypeItemId
240 240
 			);
241
-		} catch ( ConstraintParameterException $e ) {
241
+		} catch (ConstraintParameterException $e) {
242 242
 			$exceptions[] = $e;
243 243
 		}
244 244
 		try {
245 245
 			$this->constraintParameterParser->parseSyntaxClarificationParameter(
246 246
 				$constraintParameters
247 247
 			);
248
-		} catch ( ConstraintParameterException $e ) {
248
+		} catch (ConstraintParameterException $e) {
249 249
 			$exceptions[] = $e;
250 250
 		}
251 251
 		return $exceptions;
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/Lexeme/LanguageChecker.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -84,9 +84,9 @@  discard block
 block discarded – undo
84 84
 	 * @throws ConstraintParameterException
85 85
 	 * @return CheckResult
86 86
 	 */
87
-	public function checkConstraint( Context $context, Constraint $constraint ) {
88
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
89
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED );
87
+	public function checkConstraint(Context $context, Constraint $constraint) {
88
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
89
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED);
90 90
 		}
91 91
 
92 92
 		$parameters = [];
@@ -100,50 +100,50 @@  discard block
 block discarded – undo
100 100
 		);
101 101
 		$parameters['languages'] = $languages;
102 102
 
103
-		$message = ( new ViolationMessage( 'wbqc-violation-message-language' ) )
104
-			->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE )
105
-			->withItemIdSnakValueList( $languages, Role::OBJECT );
103
+		$message = (new ViolationMessage('wbqc-violation-message-language'))
104
+			->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE)
105
+			->withItemIdSnakValueList($languages, Role::OBJECT);
106 106
 		$status = CheckResult::STATUS_VIOLATION;
107 107
 
108
-		$lexeme = $this->getLexeme( $context );
109
-		if ( !$lexeme ) {
108
+		$lexeme = $this->getLexeme($context);
109
+		if (!$lexeme) {
110 110
 			// Lexeme doesn't exist, let's not bother
111
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE );
111
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE);
112 112
 		}
113 113
 
114 114
 		/** @var Lexeme $lexeme */
115 115
 		'@phan-var Lexeme $lexeme';
116 116
 
117
-		foreach ( $languages as $language ) {
118
-			if ( $language->isNoValue() || $language->isSomeValue() ) {
117
+		foreach ($languages as $language) {
118
+			if ($language->isNoValue() || $language->isSomeValue()) {
119 119
 				continue;
120 120
 			}
121
-			if ( $lexeme->getLanguage()->equals( $language->getItemId() ) ) {
121
+			if ($lexeme->getLanguage()->equals($language->getItemId())) {
122 122
 				$message = null;
123 123
 				$status = CheckResult::STATUS_COMPLIANCE;
124 124
 				break;
125 125
 			}
126 126
 		}
127 127
 
128
-		return new CheckResult( $context, $constraint, $parameters, $status, $message );
128
+		return new CheckResult($context, $constraint, $parameters, $status, $message);
129 129
 	}
130 130
 
131
-	private function getLexeme( Context $context ): ?EntityDocument {
131
+	private function getLexeme(Context $context): ?EntityDocument {
132 132
 		$entityType = $context->getEntity()->getType();
133 133
 
134
-		if ( $entityType === Lexeme::ENTITY_TYPE ) {
134
+		if ($entityType === Lexeme::ENTITY_TYPE) {
135 135
 			return $context->getEntity();
136 136
 		}
137 137
 
138
-		if ( in_array( $entityType, [ Form::ENTITY_TYPE, Sense::ENTITY_TYPE ] ) ) {
138
+		if (in_array($entityType, [Form::ENTITY_TYPE, Sense::ENTITY_TYPE])) {
139 139
 			/** @var LexemeSubEntityId $id */
140 140
 			$id = $context->getEntity()->getId();
141 141
 			'@phan-var LexemeSubEntityId $id';
142
-			return $this->entityLookup->getEntity( $id->getLexemeId() );
142
+			return $this->entityLookup->getEntity($id->getLexemeId());
143 143
 		}
144 144
 	}
145 145
 
146
-	public function checkConstraintParameters( Constraint $constraint ): array {
146
+	public function checkConstraintParameters(Constraint $constraint): array {
147 147
 		$constraintParameters = $constraint->getConstraintParameters();
148 148
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
149 149
 		$exceptions = [];
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 				$constraintTypeItemId,
154 154
 				true
155 155
 			);
156
-		} catch ( ConstraintParameterException $e ) {
156
+		} catch (ConstraintParameterException $e) {
157 157
 			$exceptions[] = $e;
158 158
 		}
159 159
 		return $exceptions;
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/PropertyScopeChecker.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 		return self::ALL_ENTITY_TYPES_SUPPORTED;
55 55
 	}
56 56
 
57
-	public function checkConstraint( Context $context, Constraint $constraint ) {
57
+	public function checkConstraint(Context $context, Constraint $constraint) {
58 58
 		$constraintParameters = $constraint->getConstraintParameters();
59 59
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
60 60
 
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 			$constraintTypeItemId
64 64
 		);
65 65
 
66
-		if ( in_array( $context->getType(), $allowedContextTypes ) ) {
66
+		if (in_array($context->getType(), $allowedContextTypes)) {
67 67
 			return new CheckResult(
68 68
 				$context->getCursor(),
69 69
 				$constraint,
@@ -76,15 +76,15 @@  discard block
 block discarded – undo
76 76
 				$constraint,
77 77
 				[],
78 78
 				CheckResult::STATUS_VIOLATION,
79
-				( new ViolationMessage( 'wbqc-violation-message-property-scope' ) )
80
-					->withEntityId( $context->getSnak()->getPropertyId() )
81
-					->withPropertyScope( $context->getType() )
82
-					->withPropertyScopeList( $allowedContextTypes )
79
+				(new ViolationMessage('wbqc-violation-message-property-scope'))
80
+					->withEntityId($context->getSnak()->getPropertyId())
81
+					->withPropertyScope($context->getType())
82
+					->withPropertyScopeList($allowedContextTypes)
83 83
 			);
84 84
 		}
85 85
 	}
86 86
 
87
-	public function checkConstraintParameters( Constraint $constraint ) {
87
+	public function checkConstraintParameters(Constraint $constraint) {
88 88
 		$constraintParameters = $constraint->getConstraintParameters();
89 89
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
90 90
 		$exceptions = [];
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 				$constraintParameters,
94 94
 				$constraintTypeItemId
95 95
 			);
96
-		} catch ( ConstraintParameterException $e ) {
96
+		} catch (ConstraintParameterException $e) {
97 97
 			$exceptions[] = $e;
98 98
 		}
99 99
 		return $exceptions;
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/ContemporaryChecker.php 1 patch
Spacing   +42 added lines, -43 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	 * @codeCoverageIgnore This method is purely declarative.
80 80
 	 */
81 81
 	public function getDefaultContextTypes() {
82
-		return [ Context::TYPE_STATEMENT ];
82
+		return [Context::TYPE_STATEMENT];
83 83
 	}
84 84
 
85 85
 	/** @codeCoverageIgnore This method is purely declarative. */
@@ -96,31 +96,31 @@  discard block
 block discarded – undo
96 96
 	 * @return CheckResult
97 97
 	 * @throws \ConfigException
98 98
 	 */
99
-	public function checkConstraint( Context $context, Constraint $constraint ) {
100
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
101
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED );
99
+	public function checkConstraint(Context $context, Constraint $constraint) {
100
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
101
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED);
102 102
 		}
103 103
 		$snak = $context->getSnak();
104
-		if ( !$snak instanceof PropertyValueSnak ) {
104
+		if (!$snak instanceof PropertyValueSnak) {
105 105
 			// nothing to check
106
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE );
106
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE);
107 107
 		}
108 108
 
109 109
 		$dataValue = $snak->getDataValue();
110
-		if ( !$dataValue instanceof EntityIdValue ) {
110
+		if (!$dataValue instanceof EntityIdValue) {
111 111
 			// wrong data type
112
-			$message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) )
113
-				->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM )
114
-				->withDataValueType( 'wikibase-entityid' );
115
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message );
112
+			$message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type'))
113
+				->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM)
114
+				->withDataValueType('wikibase-entityid');
115
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message);
116 116
 		}
117 117
 
118 118
 		$objectId = $dataValue->getEntityId();
119
-		$objectItem = $this->entityLookup->getEntity( $objectId );
120
-		if ( !( $objectItem instanceof StatementListProvider ) ) {
119
+		$objectItem = $this->entityLookup->getEntity($objectId);
120
+		if (!($objectItem instanceof StatementListProvider)) {
121 121
 			// object was deleted/doesn't exist
122
-			$message = new ViolationMessage( 'wbqc-violation-message-value-entity-must-exist' );
123
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message );
122
+			$message = new ViolationMessage('wbqc-violation-message-value-entity-must-exist');
123
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message);
124 124
 		}
125 125
 		/** @var Statement[] $objectStatements */
126 126
 		$objectStatements = $objectItem->getStatements()->toArray();
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
 		$subjectId = $context->getEntity()->getId();
129 129
 		$subjectStatements = $context->getEntity()->getStatements()->toArray();
130 130
 		/** @var String[] $startPropertyIds */
131
-		$startPropertyIds = $this->config->get( self::CONFIG_VARIABLE_START_PROPERTY_IDS );
131
+		$startPropertyIds = $this->config->get(self::CONFIG_VARIABLE_START_PROPERTY_IDS);
132 132
 		/** @var String[] $endPropertyIds */
133
-		$endPropertyIds = $this->config->get( self::CONFIG_VARIABLE_END_PROPERTY_IDS );
133
+		$endPropertyIds = $this->config->get(self::CONFIG_VARIABLE_END_PROPERTY_IDS);
134 134
 		$subjectStartValue = $this->getExtremeValue(
135 135
 			$startPropertyIds,
136 136
 			$subjectStatements,
@@ -152,15 +152,15 @@  discard block
 block discarded – undo
152 152
 			'end'
153 153
 		);
154 154
 		if (
155
-			$this->rangeCheckerHelper->getComparison( $subjectStartValue, $subjectEndValue ) <= 0 &&
156
-			$this->rangeCheckerHelper->getComparison( $objectStartValue, $objectEndValue ) <= 0 && (
157
-				$this->rangeCheckerHelper->getComparison( $subjectEndValue, $objectStartValue ) < 0 ||
158
-				$this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectStartValue ) < 0
155
+			$this->rangeCheckerHelper->getComparison($subjectStartValue, $subjectEndValue) <= 0 &&
156
+			$this->rangeCheckerHelper->getComparison($objectStartValue, $objectEndValue) <= 0 && (
157
+				$this->rangeCheckerHelper->getComparison($subjectEndValue, $objectStartValue) < 0 ||
158
+				$this->rangeCheckerHelper->getComparison($objectEndValue, $subjectStartValue) < 0
159 159
 			)
160 160
 		) {
161 161
 			if (
162 162
 				$subjectEndValue == null ||
163
-				$this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectEndValue ) < 0
163
+				$this->rangeCheckerHelper->getComparison($objectEndValue, $subjectEndValue) < 0
164 164
 			) {
165 165
 				$earlierEntityId = $objectId;
166 166
 				$minEndValue = $objectEndValue;
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 			$message = null;
184 184
 			$status = CheckResult::STATUS_COMPLIANCE;
185 185
 		}
186
-		return new CheckResult( $context, $constraint, [], $status, $message );
186
+		return new CheckResult($context, $constraint, [], $status, $message);
187 187
 	}
188 188
 
189 189
 	/**
@@ -193,19 +193,19 @@  discard block
 block discarded – undo
193 193
 	 *
194 194
 	 * @return DataValue|null
195 195
 	 */
196
-	private function getExtremeValue( $extremePropertyIds, $statements, $startOrEnd ) {
197
-		if ( $startOrEnd !== 'start' && $startOrEnd !== 'end' ) {
198
-			throw new \InvalidArgumentException( '$startOrEnd must be \'start\' or \'end\'.' );
196
+	private function getExtremeValue($extremePropertyIds, $statements, $startOrEnd) {
197
+		if ($startOrEnd !== 'start' && $startOrEnd !== 'end') {
198
+			throw new \InvalidArgumentException('$startOrEnd must be \'start\' or \'end\'.');
199 199
 		}
200 200
 		$extremeValue = null;
201
-		foreach ( $extremePropertyIds as $extremePropertyId ) {
202
-			$statementList = new StatementList( ...$statements );
203
-			$extremeStatements = $statementList->getByPropertyId( new PropertyId( $extremePropertyId ) );
201
+		foreach ($extremePropertyIds as $extremePropertyId) {
202
+			$statementList = new StatementList(...$statements);
203
+			$extremeStatements = $statementList->getByPropertyId(new PropertyId($extremePropertyId));
204 204
 			/** @var Statement $extremeStatement */
205
-			foreach ( $extremeStatements as $extremeStatement ) {
206
-				if ( $extremeStatement->getRank() !== Statement::RANK_DEPRECATED ) {
205
+			foreach ($extremeStatements as $extremeStatement) {
206
+				if ($extremeStatement->getRank() !== Statement::RANK_DEPRECATED) {
207 207
 					$snak = $extremeStatement->getMainSnak();
208
-					if ( !$snak instanceof PropertyValueSnak ) {
208
+					if (!$snak instanceof PropertyValueSnak) {
209 209
 						return null;
210 210
 					} else {
211 211
 						$comparison = $this->rangeCheckerHelper->getComparison(
@@ -214,8 +214,8 @@  discard block
 block discarded – undo
214 214
 						);
215 215
 						if (
216 216
 							$extremeValue === null ||
217
-							( $startOrEnd === 'start' && $comparison < 0 ) ||
218
-							( $startOrEnd === 'end' && $comparison > 0 )
217
+							($startOrEnd === 'start' && $comparison < 0) ||
218
+							($startOrEnd === 'end' && $comparison > 0)
219 219
 						) {
220 220
 							$extremeValue = $snak->getDataValue();
221 221
 						}
@@ -245,17 +245,16 @@  discard block
 block discarded – undo
245 245
 		DataValue $maxStartValue
246 246
 	) {
247 247
 		$messageKey = $earlierEntityId === $subjectId ?
248
-			'wbqc-violation-message-contemporary-subject-earlier' :
249
-			'wbqc-violation-message-contemporary-value-earlier';
250
-		return ( new ViolationMessage( $messageKey ) )
251
-			->withEntityId( $subjectId, Role::SUBJECT )
252
-			->withEntityId( $propertyId, Role::PREDICATE )
253
-			->withEntityId( $objectId, Role::OBJECT )
254
-			->withDataValue( $minEndValue, Role::OBJECT )
255
-			->withDataValue( $maxStartValue, Role::OBJECT );
248
+			'wbqc-violation-message-contemporary-subject-earlier' : 'wbqc-violation-message-contemporary-value-earlier';
249
+		return (new ViolationMessage($messageKey))
250
+			->withEntityId($subjectId, Role::SUBJECT)
251
+			->withEntityId($propertyId, Role::PREDICATE)
252
+			->withEntityId($objectId, Role::OBJECT)
253
+			->withDataValue($minEndValue, Role::OBJECT)
254
+			->withDataValue($maxStartValue, Role::OBJECT);
256 255
 	}
257 256
 
258
-	public function checkConstraintParameters( Constraint $constraint ) {
257
+	public function checkConstraintParameters(Constraint $constraint) {
259 258
 		// no parameters
260 259
 		return [];
261 260
 	}
Please login to merge, or discard this patch.