Completed
Push — master ( 913e4b...c8803e )
by
unknown
30s
created
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() {
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 ) {
101
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
102
-			return new CheckResult( $context, $constraint, CheckResult::STATUS_DEPRECATED );
100
+	public function checkConstraint(Context $context, Constraint $constraint) {
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 ) {
260
+	public function checkConstraintParameters(Constraint $constraint) {
262 261
 		// no parameters
263 262
 		return [];
264 263
 	}
Please login to merge, or discard this patch.