Completed
Push — master ( 7e1e37...c165cf )
by
unknown
36s queued 13s
created
src/ConstraintCheck/Checker/QualifierChecker.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -44,16 +44,16 @@
 block discarded – undo
44 44
 	 *
45 45
 	 * @return CheckResult
46 46
 	 */
47
-	public function checkConstraint( Context $context, Constraint $constraint ): CheckResult {
48
-		if ( $context->getType() === Context::TYPE_QUALIFIER ) {
49
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE );
47
+	public function checkConstraint(Context $context, Constraint $constraint): CheckResult {
48
+		if ($context->getType() === Context::TYPE_QUALIFIER) {
49
+			return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE);
50 50
 		} else {
51
-			$message = new ViolationMessage( 'wbqc-violation-message-qualifier' );
52
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message );
51
+			$message = new ViolationMessage('wbqc-violation-message-qualifier');
52
+			return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message);
53 53
 		}
54 54
 	}
55 55
 
56
-	public function checkConstraintParameters( Constraint $constraint ): array {
56
+	public function checkConstraintParameters(Constraint $constraint): array {
57 57
 		// no parameters
58 58
 		return [];
59 59
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/OneOfChecker.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 * @throws ConstraintParameterException
58 58
 	 * @return CheckResult
59 59
 	 */
60
-	public function checkConstraint( Context $context, Constraint $constraint ): CheckResult {
61
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
62
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED );
60
+	public function checkConstraint(Context $context, Constraint $constraint): CheckResult {
61
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
62
+			return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED);
63 63
 		}
64 64
 
65 65
 		$constraintParameters = $constraint->getConstraintParameters();
@@ -73,23 +73,23 @@  discard block
 block discarded – undo
73 73
 
74 74
 		$snak = $context->getSnak();
75 75
 
76
-		$message = ( new ViolationMessage( 'wbqc-violation-message-one-of' ) )
77
-			->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE )
78
-			->withItemIdSnakValueList( $items, Role::OBJECT );
76
+		$message = (new ViolationMessage('wbqc-violation-message-one-of'))
77
+			->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE)
78
+			->withItemIdSnakValueList($items, Role::OBJECT);
79 79
 		$status = CheckResult::STATUS_VIOLATION;
80 80
 
81
-		foreach ( $items as $item ) {
82
-			if ( $item->matchesSnak( $snak ) ) {
81
+		foreach ($items as $item) {
82
+			if ($item->matchesSnak($snak)) {
83 83
 				$message = null;
84 84
 				$status = CheckResult::STATUS_COMPLIANCE;
85 85
 				break;
86 86
 			}
87 87
 		}
88 88
 
89
-		return new CheckResult( $context, $constraint, $status, $message );
89
+		return new CheckResult($context, $constraint, $status, $message);
90 90
 	}
91 91
 
92
-	public function checkConstraintParameters( Constraint $constraint ): array {
92
+	public function checkConstraintParameters(Constraint $constraint): array {
93 93
 		$constraintParameters = $constraint->getConstraintParameters();
94 94
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
95 95
 		$exceptions = [];
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 				$constraintTypeItemId,
100 100
 				true
101 101
 			);
102
-		} catch ( ConstraintParameterException $e ) {
102
+		} catch (ConstraintParameterException $e) {
103 103
 			$exceptions[] = $e;
104 104
 		}
105 105
 		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
@@ -76,9 +76,9 @@  discard block
 block discarded – undo
76 76
 	 * @throws ConstraintParameterException
77 77
 	 * @return CheckResult
78 78
 	 */
79
-	public function checkConstraint( Context $context, Constraint $constraint ): CheckResult {
80
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
81
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED );
79
+	public function checkConstraint(Context $context, Constraint $constraint): CheckResult {
80
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
81
+			return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED);
82 82
 		}
83 83
 
84 84
 		$constraintParameters = $constraint->getConstraintParameters();
@@ -90,50 +90,50 @@  discard block
 block discarded – undo
90 90
 			true
91 91
 		);
92 92
 
93
-		$message = ( new ViolationMessage( 'wbqc-violation-message-language' ) )
94
-			->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE )
95
-			->withItemIdSnakValueList( $languages, Role::OBJECT );
93
+		$message = (new ViolationMessage('wbqc-violation-message-language'))
94
+			->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE)
95
+			->withItemIdSnakValueList($languages, Role::OBJECT);
96 96
 		$status = CheckResult::STATUS_VIOLATION;
97 97
 
98
-		$lexeme = $this->getLexeme( $context );
99
-		if ( !$lexeme ) {
98
+		$lexeme = $this->getLexeme($context);
99
+		if (!$lexeme) {
100 100
 			// Lexeme doesn't exist, let's not bother
101
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE );
101
+			return new CheckResult($context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE);
102 102
 		}
103 103
 
104 104
 		/** @var Lexeme $lexeme */
105 105
 		'@phan-var Lexeme $lexeme';
106 106
 
107
-		foreach ( $languages as $language ) {
108
-			if ( $language->isNoValue() || $language->isSomeValue() ) {
107
+		foreach ($languages as $language) {
108
+			if ($language->isNoValue() || $language->isSomeValue()) {
109 109
 				continue;
110 110
 			}
111
-			if ( $lexeme->getLanguage()->equals( $language->getItemId() ) ) {
111
+			if ($lexeme->getLanguage()->equals($language->getItemId())) {
112 112
 				$message = null;
113 113
 				$status = CheckResult::STATUS_COMPLIANCE;
114 114
 				break;
115 115
 			}
116 116
 		}
117 117
 
118
-		return new CheckResult( $context, $constraint, $status, $message );
118
+		return new CheckResult($context, $constraint, $status, $message);
119 119
 	}
120 120
 
121
-	private function getLexeme( Context $context ): ?EntityDocument {
121
+	private function getLexeme(Context $context): ?EntityDocument {
122 122
 		$entityType = $context->getEntity()->getType();
123 123
 
124
-		if ( $entityType === Lexeme::ENTITY_TYPE ) {
124
+		if ($entityType === Lexeme::ENTITY_TYPE) {
125 125
 			return $context->getEntity();
126 126
 		}
127 127
 
128
-		if ( in_array( $entityType, [ Form::ENTITY_TYPE, Sense::ENTITY_TYPE ] ) ) {
128
+		if (in_array($entityType, [Form::ENTITY_TYPE, Sense::ENTITY_TYPE])) {
129 129
 			/** @var LexemeSubEntityId $id */
130 130
 			$id = $context->getEntity()->getId();
131 131
 			'@phan-var LexemeSubEntityId $id';
132
-			return $this->entityLookup->getEntity( $id->getLexemeId() );
132
+			return $this->entityLookup->getEntity($id->getLexemeId());
133 133
 		}
134 134
 	}
135 135
 
136
-	public function checkConstraintParameters( Constraint $constraint ): array {
136
+	public function checkConstraintParameters(Constraint $constraint): array {
137 137
 		$constraintParameters = $constraint->getConstraintParameters();
138 138
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
139 139
 		$exceptions = [];
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 				$constraintTypeItemId,
144 144
 				true
145 145
 			);
146
-		} catch ( ConstraintParameterException $e ) {
146
+		} catch (ConstraintParameterException $e) {
147 147
 			$exceptions[] = $e;
148 148
 		}
149 149
 		return $exceptions;
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/NoBoundsChecker.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -36,17 +36,17 @@  discard block
 block discarded – undo
36 36
 		return self::ALL_ENTITY_TYPES_SUPPORTED;
37 37
 	}
38 38
 
39
-	public function checkConstraint( Context $context, Constraint $constraint ): CheckResult {
39
+	public function checkConstraint(Context $context, Constraint $constraint): CheckResult {
40 40
 		$snak = $context->getSnak();
41 41
 
42
-		if ( !$snak instanceof PropertyValueSnak ) {
42
+		if (!$snak instanceof PropertyValueSnak) {
43 43
 			// nothing to check
44
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE );
44
+			return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE);
45 45
 		}
46 46
 
47
-		if ( $snak->getDataValue() instanceof QuantityValue ) {
48
-			$message = ( new ViolationMessage( 'wbqc-violation-message-noBounds' ) )
49
-				->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY );
47
+		if ($snak->getDataValue() instanceof QuantityValue) {
48
+			$message = (new ViolationMessage('wbqc-violation-message-noBounds'))
49
+				->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY);
50 50
 			return new CheckResult(
51 51
 				$context,
52 52
 				$constraint,
@@ -55,10 +55,10 @@  discard block
 block discarded – undo
55 55
 			);
56 56
 		}
57 57
 
58
-		return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE );
58
+		return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE);
59 59
 	}
60 60
 
61
-	public function checkConstraintParameters( Constraint $constraint ): array {
61
+	public function checkConstraintParameters(Constraint $constraint): array {
62 62
 		// no parameters
63 63
 		return [];
64 64
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/InverseChecker.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -89,9 +89,9 @@  discard block
 block discarded – undo
89 89
 	 * @throws ConstraintParameterException
90 90
 	 * @return CheckResult
91 91
 	 */
92
-	public function checkConstraint( Context $context, Constraint $constraint ): CheckResult {
93
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
94
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED );
92
+	public function checkConstraint(Context $context, Constraint $constraint): CheckResult {
93
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
94
+			return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED);
95 95
 		}
96 96
 
97 97
 		$constraintParameters = $constraint->getConstraintParameters();
@@ -104,9 +104,9 @@  discard block
 block discarded – undo
104 104
 
105 105
 		$snak = $context->getSnak();
106 106
 
107
-		if ( !$snak instanceof PropertyValueSnak ) {
107
+		if (!$snak instanceof PropertyValueSnak) {
108 108
 			// nothing to check
109
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE );
109
+			return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE);
110 110
 		}
111 111
 
112 112
 		$dataValue = $snak->getDataValue();
@@ -115,18 +115,18 @@  discard block
 block discarded – undo
115 115
 		 * error handling:
116 116
 		 *   type of $dataValue for properties with 'Inverse' constraint has to be 'wikibase-entityid'
117 117
 		 */
118
-		if ( !$dataValue instanceof EntityIdValue ) {
119
-			$message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) )
120
-				->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
121
-				->withDataValueType( 'wikibase-entityid' );
122
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message );
118
+		if (!$dataValue instanceof EntityIdValue) {
119
+			$message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type'))
120
+				->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
121
+				->withDataValueType('wikibase-entityid');
122
+			return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message);
123 123
 		}
124 124
 
125 125
 		$targetEntityId = $dataValue->getEntityId();
126
-		$targetEntity = $this->entityLookup->getEntity( $targetEntityId );
127
-		if ( !$targetEntity instanceof StatementListProvider ) {
128
-			$message = new ViolationMessage( 'wbqc-violation-message-target-entity-must-exist' );
129
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message );
126
+		$targetEntity = $this->entityLookup->getEntity($targetEntityId);
127
+		if (!$targetEntity instanceof StatementListProvider) {
128
+			$message = new ViolationMessage('wbqc-violation-message-target-entity-must-exist');
129
+			return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message);
130 130
 		}
131 131
 
132 132
 		$inverseStatement = $this->connectionCheckerHelper->findStatementWithPropertyAndEntityIdValue(
@@ -134,23 +134,23 @@  discard block
 block discarded – undo
134 134
 			$propertyId,
135 135
 			$context->getEntity()->getId()
136 136
 		);
137
-		if ( $inverseStatement !== null ) {
137
+		if ($inverseStatement !== null) {
138 138
 			$message = null;
139 139
 			$status = CheckResult::STATUS_COMPLIANCE;
140 140
 		} else {
141
-			$message = ( new ViolationMessage( 'wbqc-violation-message-inverse' ) )
142
-				->withEntityId( $targetEntityId, Role::SUBJECT )
143
-				->withEntityId( $propertyId, Role::PREDICATE )
144
-				->withEntityId( $context->getEntity()->getId(), Role::OBJECT );
141
+			$message = (new ViolationMessage('wbqc-violation-message-inverse'))
142
+				->withEntityId($targetEntityId, Role::SUBJECT)
143
+				->withEntityId($propertyId, Role::PREDICATE)
144
+				->withEntityId($context->getEntity()->getId(), Role::OBJECT);
145 145
 			$status = CheckResult::STATUS_VIOLATION;
146 146
 		}
147 147
 
148
-		return ( new CheckResult( $context, $constraint, $status, $message ) )
149
-			->withMetadata( Metadata::ofDependencyMetadata(
150
-				DependencyMetadata::ofEntityId( $targetEntityId ) ) );
148
+		return (new CheckResult($context, $constraint, $status, $message))
149
+			->withMetadata(Metadata::ofDependencyMetadata(
150
+				DependencyMetadata::ofEntityId($targetEntityId) ));
151 151
 	}
152 152
 
153
-	public function checkConstraintParameters( Constraint $constraint ): array {
153
+	public function checkConstraintParameters(Constraint $constraint): array {
154 154
 		$constraintParameters = $constraint->getConstraintParameters();
155 155
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
156 156
 		$exceptions = [];
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 				$constraintParameters,
160 160
 				$constraintTypeItemId
161 161
 			);
162
-		} catch ( ConstraintParameterException $e ) {
162
+		} catch (ConstraintParameterException $e) {
163 163
 			$exceptions[] = $e;
164 164
 		}
165 165
 		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
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	 * @codeCoverageIgnore This method is purely declarative.
81 81
 	 */
82 82
 	public function getDefaultContextTypes(): array {
83
-		return [ Context::TYPE_STATEMENT ];
83
+		return [Context::TYPE_STATEMENT];
84 84
 	}
85 85
 
86 86
 	/** @codeCoverageIgnore This method is purely declarative. */
@@ -97,31 +97,31 @@  discard block
 block discarded – undo
97 97
 	 * @return CheckResult
98 98
 	 * @throws ConfigException
99 99
 	 */
100
-	public function checkConstraint( Context $context, Constraint $constraint ): CheckResult {
101
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
102
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED );
100
+	public function checkConstraint(Context $context, Constraint $constraint): CheckResult {
101
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
102
+			return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED);
103 103
 		}
104 104
 		$snak = $context->getSnak();
105
-		if ( !$snak instanceof PropertyValueSnak ) {
105
+		if (!$snak instanceof PropertyValueSnak) {
106 106
 			// nothing to check
107
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE );
107
+			return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE);
108 108
 		}
109 109
 
110 110
 		$dataValue = $snak->getDataValue();
111
-		if ( !$dataValue instanceof EntityIdValue ) {
111
+		if (!$dataValue instanceof EntityIdValue) {
112 112
 			// wrong data type
113
-			$message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) )
114
-				->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM )
115
-				->withDataValueType( 'wikibase-entityid' );
116
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message );
113
+			$message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type'))
114
+				->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM)
115
+				->withDataValueType('wikibase-entityid');
116
+			return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message);
117 117
 		}
118 118
 
119 119
 		$objectId = $dataValue->getEntityId();
120
-		$objectItem = $this->entityLookup->getEntity( $objectId );
121
-		if ( !( $objectItem instanceof StatementListProvider ) ) {
120
+		$objectItem = $this->entityLookup->getEntity($objectId);
121
+		if (!($objectItem instanceof StatementListProvider)) {
122 122
 			// object was deleted/doesn't exist
123
-			$message = new ViolationMessage( 'wbqc-violation-message-value-entity-must-exist' );
124
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message );
123
+			$message = new ViolationMessage('wbqc-violation-message-value-entity-must-exist');
124
+			return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message);
125 125
 		}
126 126
 		/** @var Statement[] $objectStatements */
127 127
 		$objectStatements = $objectItem->getStatements()->toArray();
@@ -129,9 +129,9 @@  discard block
 block discarded – undo
129 129
 		$subjectId = $context->getEntity()->getId();
130 130
 		$subjectStatements = $context->getEntity()->getStatements()->toArray();
131 131
 		/** @var String[] $startPropertyIds */
132
-		$startPropertyIds = $this->config->get( self::CONFIG_VARIABLE_START_PROPERTY_IDS );
132
+		$startPropertyIds = $this->config->get(self::CONFIG_VARIABLE_START_PROPERTY_IDS);
133 133
 		/** @var String[] $endPropertyIds */
134
-		$endPropertyIds = $this->config->get( self::CONFIG_VARIABLE_END_PROPERTY_IDS );
134
+		$endPropertyIds = $this->config->get(self::CONFIG_VARIABLE_END_PROPERTY_IDS);
135 135
 		$subjectStartValue = $this->getExtremeValue(
136 136
 			$startPropertyIds,
137 137
 			$subjectStatements,
@@ -153,15 +153,15 @@  discard block
 block discarded – undo
153 153
 			'end'
154 154
 		);
155 155
 		if (
156
-			$this->rangeCheckerHelper->getComparison( $subjectStartValue, $subjectEndValue ) <= 0 &&
157
-			$this->rangeCheckerHelper->getComparison( $objectStartValue, $objectEndValue ) <= 0 && (
158
-				$this->rangeCheckerHelper->getComparison( $subjectEndValue, $objectStartValue ) < 0 ||
159
-				$this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectStartValue ) < 0
156
+			$this->rangeCheckerHelper->getComparison($subjectStartValue, $subjectEndValue) <= 0 &&
157
+			$this->rangeCheckerHelper->getComparison($objectStartValue, $objectEndValue) <= 0 && (
158
+				$this->rangeCheckerHelper->getComparison($subjectEndValue, $objectStartValue) < 0 ||
159
+				$this->rangeCheckerHelper->getComparison($objectEndValue, $subjectStartValue) < 0
160 160
 			)
161 161
 		) {
162 162
 			if (
163 163
 				$subjectEndValue == null ||
164
-				$this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectEndValue ) < 0
164
+				$this->rangeCheckerHelper->getComparison($objectEndValue, $subjectEndValue) < 0
165 165
 			) {
166 166
 				$earlierEntityId = $objectId;
167 167
 				$minEndValue = $objectEndValue;
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 			$message = null;
187 187
 			$status = CheckResult::STATUS_COMPLIANCE;
188 188
 		}
189
-		return new CheckResult( $context, $constraint, $status, $message );
189
+		return new CheckResult($context, $constraint, $status, $message);
190 190
 	}
191 191
 
192 192
 	/**
@@ -196,19 +196,19 @@  discard block
 block discarded – undo
196 196
 	 *
197 197
 	 * @return DataValue|null
198 198
 	 */
199
-	private function getExtremeValue( $extremePropertyIds, $statements, $startOrEnd ) {
200
-		if ( $startOrEnd !== 'start' && $startOrEnd !== 'end' ) {
201
-			throw new \InvalidArgumentException( '$startOrEnd must be \'start\' or \'end\'.' );
199
+	private function getExtremeValue($extremePropertyIds, $statements, $startOrEnd) {
200
+		if ($startOrEnd !== 'start' && $startOrEnd !== 'end') {
201
+			throw new \InvalidArgumentException('$startOrEnd must be \'start\' or \'end\'.');
202 202
 		}
203 203
 		$extremeValue = null;
204
-		foreach ( $extremePropertyIds as $extremePropertyId ) {
205
-			$statementList = new StatementList( ...$statements );
206
-			$extremeStatements = $statementList->getByPropertyId( new NumericPropertyId( $extremePropertyId ) );
204
+		foreach ($extremePropertyIds as $extremePropertyId) {
205
+			$statementList = new StatementList(...$statements);
206
+			$extremeStatements = $statementList->getByPropertyId(new NumericPropertyId($extremePropertyId));
207 207
 			/** @var Statement $extremeStatement */
208
-			foreach ( $extremeStatements as $extremeStatement ) {
209
-				if ( $extremeStatement->getRank() !== Statement::RANK_DEPRECATED ) {
208
+			foreach ($extremeStatements as $extremeStatement) {
209
+				if ($extremeStatement->getRank() !== Statement::RANK_DEPRECATED) {
210 210
 					$snak = $extremeStatement->getMainSnak();
211
-					if ( !$snak instanceof PropertyValueSnak ) {
211
+					if (!$snak instanceof PropertyValueSnak) {
212 212
 						return null;
213 213
 					} else {
214 214
 						$comparison = $this->rangeCheckerHelper->getComparison(
@@ -217,8 +217,8 @@  discard block
 block discarded – undo
217 217
 						);
218 218
 						if (
219 219
 							$extremeValue === null ||
220
-							( $startOrEnd === 'start' && $comparison < 0 ) ||
221
-							( $startOrEnd === 'end' && $comparison > 0 )
220
+							($startOrEnd === 'start' && $comparison < 0) ||
221
+							($startOrEnd === 'end' && $comparison > 0)
222 222
 						) {
223 223
 							$extremeValue = $snak->getDataValue();
224 224
 						}
@@ -248,17 +248,16 @@  discard block
 block discarded – undo
248 248
 		DataValue $maxStartValue
249 249
 	) {
250 250
 		$messageKey = $earlierEntityId === $subjectId ?
251
-			'wbqc-violation-message-contemporary-subject-earlier' :
252
-			'wbqc-violation-message-contemporary-value-earlier';
253
-		return ( new ViolationMessage( $messageKey ) )
254
-			->withEntityId( $subjectId, Role::SUBJECT )
255
-			->withEntityId( $propertyId, Role::PREDICATE )
256
-			->withEntityId( $objectId, Role::OBJECT )
257
-			->withDataValue( $minEndValue, Role::OBJECT )
258
-			->withDataValue( $maxStartValue, Role::OBJECT );
251
+			'wbqc-violation-message-contemporary-subject-earlier' : 'wbqc-violation-message-contemporary-value-earlier';
252
+		return (new ViolationMessage($messageKey))
253
+			->withEntityId($subjectId, Role::SUBJECT)
254
+			->withEntityId($propertyId, Role::PREDICATE)
255
+			->withEntityId($objectId, Role::OBJECT)
256
+			->withDataValue($minEndValue, Role::OBJECT)
257
+			->withDataValue($maxStartValue, Role::OBJECT);
259 258
 	}
260 259
 
261
-	public function checkConstraintParameters( Constraint $constraint ): array {
260
+	public function checkConstraintParameters(Constraint $constraint): array {
262 261
 		// no parameters
263 262
 		return [];
264 263
 	}
Please login to merge, or discard this patch.
src/ConstraintCheck/Checker/ValueTypeChecker.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -88,9 +88,9 @@  discard block
 block discarded – undo
88 88
 	 * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs
89 89
 	 * @return CheckResult
90 90
 	 */
91
-	public function checkConstraint( Context $context, Constraint $constraint ): CheckResult {
92
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
93
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED );
91
+	public function checkConstraint(Context $context, Constraint $constraint): CheckResult {
92
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
93
+			return new CheckResult($context, $constraint, CheckResult::STATUS_DEPRECATED);
94 94
 		}
95 95
 
96 96
 		$constraintParameters = $constraint->getConstraintParameters();
@@ -106,18 +106,18 @@  discard block
 block discarded – undo
106 106
 			$constraintTypeItemId
107 107
 		);
108 108
 		$relationIds = [];
109
-		if ( $relation === 'instance' || $relation === 'instanceOrSubclass' ) {
110
-			$relationIds[] = $this->config->get( 'WBQualityConstraintsInstanceOfId' );
109
+		if ($relation === 'instance' || $relation === 'instanceOrSubclass') {
110
+			$relationIds[] = $this->config->get('WBQualityConstraintsInstanceOfId');
111 111
 		}
112
-		if ( $relation === 'subclass' || $relation === 'instanceOrSubclass' ) {
113
-			$relationIds[] = $this->config->get( 'WBQualityConstraintsSubclassOfId' );
112
+		if ($relation === 'subclass' || $relation === 'instanceOrSubclass') {
113
+			$relationIds[] = $this->config->get('WBQualityConstraintsSubclassOfId');
114 114
 		}
115 115
 
116 116
 		$snak = $context->getSnak();
117 117
 
118
-		if ( !$snak instanceof PropertyValueSnak ) {
118
+		if (!$snak instanceof PropertyValueSnak) {
119 119
 			// nothing to check
120
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_COMPLIANCE );
120
+			return new CheckResult($context, $constraint, CheckResult::STATUS_COMPLIANCE);
121 121
 		}
122 122
 
123 123
 		$dataValue = $snak->getDataValue();
@@ -126,23 +126,23 @@  discard block
 block discarded – undo
126 126
 		 * error handling:
127 127
 		 *   type of $dataValue for properties with 'Value type' constraint has to be 'wikibase-entityid'
128 128
 		 */
129
-		if ( !$dataValue instanceof EntityIdValue ) {
130
-			$message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) )
131
-				->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM )
132
-				->withDataValueType( 'wikibase-entityid' );
133
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message );
129
+		if (!$dataValue instanceof EntityIdValue) {
130
+			$message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type'))
131
+				->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM)
132
+				->withDataValueType('wikibase-entityid');
133
+			return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message);
134 134
 		}
135 135
 
136 136
 		try {
137
-			$item = $this->entityLookup->getEntity( $dataValue->getEntityId() );
138
-		} catch ( UnresolvedEntityRedirectException $e ) {
137
+			$item = $this->entityLookup->getEntity($dataValue->getEntityId());
138
+		} catch (UnresolvedEntityRedirectException $e) {
139 139
 			// Edge case (double redirect): Pretend the entity doesn't exist
140 140
 			$item = null;
141 141
 		}
142 142
 
143
-		if ( !( $item instanceof StatementListProvidingEntity ) ) {
144
-			$message = new ViolationMessage( 'wbqc-violation-message-value-entity-must-exist' );
145
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_VIOLATION, $message );
143
+		if (!($item instanceof StatementListProvidingEntity)) {
144
+			$message = new ViolationMessage('wbqc-violation-message-value-entity-must-exist');
145
+			return new CheckResult($context, $constraint, CheckResult::STATUS_VIOLATION, $message);
146 146
 		}
147 147
 
148 148
 		$statements = $item->getStatements();
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 			$classes
154 154
 		);
155 155
 
156
-		if ( $result->getBool() ) {
156
+		if ($result->getBool()) {
157 157
 			$message = null;
158 158
 			$status = CheckResult::STATUS_COMPLIANCE;
159 159
 		} else {
@@ -167,11 +167,11 @@  discard block
 block discarded – undo
167 167
 			$status = CheckResult::STATUS_VIOLATION;
168 168
 		}
169 169
 
170
-		return ( new CheckResult( $context, $constraint, $status, $message ) )
171
-			->withMetadata( $result->getMetadata() );
170
+		return (new CheckResult($context, $constraint, $status, $message))
171
+			->withMetadata($result->getMetadata());
172 172
 	}
173 173
 
174
-	public function checkConstraintParameters( Constraint $constraint ): array {
174
+	public function checkConstraintParameters(Constraint $constraint): array {
175 175
 		$constraintParameters = $constraint->getConstraintParameters();
176 176
 		$constraintTypeItemId = $constraint->getConstraintTypeItemId();
177 177
 		$exceptions = [];
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 				$constraintParameters,
181 181
 				$constraintTypeItemId
182 182
 			);
183
-		} catch ( ConstraintParameterException $e ) {
183
+		} catch (ConstraintParameterException $e) {
184 184
 			$exceptions[] = $e;
185 185
 		}
186 186
 		try {
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 				$constraintParameters,
189 189
 				$constraintTypeItemId
190 190
 			);
191
-		} catch ( ConstraintParameterException $e ) {
191
+		} catch (ConstraintParameterException $e) {
192 192
 			$exceptions[] = $e;
193 193
 		}
194 194
 		return $exceptions;
Please login to merge, or discard this patch.
src/ConstraintCheck/Helper/SparqlHelper.php 1 patch
Spacing   +203 added lines, -207 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\Helper;
6 6
 
@@ -166,143 +166,143 @@  discard block
 block discarded – undo
166 166
 		$this->defaultUserAgent = $defaultUserAgent;
167 167
 		$this->requestFactory = $requestFactory;
168 168
 		$this->entityPrefixes = [];
169
-		foreach ( $rdfVocabulary->entityNamespaceNames as $namespaceName ) {
170
-			$this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI( $namespaceName );
169
+		foreach ($rdfVocabulary->entityNamespaceNames as $namespaceName) {
170
+			$this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI($namespaceName);
171 171
 		}
172 172
 
173
-		$this->primaryEndpoint = $config->get( 'WBQualityConstraintsSparqlEndpoint' );
174
-		$this->additionalEndpoints = $config->get( 'WBQualityConstraintsAdditionalSparqlEndpoints' ) ?: [];
175
-		$this->maxQueryTimeMillis = $config->get( 'WBQualityConstraintsSparqlMaxMillis' );
176
-		$this->subclassOfId = new NumericPropertyId( $config->get( 'WBQualityConstraintsSubclassOfId' ) );
177
-		$this->cacheMapSize = $config->get( 'WBQualityConstraintsFormatCacheMapSize' );
173
+		$this->primaryEndpoint = $config->get('WBQualityConstraintsSparqlEndpoint');
174
+		$this->additionalEndpoints = $config->get('WBQualityConstraintsAdditionalSparqlEndpoints') ?: [];
175
+		$this->maxQueryTimeMillis = $config->get('WBQualityConstraintsSparqlMaxMillis');
176
+		$this->subclassOfId = new NumericPropertyId($config->get('WBQualityConstraintsSubclassOfId'));
177
+		$this->cacheMapSize = $config->get('WBQualityConstraintsFormatCacheMapSize');
178 178
 		$this->timeoutExceptionClasses = $config->get(
179 179
 			'WBQualityConstraintsSparqlTimeoutExceptionClasses'
180 180
 		);
181 181
 		$this->sparqlHasWikibaseSupport = $config->get(
182 182
 			'WBQualityConstraintsSparqlHasWikibaseSupport'
183 183
 		);
184
-		$this->sparqlThrottlingFallbackDuration = (int)$config->get(
184
+		$this->sparqlThrottlingFallbackDuration = (int) $config->get(
185 185
 			'WBQualityConstraintsSparqlThrottlingFallbackDuration'
186 186
 		);
187 187
 
188
-		$this->prefixes = $this->getQueryPrefixes( $rdfVocabulary );
188
+		$this->prefixes = $this->getQueryPrefixes($rdfVocabulary);
189 189
 
190 190
 		$this->rdfVocabularyWithoutNormalization = clone $rdfVocabulary;
191 191
 		// @phan-suppress-next-line PhanTypeMismatchProperty
192 192
 		$this->rdfVocabularyWithoutNormalization->normalizedPropertyValueNamespace = array_fill_keys(
193
-			array_keys( $rdfVocabulary->normalizedPropertyValueNamespace ),
193
+			array_keys($rdfVocabulary->normalizedPropertyValueNamespace),
194 194
 			null
195 195
 		);
196 196
 	}
197 197
 
198
-	private function getQueryPrefixes( RdfVocabulary $rdfVocabulary ): string {
198
+	private function getQueryPrefixes(RdfVocabulary $rdfVocabulary): string {
199 199
 		// TODO: it would probably be smarter that RdfVocabulary exposed these prefixes somehow
200 200
 		$prefixes = '';
201
-		foreach ( $rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName ) {
201
+		foreach ($rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName) {
202 202
 			$prefixes .= <<<END
203
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
203
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
204 204
 END;
205 205
 		}
206 206
 
207
-		foreach ( $rdfVocabulary->statementNamespaceNames as $sourceName => $sourceNamespaces ) {
207
+		foreach ($rdfVocabulary->statementNamespaceNames as $sourceName => $sourceNamespaces) {
208 208
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NS_VALUE];
209 209
 			$prefixes .= <<<END
210
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
210
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
211 211
 END;
212 212
 		}
213 213
 
214
-		foreach ( $rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces ) {
214
+		foreach ($rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces) {
215 215
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_DIRECT_CLAIM];
216 216
 			$prefixes .= <<<END
217
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
217
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
218 218
 END;
219 219
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM];
220 220
 			$prefixes .= <<<END
221
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
221
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
222 222
 END;
223 223
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM_STATEMENT];
224 224
 			$prefixes .= <<<END
225
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
225
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
226 226
 END;
227 227
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM_VALUE];
228 228
 			$prefixes .= <<<END
229
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
229
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
230 230
 END;
231 231
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER];
232 232
 			$prefixes .= <<<END
233
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
233
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
234 234
 END;
235 235
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER_VALUE];
236 236
 			$prefixes .= <<<END
237
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
237
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
238 238
 END;
239 239
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE];
240 240
 			$prefixes .= <<<END
241
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
241
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
242 242
 END;
243 243
 			$namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE_VALUE];
244 244
 			$prefixes .= <<<END
245
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
245
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
246 246
 END;
247 247
 		}
248 248
 		$namespaceName = RdfVocabulary::NS_ONTOLOGY;
249 249
 		$prefixes .= <<<END
250
-PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n
250
+PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n
251 251
 END;
252 252
 		return $prefixes;
253 253
 	}
254 254
 
255 255
 	/** Return a SPARQL term like `wd:Q123` for the given ID. */
256
-	private function wd( EntityId $id ): string {
257
-		$repository = $this->rdfVocabulary->getEntityRepositoryName( $id );
256
+	private function wd(EntityId $id): string {
257
+		$repository = $this->rdfVocabulary->getEntityRepositoryName($id);
258 258
 		$prefix = $this->rdfVocabulary->entityNamespaceNames[$repository];
259 259
 		return "$prefix:{$id->getSerialization()}";
260 260
 	}
261 261
 
262 262
 	/** Return a SPARQL term like `wdt:P123` for the given ID. */
263
-	private function wdt( PropertyId $id ): string {
264
-		$repository = $this->rdfVocabulary->getEntityRepositoryName( $id );
263
+	private function wdt(PropertyId $id): string {
264
+		$repository = $this->rdfVocabulary->getEntityRepositoryName($id);
265 265
 		$prefix = $this->rdfVocabulary->propertyNamespaceNames[$repository][RdfVocabulary::NSP_DIRECT_CLAIM];
266 266
 		return "$prefix:{$id->getSerialization()}";
267 267
 	}
268 268
 
269 269
 	/** Return a SPARQL term like `p:P123` for the given ID. */
270
-	private function p( PropertyId $id ): string {
271
-		$repository = $this->rdfVocabulary->getEntityRepositoryName( $id );
270
+	private function p(PropertyId $id): string {
271
+		$repository = $this->rdfVocabulary->getEntityRepositoryName($id);
272 272
 		$prefix = $this->rdfVocabulary->propertyNamespaceNames[$repository][RdfVocabulary::NSP_CLAIM];
273 273
 		return "$prefix:{$id->getSerialization()}";
274 274
 	}
275 275
 
276 276
 	/** Return a SPARQL term like `pq:P123` for the given ID. */
277
-	private function pq( PropertyId $id ): string {
278
-		$repository = $this->rdfVocabulary->getEntityRepositoryName( $id );
277
+	private function pq(PropertyId $id): string {
278
+		$repository = $this->rdfVocabulary->getEntityRepositoryName($id);
279 279
 		$prefix = $this->rdfVocabulary->propertyNamespaceNames[$repository][RdfVocabulary::NSP_QUALIFIER];
280 280
 		return "$prefix:{$id->getSerialization()}";
281 281
 	}
282 282
 
283 283
 	/** Return a SPARQL term like `wdno:P123` for the given ID. */
284
-	private function wdno( PropertyId $id ): string {
285
-		$repository = $this->rdfVocabulary->getEntityRepositoryName( $id );
284
+	private function wdno(PropertyId $id): string {
285
+		$repository = $this->rdfVocabulary->getEntityRepositoryName($id);
286 286
 		$prefix = $this->rdfVocabulary->propertyNamespaceNames[$repository][RdfVocabulary::NSP_NOVALUE];
287 287
 		return "$prefix:{$id->getSerialization()}";
288 288
 	}
289 289
 
290 290
 	/** Return a SPARQL term like `prov:NAME` for the given name. */
291
-	private function prov( string $name ): string {
291
+	private function prov(string $name): string {
292 292
 		$prefix = RdfVocabulary::NS_PROV;
293 293
 		return "$prefix:$name";
294 294
 	}
295 295
 
296 296
 	/** Return a SPARQL term like `wikibase:NAME` for the given name. */
297
-	private function wikibase( string $name ): string {
297
+	private function wikibase(string $name): string {
298 298
 		$prefix = RdfVocabulary::NS_ONTOLOGY;
299 299
 		return "$prefix:$name";
300 300
 	}
301 301
 
302 302
 	/** Return a SPARQL snippet like `MINUS { ?var wikibase:rank wikibase:DeprecatedRank. }`. */
303
-	private function minusDeprecatedRank( string $varName ): string {
303
+	private function minusDeprecatedRank(string $varName): string {
304 304
 		$deprecatedRank = RdfVocabulary::RANK_MAP[Statement::RANK_DEPRECATED];
305
-		return "MINUS { $varName {$this->wikibase( 'rank' )} {$this->wikibase( $deprecatedRank )}. }";
305
+		return "MINUS { $varName {$this->wikibase('rank')} {$this->wikibase($deprecatedRank)}. }";
306 306
 	}
307 307
 
308 308
 	/**
@@ -312,43 +312,42 @@  discard block
 block discarded – undo
312 312
 	 * @return CachedBool
313 313
 	 * @throws SparqlHelperException if the query times out or some other error occurs
314 314
 	 */
315
-	public function hasType( EntityId $id, array $classes ): CachedBool {
315
+	public function hasType(EntityId $id, array $classes): CachedBool {
316 316
 		// TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually
317 317
 		$gearingHint = $this->sparqlHasWikibaseSupport ?
318
-			' hint:Prior hint:gearing "forward".' :
319
-			'';
318
+			' hint:Prior hint:gearing "forward".' : '';
320 319
 
321 320
 		$metadatas = [];
322 321
 
323
-		foreach ( array_chunk( $classes, 20 ) as $classesChunk ) {
324
-			$classesValues = implode( ' ', array_map(
325
-				function ( string $class ) {
326
-					return $this->wd( new ItemId( $class ) );
322
+		foreach (array_chunk($classes, 20) as $classesChunk) {
323
+			$classesValues = implode(' ', array_map(
324
+				function(string $class) {
325
+					return $this->wd(new ItemId($class));
327 326
 				},
328 327
 				$classesChunk
329
-			) );
328
+			));
330 329
 
331 330
 			$query = <<<EOF
332 331
 ASK {
333
-  BIND({$this->wd( $id )} AS ?item)
332
+  BIND({$this->wd($id)} AS ?item)
334 333
   VALUES ?class { $classesValues }
335
-  ?item {$this->wdt( $this->subclassOfId )}* ?class.$gearingHint
334
+  ?item {$this->wdt($this->subclassOfId)}* ?class.$gearingHint
336 335
 }
337 336
 EOF;
338 337
 
339
-			$result = $this->runQuery( $query, $this->primaryEndpoint );
338
+			$result = $this->runQuery($query, $this->primaryEndpoint);
340 339
 			$metadatas[] = $result->getMetadata();
341
-			if ( $result->getArray()['boolean'] ) {
340
+			if ($result->getArray()['boolean']) {
342 341
 				return new CachedBool(
343 342
 					true,
344
-					Metadata::merge( $metadatas )
343
+					Metadata::merge($metadatas)
345 344
 				);
346 345
 			}
347 346
 		}
348 347
 
349 348
 		return new CachedBool(
350 349
 			false,
351
-			Metadata::merge( $metadatas )
350
+			Metadata::merge($metadatas)
352 351
 		);
353 352
 	}
354 353
 
@@ -365,12 +364,12 @@  discard block
 block discarded – undo
365 364
 		array $separators
366 365
 	): CachedEntityIds {
367 366
 		$mainSnak = $statement->getMainSnak();
368
-		if ( !( $mainSnak instanceof PropertyValueSnak ) ) {
369
-			return new CachedEntityIds( [], Metadata::blank() );
367
+		if (!($mainSnak instanceof PropertyValueSnak)) {
368
+			return new CachedEntityIds([], Metadata::blank());
370 369
 		}
371 370
 
372 371
 		$propertyId = $statement->getPropertyId();
373
-		$pPredicateAndObject = "{$this->p( $propertyId )} ?otherStatement."; // p:P123 ?otherStatement.
372
+		$pPredicateAndObject = "{$this->p($propertyId)} ?otherStatement."; // p:P123 ?otherStatement.
374 373
 		$otherStatementPredicateAndObject = $this->getSnakPredicateAndObject(
375 374
 			$entityId,
376 375
 			$mainSnak,
@@ -379,57 +378,57 @@  discard block
 block discarded – undo
379 378
 
380 379
 		$isSeparator = [];
381 380
 		$unusedSeparators = [];
382
-		foreach ( $separators as $separator ) {
381
+		foreach ($separators as $separator) {
383 382
 			$isSeparator[$separator->getSerialization()] = true;
384 383
 			$unusedSeparators[$separator->getSerialization()] = $separator;
385 384
 		}
386 385
 		$separatorFilters = '';
387
-		foreach ( $statement->getQualifiers() as $qualifier ) {
386
+		foreach ($statement->getQualifiers() as $qualifier) {
388 387
 			$qualPropertyId = $qualifier->getPropertyId();
389
-			if ( !( $isSeparator[$qualPropertyId->getSerialization()] ?? false ) ) {
388
+			if (!($isSeparator[$qualPropertyId->getSerialization()] ?? false)) {
390 389
 				continue;
391 390
 			}
392
-			unset( $unusedSeparators[$qualPropertyId->getSerialization()] );
391
+			unset($unusedSeparators[$qualPropertyId->getSerialization()]);
393 392
 			// only look for other statements with the same qualifier
394
-			if ( $qualifier instanceof PropertyValueSnak ) {
393
+			if ($qualifier instanceof PropertyValueSnak) {
395 394
 				$sepPredicateAndObject = $this->getSnakPredicateAndObject(
396 395
 					$entityId,
397 396
 					$qualifier,
398 397
 					RdfVocabulary::NSP_QUALIFIER
399 398
 				);
400 399
 				$separatorFilters .= "  ?otherStatement $sepPredicateAndObject\n";
401
-			} elseif ( $qualifier instanceof PropertyNoValueSnak ) {
402
-				$sepPredicateAndObject = "a {$this->wdno( $qualPropertyId )}."; // a wdno:P123.
400
+			} elseif ($qualifier instanceof PropertyNoValueSnak) {
401
+				$sepPredicateAndObject = "a {$this->wdno($qualPropertyId)}."; // a wdno:P123.
403 402
 				$separatorFilters .= "  ?otherStatement $sepPredicateAndObject\n";
404 403
 			} else {
405 404
 				// "some value" / "unknown value" is always different from everything else,
406 405
 				// therefore the whole statement has no duplicates and we can return immediately
407
-				return new CachedEntityIds( [], Metadata::blank() );
406
+				return new CachedEntityIds([], Metadata::blank());
408 407
 			}
409 408
 		}
410
-		foreach ( $unusedSeparators as $unusedSeparator ) {
409
+		foreach ($unusedSeparators as $unusedSeparator) {
411 410
 			// exclude other statements which have a separator that this one lacks
412
-			$separatorFilters .= "  MINUS { ?otherStatement {$this->pq( $unusedSeparator )} []. }\n";
413
-			$separatorFilters .= "  MINUS { ?otherStatement a {$this->wdno( $unusedSeparator )}. }\n";
411
+			$separatorFilters .= "  MINUS { ?otherStatement {$this->pq($unusedSeparator)} []. }\n";
412
+			$separatorFilters .= "  MINUS { ?otherStatement a {$this->wdno($unusedSeparator)}. }\n";
414 413
 		}
415 414
 
416 415
 		$query = <<<SPARQL
417 416
 SELECT DISTINCT ?otherEntity WHERE {
418 417
   ?otherEntity $pPredicateAndObject
419 418
   ?otherStatement $otherStatementPredicateAndObject
420
-  {$this->minusDeprecatedRank( '?otherStatement' )}
421
-  FILTER(?otherEntity != {$this->wd( $entityId )})
419
+  {$this->minusDeprecatedRank('?otherStatement')}
420
+  FILTER(?otherEntity != {$this->wd($entityId)})
422 421
 $separatorFilters
423 422
 }
424 423
 LIMIT 10
425 424
 SPARQL;
426 425
 
427
-		$results = [ $this->runQuery( $query, $this->primaryEndpoint ) ];
428
-		foreach ( $this->additionalEndpoints as $endpoint ) {
429
-			$results[] = $this->runQuery( $query, $endpoint );
426
+		$results = [$this->runQuery($query, $this->primaryEndpoint)];
427
+		foreach ($this->additionalEndpoints as $endpoint) {
428
+			$results[] = $this->runQuery($query, $endpoint);
430 429
 		}
431 430
 
432
-		return $this->getOtherEntities( $results );
431
+		return $this->getOtherEntities($results);
433 432
 	}
434 433
 
435 434
 	/**
@@ -448,40 +447,38 @@  discard block
 block discarded – undo
448 447
 		bool $ignoreDeprecatedStatements
449 448
 	): CachedEntityIds {
450 449
 		$propertyId = $snak->getPropertyId();
451
-		$pPredicateAndObject = "{$this->p( $propertyId )} ?otherStatement."; // p:P123 ?otherStatement.
450
+		$pPredicateAndObject = "{$this->p($propertyId)} ?otherStatement."; // p:P123 ?otherStatement.
452 451
 
453 452
 		$otherSubject = $type === Context::TYPE_QUALIFIER ?
454
-			'?otherStatement' :
455
-			"?otherStatement {$this->prov( 'wasDerivedFrom' )} ?reference.\n  ?reference";
453
+			'?otherStatement' : "?otherStatement {$this->prov('wasDerivedFrom')} ?reference.\n  ?reference";
456 454
 		$otherPredicateAndObject = $this->getSnakPredicateAndObject(
457 455
 			$entityId,
458 456
 			$snak,
459 457
 			$type === Context::TYPE_QUALIFIER ?
460
-				RdfVocabulary::NSP_QUALIFIER :
461
-				RdfVocabulary::NSP_REFERENCE
458
+				RdfVocabulary::NSP_QUALIFIER : RdfVocabulary::NSP_REFERENCE
462 459
 		);
463 460
 
464 461
 		$deprecatedFilter = '';
465
-		if ( $ignoreDeprecatedStatements ) {
466
-			$deprecatedFilter = '  ' . $this->minusDeprecatedRank( '?otherStatement' );
462
+		if ($ignoreDeprecatedStatements) {
463
+			$deprecatedFilter = '  '.$this->minusDeprecatedRank('?otherStatement');
467 464
 		}
468 465
 
469 466
 		$query = <<<SPARQL
470 467
 SELECT DISTINCT ?otherEntity WHERE {
471 468
   ?otherEntity $pPredicateAndObject
472 469
   $otherSubject $otherPredicateAndObject
473
-  FILTER(?otherEntity != {$this->wd( $entityId )})
470
+  FILTER(?otherEntity != {$this->wd($entityId)})
474 471
 $deprecatedFilter
475 472
 }
476 473
 LIMIT 10
477 474
 SPARQL;
478 475
 
479
-		$results = [ $this->runQuery( $query, $this->primaryEndpoint ) ];
480
-		foreach ( $this->additionalEndpoints as $endpoint ) {
481
-			$results[] = $this->runQuery( $query, $endpoint );
476
+		$results = [$this->runQuery($query, $this->primaryEndpoint)];
477
+		foreach ($this->additionalEndpoints as $endpoint) {
478
+			$results[] = $this->runQuery($query, $endpoint);
482 479
 		}
483 480
 
484
-		return $this->getOtherEntities( $results );
481
+		return $this->getOtherEntities($results);
485 482
 	}
486 483
 
487 484
 	/**
@@ -512,13 +509,13 @@  discard block
 block discarded – undo
512 509
 		$writer->start();
513 510
 		$writer->drain();
514 511
 		$placeholder1 = 'wbqc';
515
-		$placeholder2 = 'x' . wfRandomString( 32 );
516
-		$writer->about( $placeholder1, $placeholder2 );
512
+		$placeholder2 = 'x'.wfRandomString(32);
513
+		$writer->about($placeholder1, $placeholder2);
517 514
 
518 515
 		$propertyId = $snak->getPropertyId();
519 516
 		$pid = $propertyId->getSerialization();
520
-		$propertyRepository = $this->rdfVocabulary->getEntityRepositoryName( $propertyId );
521
-		$entityRepository = $this->rdfVocabulary->getEntityRepositoryName( $entityId );
517
+		$propertyRepository = $this->rdfVocabulary->getEntityRepositoryName($propertyId);
518
+		$entityRepository = $this->rdfVocabulary->getEntityRepositoryName($entityId);
522 519
 		$propertyNamespace = $this->rdfVocabulary->propertyNamespaceNames[$propertyRepository][$namespace];
523 520
 		$value = $snak->getDataValue();
524 521
 		if (
@@ -549,21 +546,21 @@  discard block
 block discarded – undo
549 546
 				$writer,
550 547
 				$propertyNamespace,
551 548
 				$pid,
552
-				$this->propertyDataTypeLookup->getDataTypeIdForProperty( $propertyId ),
549
+				$this->propertyDataTypeLookup->getDataTypeIdForProperty($propertyId),
553 550
 				$this->rdfVocabulary->statementNamespaceNames[$entityRepository][RdfVocabulary::NS_VALUE], // should be unused
554 551
 				$snak
555 552
 			);
556 553
 		}
557 554
 
558 555
 		$triple = $writer->drain(); // wbqc:xRANDOM ps:PID "value". or similar
559
-		return trim( str_replace( "$placeholder1:$placeholder2", '', $triple ) );
556
+		return trim(str_replace("$placeholder1:$placeholder2", '', $triple));
560 557
 	}
561 558
 
562 559
 	/**
563 560
 	 * Return SPARQL code for a string literal with $text as content.
564 561
 	 */
565
-	private function stringLiteral( string $text ): string {
566
-		return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"';
562
+	private function stringLiteral(string $text): string {
563
+		return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"';
567 564
 	}
568 565
 
569 566
 	/**
@@ -573,26 +570,26 @@  discard block
 block discarded – undo
573 570
 	 *
574 571
 	 * @return CachedEntityIds
575 572
 	 */
576
-	private function getOtherEntities( array $results ): CachedEntityIds {
573
+	private function getOtherEntities(array $results): CachedEntityIds {
577 574
 		$allResultBindings = [];
578 575
 		$metadatas = [];
579 576
 
580
-		foreach ( $results as $result ) {
577
+		foreach ($results as $result) {
581 578
 			$metadatas[] = $result->getMetadata();
582
-			$allResultBindings = array_merge( $allResultBindings, $result->getArray()['results']['bindings'] );
579
+			$allResultBindings = array_merge($allResultBindings, $result->getArray()['results']['bindings']);
583 580
 		}
584 581
 
585 582
 		$entityIds = array_map(
586
-			function ( $resultBindings ) {
583
+			function($resultBindings) {
587 584
 				$entityIRI = $resultBindings['otherEntity']['value'];
588
-				foreach ( $this->entityPrefixes as $entityPrefix ) {
589
-					$entityPrefixLength = strlen( $entityPrefix );
590
-					if ( substr( $entityIRI, 0, $entityPrefixLength ) === $entityPrefix ) {
585
+				foreach ($this->entityPrefixes as $entityPrefix) {
586
+					$entityPrefixLength = strlen($entityPrefix);
587
+					if (substr($entityIRI, 0, $entityPrefixLength) === $entityPrefix) {
591 588
 						try {
592 589
 							return $this->entityIdParser->parse(
593
-								substr( $entityIRI, $entityPrefixLength )
590
+								substr($entityIRI, $entityPrefixLength)
594 591
 							);
595
-						} catch ( EntityIdParsingException $e ) {
592
+						} catch (EntityIdParsingException $e) {
596 593
 							// fall through
597 594
 						}
598 595
 					}
@@ -606,8 +603,8 @@  discard block
 block discarded – undo
606 603
 		);
607 604
 
608 605
 		return new CachedEntityIds(
609
-			array_values( array_filter( array_unique( $entityIds ) ) ),
610
-			Metadata::merge( $metadatas )
606
+			array_values(array_filter(array_unique($entityIds))),
607
+			Metadata::merge($metadatas)
611 608
 		);
612 609
 	}
613 610
 
@@ -615,43 +612,43 @@  discard block
 block discarded – undo
615 612
 	 * @throws SparqlHelperException if the query times out or some other error occurs
616 613
 	 * @throws ConstraintParameterException if the $regex is invalid
617 614
 	 */
618
-	public function matchesRegularExpression( string $text, string $regex ): bool {
615
+	public function matchesRegularExpression(string $text, string $regex): bool {
619 616
 		// caching wrapper around matchesRegularExpressionWithSparql
620 617
 
621
-		$textHash = hash( 'sha256', $text );
618
+		$textHash = hash('sha256', $text);
622 619
 		$cacheKey = $this->cache->makeKey(
623 620
 			'WikibaseQualityConstraints', // extension
624 621
 			'regex', // action
625 622
 			'WDQS-Java', // regex flavor
626
-			hash( 'sha256', $regex )
623
+			hash('sha256', $regex)
627 624
 		);
628 625
 
629 626
 		$cacheMapArray = $this->cache->getWithSetCallback(
630 627
 			$cacheKey,
631 628
 			WANObjectCache::TTL_DAY,
632
-			function ( $cacheMapArray ) use ( $text, $regex, $textHash ) {
629
+			function($cacheMapArray) use ($text, $regex, $textHash) {
633 630
 				// Initialize the cache map if not set
634
-				if ( $cacheMapArray === false ) {
631
+				if ($cacheMapArray === false) {
635 632
 					$key = 'wikibase.quality.constraints.regex.cache.refresh.init';
636
-					$this->dataFactory->increment( $key );
633
+					$this->dataFactory->increment($key);
637 634
 					return [];
638 635
 				}
639 636
 
640 637
 				$key = 'wikibase.quality.constraints.regex.cache.refresh';
641
-				$this->dataFactory->increment( $key );
642
-				$cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $this->cacheMapSize );
643
-				if ( $cacheMap->has( $textHash ) ) {
638
+				$this->dataFactory->increment($key);
639
+				$cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $this->cacheMapSize);
640
+				if ($cacheMap->has($textHash)) {
644 641
 					$key = 'wikibase.quality.constraints.regex.cache.refresh.hit';
645
-					$this->dataFactory->increment( $key );
646
-					$cacheMap->get( $textHash ); // ping cache
642
+					$this->dataFactory->increment($key);
643
+					$cacheMap->get($textHash); // ping cache
647 644
 				} else {
648 645
 					$key = 'wikibase.quality.constraints.regex.cache.refresh.miss';
649
-					$this->dataFactory->increment( $key );
646
+					$this->dataFactory->increment($key);
650 647
 					try {
651
-						$matches = $this->matchesRegularExpressionWithSparql( $text, $regex );
652
-					} catch ( ConstraintParameterException $e ) {
653
-						$matches = $this->serializeConstraintParameterException( $e );
654
-					} catch ( SparqlHelperException $e ) {
648
+						$matches = $this->matchesRegularExpressionWithSparql($text, $regex);
649
+					} catch (ConstraintParameterException $e) {
650
+						$matches = $this->serializeConstraintParameterException($e);
651
+					} catch (SparqlHelperException $e) {
655 652
 						// don’t cache this
656 653
 						return $cacheMap->toArray();
657 654
 					}
@@ -675,42 +672,42 @@  discard block
 block discarded – undo
675 672
 			]
676 673
 		);
677 674
 
678
-		if ( isset( $cacheMapArray[$textHash] ) ) {
675
+		if (isset($cacheMapArray[$textHash])) {
679 676
 			$key = 'wikibase.quality.constraints.regex.cache.hit';
680
-			$this->dataFactory->increment( $key );
677
+			$this->dataFactory->increment($key);
681 678
 			$matches = $cacheMapArray[$textHash];
682
-			if ( is_bool( $matches ) ) {
679
+			if (is_bool($matches)) {
683 680
 				return $matches;
684
-			} elseif ( is_array( $matches ) &&
685
-				$matches['type'] == ConstraintParameterException::class ) {
686
-				throw $this->deserializeConstraintParameterException( $matches );
681
+			} elseif (is_array($matches) &&
682
+				$matches['type'] == ConstraintParameterException::class) {
683
+				throw $this->deserializeConstraintParameterException($matches);
687 684
 			} else {
688 685
 				throw new UnexpectedValueException(
689
-					'Value of unknown type in object cache (' .
690
-					'cache key: ' . $cacheKey . ', ' .
691
-					'cache map key: ' . $textHash . ', ' .
692
-					'value type: ' . get_debug_type( $matches ) . ')'
686
+					'Value of unknown type in object cache ('.
687
+					'cache key: '.$cacheKey.', '.
688
+					'cache map key: '.$textHash.', '.
689
+					'value type: '.get_debug_type($matches).')'
693 690
 				);
694 691
 			}
695 692
 		} else {
696 693
 			$key = 'wikibase.quality.constraints.regex.cache.miss';
697
-			$this->dataFactory->increment( $key );
698
-			return $this->matchesRegularExpressionWithSparql( $text, $regex );
694
+			$this->dataFactory->increment($key);
695
+			return $this->matchesRegularExpressionWithSparql($text, $regex);
699 696
 		}
700 697
 	}
701 698
 
702
-	private function serializeConstraintParameterException( ConstraintParameterException $cpe ): array {
699
+	private function serializeConstraintParameterException(ConstraintParameterException $cpe): array {
703 700
 		return [
704 701
 			'type' => ConstraintParameterException::class,
705
-			'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ),
702
+			'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()),
706 703
 		];
707 704
 	}
708 705
 
709
-	private function deserializeConstraintParameterException( array $serialization ): ConstraintParameterException {
706
+	private function deserializeConstraintParameterException(array $serialization): ConstraintParameterException {
710 707
 		$message = $this->violationMessageDeserializer->deserialize(
711 708
 			$serialization['violationMessage']
712 709
 		);
713
-		return new ConstraintParameterException( $message );
710
+		return new ConstraintParameterException($message);
714 711
 	}
715 712
 
716 713
 	/**
@@ -720,25 +717,25 @@  discard block
 block discarded – undo
720 717
 	 * @throws SparqlHelperException if the query times out or some other error occurs
721 718
 	 * @throws ConstraintParameterException if the $regex is invalid
722 719
 	 */
723
-	public function matchesRegularExpressionWithSparql( string $text, string $regex ): bool {
724
-		$textStringLiteral = $this->stringLiteral( $text );
725
-		$regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' );
720
+	public function matchesRegularExpressionWithSparql(string $text, string $regex): bool {
721
+		$textStringLiteral = $this->stringLiteral($text);
722
+		$regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$');
726 723
 
727 724
 		$query = <<<EOF
728 725
 SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {}
729 726
 EOF;
730 727
 
731
-		$result = $this->runQuery( $query, $this->primaryEndpoint, false );
728
+		$result = $this->runQuery($query, $this->primaryEndpoint, false);
732 729
 
733 730
 		$vars = $result->getArray()['results']['bindings'][0];
734
-		if ( array_key_exists( 'matches', $vars ) ) {
731
+		if (array_key_exists('matches', $vars)) {
735 732
 			// true or false ⇒ regex okay, text matches or not
736 733
 			return $vars['matches']['value'] === 'true';
737 734
 		} else {
738 735
 			// empty result: regex broken
739 736
 			throw new ConstraintParameterException(
740
-				( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) )
741
-					->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE )
737
+				(new ViolationMessage('wbqc-violation-message-parameter-regex'))
738
+					->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE)
742 739
 			);
743 740
 		}
744 741
 	}
@@ -746,14 +743,14 @@  discard block
 block discarded – undo
746 743
 	/**
747 744
 	 * Check whether the text content of an error response indicates a query timeout.
748 745
 	 */
749
-	public function isTimeout( string $responseContent ): bool {
750
-		$timeoutRegex = implode( '|', array_map(
751
-			static function ( $fqn ) {
752
-				return preg_quote( $fqn, '/' );
746
+	public function isTimeout(string $responseContent): bool {
747
+		$timeoutRegex = implode('|', array_map(
748
+			static function($fqn) {
749
+				return preg_quote($fqn, '/');
753 750
 			},
754 751
 			$this->timeoutExceptionClasses
755
-		) );
756
-		return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent );
752
+		));
753
+		return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent);
757 754
 	}
758 755
 
759 756
 	/**
@@ -765,17 +762,17 @@  discard block
 block discarded – undo
765 762
 	 * @return int|boolean the max-age (in seconds)
766 763
 	 * or a plain boolean if no max-age can be determined
767 764
 	 */
768
-	public function getCacheMaxAge( array $responseHeaders ) {
765
+	public function getCacheMaxAge(array $responseHeaders) {
769 766
 		if (
770
-			array_key_exists( 'x-cache-status', $responseHeaders ) &&
771
-			preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] )
767
+			array_key_exists('x-cache-status', $responseHeaders) &&
768
+			preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0])
772 769
 		) {
773 770
 			$maxage = [];
774 771
 			if (
775
-				array_key_exists( 'cache-control', $responseHeaders ) &&
776
-				preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage )
772
+				array_key_exists('cache-control', $responseHeaders) &&
773
+				preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage)
777 774
 			) {
778
-				return intval( $maxage[1] );
775
+				return intval($maxage[1]);
779 776
 			} else {
780 777
 				return true;
781 778
 			}
@@ -796,34 +793,34 @@  discard block
 block discarded – undo
796 793
 	 * or SparlHelper::EMPTY_RETRY_AFTER if there is an empty Retry-After
797 794
 	 * or SparlHelper::INVALID_RETRY_AFTER if there is something wrong with the format
798 795
 	 */
799
-	public function getThrottling( MWHttpRequest $request ) {
800
-		$retryAfterValue = $request->getResponseHeader( 'Retry-After' );
801
-		if ( $retryAfterValue === null ) {
796
+	public function getThrottling(MWHttpRequest $request) {
797
+		$retryAfterValue = $request->getResponseHeader('Retry-After');
798
+		if ($retryAfterValue === null) {
802 799
 			return self::NO_RETRY_AFTER;
803 800
 		}
804 801
 
805
-		$trimmedRetryAfterValue = trim( $retryAfterValue );
806
-		if ( $trimmedRetryAfterValue === '' ) {
802
+		$trimmedRetryAfterValue = trim($retryAfterValue);
803
+		if ($trimmedRetryAfterValue === '') {
807 804
 			return self::EMPTY_RETRY_AFTER;
808 805
 		}
809 806
 
810
-		if ( is_numeric( $trimmedRetryAfterValue ) ) {
811
-			$delaySeconds = (int)$trimmedRetryAfterValue;
812
-			if ( $delaySeconds >= 0 ) {
813
-				return $this->getTimestampInFuture( new DateInterval( 'PT' . $delaySeconds . 'S' ) );
807
+		if (is_numeric($trimmedRetryAfterValue)) {
808
+			$delaySeconds = (int) $trimmedRetryAfterValue;
809
+			if ($delaySeconds >= 0) {
810
+				return $this->getTimestampInFuture(new DateInterval('PT'.$delaySeconds.'S'));
814 811
 			}
815 812
 		} else {
816
-			$return = strtotime( $trimmedRetryAfterValue );
817
-			if ( $return !== false ) {
818
-				return new ConvertibleTimestamp( $return );
813
+			$return = strtotime($trimmedRetryAfterValue);
814
+			if ($return !== false) {
815
+				return new ConvertibleTimestamp($return);
819 816
 			}
820 817
 		}
821 818
 		return self::INVALID_RETRY_AFTER;
822 819
 	}
823 820
 
824
-	private function getTimestampInFuture( DateInterval $delta ): ConvertibleTimestamp {
821
+	private function getTimestampInFuture(DateInterval $delta): ConvertibleTimestamp {
825 822
 		$now = new ConvertibleTimestamp();
826
-		return new ConvertibleTimestamp( $now->timestamp->add( $delta ) );
823
+		return new ConvertibleTimestamp($now->timestamp->add($delta));
827 824
 	}
828 825
 
829 826
 	/**
@@ -838,64 +835,63 @@  discard block
 block discarded – undo
838 835
 	 *
839 836
 	 * @throws SparqlHelperException if the query times out or some other error occurs
840 837
 	 */
841
-	protected function runQuery( string $query, string $endpoint, bool $needsPrefixes = true ): CachedQueryResults {
842
-		if ( $this->throttlingLock->isLocked( self::EXPIRY_LOCK_ID ) ) {
843
-			$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' );
838
+	protected function runQuery(string $query, string $endpoint, bool $needsPrefixes = true): CachedQueryResults {
839
+		if ($this->throttlingLock->isLocked(self::EXPIRY_LOCK_ID)) {
840
+			$this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling');
844 841
 			throw new TooManySparqlRequestsException();
845 842
 		}
846 843
 
847
-		if ( $this->sparqlHasWikibaseSupport ) {
844
+		if ($this->sparqlHasWikibaseSupport) {
848 845
 			$needsPrefixes = false;
849 846
 		}
850 847
 
851
-		if ( $needsPrefixes ) {
852
-			$query = $this->prefixes . $query;
848
+		if ($needsPrefixes) {
849
+			$query = $this->prefixes.$query;
853 850
 		}
854
-		$query = "#wbqc\n" . $query;
851
+		$query = "#wbqc\n".$query;
855 852
 
856
-		$url = $endpoint . '?' . http_build_query(
853
+		$url = $endpoint.'?'.http_build_query(
857 854
 			[
858 855
 				'query' => $query,
859 856
 				'format' => 'json',
860 857
 				'maxQueryTimeMillis' => $this->maxQueryTimeMillis,
861 858
 			],
862
-			'', ini_get( 'arg_separator.output' ),
859
+			'', ini_get('arg_separator.output'),
863 860
 			// encode spaces with %20, not +
864 861
 			PHP_QUERY_RFC3986
865 862
 		);
866 863
 
867 864
 		$options = [
868 865
 			'method' => 'GET',
869
-			'timeout' => (int)round( ( $this->maxQueryTimeMillis + 1000 ) / 1000 ),
866
+			'timeout' => (int) round(($this->maxQueryTimeMillis + 1000) / 1000),
870 867
 			'connectTimeout' => 'default',
871 868
 			'userAgent' => $this->defaultUserAgent,
872 869
 		];
873
-		$request = $this->requestFactory->create( $url, $options, __METHOD__ );
874
-		$startTime = microtime( true );
870
+		$request = $this->requestFactory->create($url, $options, __METHOD__);
871
+		$startTime = microtime(true);
875 872
 		$requestStatus = $request->execute();
876
-		$endTime = microtime( true );
873
+		$endTime = microtime(true);
877 874
 		$this->dataFactory->timing(
878 875
 			'wikibase.quality.constraints.sparql.timing',
879
-			( $endTime - $startTime ) * 1000
876
+			($endTime - $startTime) * 1000
880 877
 		);
881 878
 
882
-		$this->guardAgainstTooManyRequestsError( $request );
879
+		$this->guardAgainstTooManyRequestsError($request);
883 880
 
884
-		$maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() );
885
-		if ( $maxAge ) {
886
-			$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' );
881
+		$maxAge = $this->getCacheMaxAge($request->getResponseHeaders());
882
+		if ($maxAge) {
883
+			$this->dataFactory->increment('wikibase.quality.constraints.sparql.cached');
887 884
 		}
888 885
 
889
-		if ( $requestStatus->isOK() ) {
886
+		if ($requestStatus->isOK()) {
890 887
 			$json = $request->getContent();
891
-			$jsonStatus = FormatJson::parse( $json, FormatJson::FORCE_ASSOC );
892
-			if ( $jsonStatus->isOK() ) {
888
+			$jsonStatus = FormatJson::parse($json, FormatJson::FORCE_ASSOC);
889
+			if ($jsonStatus->isOK()) {
893 890
 				return new CachedQueryResults(
894 891
 					$jsonStatus->getValue(),
895 892
 					Metadata::ofCachingMetadata(
896 893
 						$maxAge ?
897
-							CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) :
898
-							CachingMetadata::fresh()
894
+							CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh()
899 895
 					)
900 896
 				);
901 897
 			} else {
@@ -912,9 +908,9 @@  discard block
 block discarded – undo
912 908
 			// fall through to general error handling
913 909
 		}
914 910
 
915
-		$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' );
911
+		$this->dataFactory->increment('wikibase.quality.constraints.sparql.error');
916 912
 
917
-		if ( $this->isTimeout( $request->getContent() ) ) {
913
+		if ($this->isTimeout($request->getContent())) {
918 914
 			$this->dataFactory->increment(
919 915
 				'wikibase.quality.constraints.sparql.error.timeout'
920 916
 			);
@@ -929,29 +925,29 @@  discard block
 block discarded – undo
929 925
 	 * @param MWHttpRequest $request
930 926
 	 * @throws TooManySparqlRequestsException
931 927
 	 */
932
-	private function guardAgainstTooManyRequestsError( MWHttpRequest $request ): void {
933
-		if ( $request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS ) {
928
+	private function guardAgainstTooManyRequestsError(MWHttpRequest $request): void {
929
+		if ($request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS) {
934 930
 			return;
935 931
 		}
936 932
 
937 933
 		$fallbackBlockDuration = $this->sparqlThrottlingFallbackDuration;
938 934
 
939
-		if ( $fallbackBlockDuration < 0 ) {
940
-			throw new InvalidArgumentException( 'Fallback duration must be positive int but is: ' .
941
-				$fallbackBlockDuration );
935
+		if ($fallbackBlockDuration < 0) {
936
+			throw new InvalidArgumentException('Fallback duration must be positive int but is: '.
937
+				$fallbackBlockDuration);
942 938
 		}
943 939
 
944
-		$this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' );
945
-		$throttlingUntil = $this->getThrottling( $request );
946
-		if ( !( $throttlingUntil instanceof ConvertibleTimestamp ) ) {
947
-			$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid( $request );
940
+		$this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling');
941
+		$throttlingUntil = $this->getThrottling($request);
942
+		if (!($throttlingUntil instanceof ConvertibleTimestamp)) {
943
+			$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid($request);
948 944
 			$this->throttlingLock->lock(
949 945
 				self::EXPIRY_LOCK_ID,
950
-				$this->getTimestampInFuture( new DateInterval( 'PT' . $fallbackBlockDuration . 'S' ) )
946
+				$this->getTimestampInFuture(new DateInterval('PT'.$fallbackBlockDuration.'S'))
951 947
 			);
952 948
 		} else {
953
-			$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent( $throttlingUntil, $request );
954
-			$this->throttlingLock->lock( self::EXPIRY_LOCK_ID, $throttlingUntil );
949
+			$this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent($throttlingUntil, $request);
950
+			$this->throttlingLock->lock(self::EXPIRY_LOCK_ID, $throttlingUntil);
955 951
 		}
956 952
 		throw new TooManySparqlRequestsException();
957 953
 	}
Please login to merge, or discard this patch.
src/ConstraintRepositoryLookup.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 * @param string|false $dbName Database name ($domain for ILoadBalancer methods).
30 30
 	 * @param LoggerInterface|null $logger
31 31
 	 */
32
-	public function __construct( ILoadBalancer $lb, $dbName, ?LoggerInterface $logger = null ) {
32
+	public function __construct(ILoadBalancer $lb, $dbName, ?LoggerInterface $logger = null) {
33 33
 		$this->lb = $lb;
34 34
 		$this->dbName = $dbName;
35 35
 		$this->logger = $logger ?? new NullLogger();
@@ -40,22 +40,22 @@  discard block
 block discarded – undo
40 40
 	 *
41 41
 	 * @return Constraint[]
42 42
 	 */
43
-	public function queryConstraintsForProperty( NumericPropertyId $propertyId ) {
44
-		$dbr = $this->lb->getConnection( ILoadBalancer::DB_REPLICA, [], $this->dbName );
43
+	public function queryConstraintsForProperty(NumericPropertyId $propertyId) {
44
+		$dbr = $this->lb->getConnection(ILoadBalancer::DB_REPLICA, [], $this->dbName);
45 45
 
46 46
 		$results = $dbr->newSelectQueryBuilder()
47
-			->select( [
47
+			->select([
48 48
 				'constraint_type_qid',
49 49
 				'constraint_parameters',
50 50
 				'constraint_guid',
51 51
 				'pid',
52
-			] )
53
-			->from( 'wbqc_constraints' )
54
-			->where( [ 'pid' => $propertyId->getNumericId() ] )
55
-			->caller( __METHOD__ )
52
+			])
53
+			->from('wbqc_constraints')
54
+			->where(['pid' => $propertyId->getNumericId()])
55
+			->caller(__METHOD__)
56 56
 			->fetchResultSet();
57 57
 
58
-		return $this->convertToConstraints( $results );
58
+		return $this->convertToConstraints($results);
59 59
 	}
60 60
 
61 61
 	/**
@@ -63,25 +63,25 @@  discard block
 block discarded – undo
63 63
 	 *
64 64
 	 * @return Constraint[]
65 65
 	 */
66
-	private function convertToConstraints( IResultWrapper $results ) {
66
+	private function convertToConstraints(IResultWrapper $results) {
67 67
 		$constraints = [];
68
-		foreach ( $results as $result ) {
68
+		foreach ($results as $result) {
69 69
 			$constraintTypeItemId = $result->constraint_type_qid;
70
-			$constraintParameters = json_decode( $result->constraint_parameters, true );
70
+			$constraintParameters = json_decode($result->constraint_parameters, true);
71 71
 
72
-			if ( $constraintParameters === null ) {
72
+			if ($constraintParameters === null) {
73 73
 				// T171295
74
-				$this->logger->warning( 'Constraint {constraintId} has invalid constraint parameters.', [
74
+				$this->logger->warning('Constraint {constraintId} has invalid constraint parameters.', [
75 75
 					'method' => __METHOD__,
76 76
 					'constraintId' => $result->constraint_guid,
77 77
 					'constraintParameters' => $result->constraint_parameters,
78
-				] );
79
-				$constraintParameters = [ '@error' => [ /* unknown */ ] ];
78
+				]);
79
+				$constraintParameters = ['@error' => [/* unknown */]];
80 80
 			}
81 81
 
82 82
 			$constraints[] = new Constraint(
83 83
 				$result->constraint_guid,
84
-				NumericPropertyId::newFromNumber( $result->pid ),
84
+				NumericPropertyId::newFromNumber($result->pid),
85 85
 				$constraintTypeItemId,
86 86
 				$constraintParameters
87 87
 			);
Please login to merge, or discard this patch.