Completed
Push — master ( f09e1e...277d81 )
by
unknown
03:55 queued 01:25
created
src/ConstraintCheck/Checker/ContemporaryChecker.php 1 patch
Spacing   +42 added lines, -43 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	 * @codeCoverageIgnore This method is purely declarative.
79 79
 	 */
80 80
 	public function getDefaultContextTypes() {
81
-		return [ Context::TYPE_STATEMENT ];
81
+		return [Context::TYPE_STATEMENT];
82 82
 	}
83 83
 
84 84
 	/**
@@ -90,30 +90,30 @@  discard block
 block discarded – undo
90 90
 	 * @return CheckResult
91 91
 	 * @throws \ConfigException
92 92
 	 */
93
-	public function checkConstraint( Context $context, Constraint $constraint ) {
94
-		if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
95
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED );
93
+	public function checkConstraint(Context $context, Constraint $constraint) {
94
+		if ($context->getSnakRank() === Statement::RANK_DEPRECATED) {
95
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED);
96 96
 		}
97 97
 		$snak = $context->getSnak();
98
-		if ( !$snak instanceof PropertyValueSnak ) {
98
+		if (!$snak instanceof PropertyValueSnak) {
99 99
 			// nothing to check
100
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE );
100
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE);
101 101
 		}
102
-		if ( $snak->getDataValue()->getType() !== 'wikibase-entityid' ) {
102
+		if ($snak->getDataValue()->getType() !== 'wikibase-entityid') {
103 103
 			// wrong data type
104
-			$message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) )
105
-				->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM )
106
-				->withDataValueType( 'wikibase-entityid' );
107
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message );
104
+			$message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type'))
105
+				->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM)
106
+				->withDataValueType('wikibase-entityid');
107
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message);
108 108
 		}
109 109
 
110 110
 		/** @var EntityId $objectId */
111 111
 		$objectId = $snak->getDataValue()->getEntityId();
112
-		$objectItem = $this->entityLookup->getEntity( $objectId );
113
-		if ( !( $objectItem instanceof StatementListProvider ) ) {
112
+		$objectItem = $this->entityLookup->getEntity($objectId);
113
+		if (!($objectItem instanceof StatementListProvider)) {
114 114
 			// object was deleted/doesn't exist
115
-			$message = new ViolationMessage( 'wbqc-violation-message-value-entity-must-exist' );
116
-			return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message );
115
+			$message = new ViolationMessage('wbqc-violation-message-value-entity-must-exist');
116
+			return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message);
117 117
 		}
118 118
 		/** @var Statement[] $objectStatements */
119 119
 		$objectStatements = $objectItem->getStatements()->toArray();
@@ -123,9 +123,9 @@  discard block
 block discarded – undo
123 123
 		/** @var Statement[] $subjectStatements */
124 124
 		$subjectStatements = $context->getEntity()->getStatements()->toArray();
125 125
 		/** @var String[] $startPropertyIds */
126
-		$startPropertyIds = $this->config->get( self::CONFIG_VARIABLE_START_PROPERTY_IDS );
126
+		$startPropertyIds = $this->config->get(self::CONFIG_VARIABLE_START_PROPERTY_IDS);
127 127
 		/** @var String[] $endPropertyIds */
128
-		$endPropertyIds = $this->config->get( self::CONFIG_VARIABLE_END_PROPERTY_IDS );
128
+		$endPropertyIds = $this->config->get(self::CONFIG_VARIABLE_END_PROPERTY_IDS);
129 129
 		$subjectStartValue = $this->getExtremeValue(
130 130
 			$startPropertyIds,
131 131
 			$subjectStatements,
@@ -147,15 +147,15 @@  discard block
 block discarded – undo
147 147
 			'end'
148 148
 		);
149 149
 		if (
150
-			$this->rangeCheckerHelper->getComparison( $subjectStartValue, $subjectEndValue ) <= 0 &&
151
-			$this->rangeCheckerHelper->getComparison( $objectStartValue, $objectEndValue ) <= 0 && (
152
-				$this->rangeCheckerHelper->getComparison( $subjectEndValue, $objectStartValue ) < 0 ||
153
-				$this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectStartValue ) < 0
150
+			$this->rangeCheckerHelper->getComparison($subjectStartValue, $subjectEndValue) <= 0 &&
151
+			$this->rangeCheckerHelper->getComparison($objectStartValue, $objectEndValue) <= 0 && (
152
+				$this->rangeCheckerHelper->getComparison($subjectEndValue, $objectStartValue) < 0 ||
153
+				$this->rangeCheckerHelper->getComparison($objectEndValue, $subjectStartValue) < 0
154 154
 			)
155 155
 		) {
156 156
 			if (
157 157
 				$subjectEndValue == null ||
158
-				$this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectEndValue ) < 0
158
+				$this->rangeCheckerHelper->getComparison($objectEndValue, $subjectEndValue) < 0
159 159
 			) {
160 160
 				$earlierEntityId = $objectId;
161 161
 				$minEndValue = $objectEndValue;
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 			$message = null;
179 179
 			$status = CheckResult::STATUS_COMPLIANCE;
180 180
 		}
181
-		return new CheckResult( $context, $constraint, [], $status, $message );
181
+		return new CheckResult($context, $constraint, [], $status, $message);
182 182
 	}
183 183
 
184 184
 	/**
@@ -188,19 +188,19 @@  discard block
 block discarded – undo
188 188
 	 *
189 189
 	 * @return DataValue|null
190 190
 	 */
191
-	private function getExtremeValue( $extremePropertyIds, $statements, $startOrEnd ) {
192
-		if ( $startOrEnd !== 'start' && $startOrEnd !== 'end' ) {
193
-			throw new \InvalidArgumentException( '$startOrEnd must be \'start\' or \'end\'.' );
191
+	private function getExtremeValue($extremePropertyIds, $statements, $startOrEnd) {
192
+		if ($startOrEnd !== 'start' && $startOrEnd !== 'end') {
193
+			throw new \InvalidArgumentException('$startOrEnd must be \'start\' or \'end\'.');
194 194
 		}
195 195
 		$extremeValue = null;
196
-		foreach ( $extremePropertyIds as $extremePropertyId ) {
197
-			$statementList = new StatementList( $statements );
198
-			$extremeStatements = $statementList->getByPropertyId( new PropertyId( $extremePropertyId ) );
196
+		foreach ($extremePropertyIds as $extremePropertyId) {
197
+			$statementList = new StatementList($statements);
198
+			$extremeStatements = $statementList->getByPropertyId(new PropertyId($extremePropertyId));
199 199
 			/** @var Statement $extremeStatement */
200
-			foreach ( $extremeStatements as $extremeStatement ) {
201
-				if ( $extremeStatement->getRank() !== Statement::RANK_DEPRECATED ) {
200
+			foreach ($extremeStatements as $extremeStatement) {
201
+				if ($extremeStatement->getRank() !== Statement::RANK_DEPRECATED) {
202 202
 					$snak = $extremeStatement->getMainSnak();
203
-					if ( !$snak instanceof PropertyValueSnak ) {
203
+					if (!$snak instanceof PropertyValueSnak) {
204 204
 						return null;
205 205
 					} else {
206 206
 						$comparison = $this->rangeCheckerHelper->getComparison(
@@ -209,8 +209,8 @@  discard block
 block discarded – undo
209 209
 						);
210 210
 						if (
211 211
 							$extremeValue === null ||
212
-							( $startOrEnd === 'start' && $comparison < 0 ) ||
213
-							( $startOrEnd === 'end' && $comparison > 0 )
212
+							($startOrEnd === 'start' && $comparison < 0) ||
213
+							($startOrEnd === 'end' && $comparison > 0)
214 214
 						) {
215 215
 							$extremeValue = $snak->getDataValue();
216 216
 						}
@@ -240,17 +240,16 @@  discard block
 block discarded – undo
240 240
 		DataValue $maxStartValue
241 241
 	) {
242 242
 		$messageKey = $earlierEntityId === $subjectId ?
243
-			'wbqc-violation-message-contemporary-subject-earlier' :
244
-			'wbqc-violation-message-contemporary-value-earlier';
245
-		return ( new ViolationMessage( $messageKey ) )
246
-			->withEntityId( $subjectId, Role::SUBJECT )
247
-			->withEntityId( $propertyId, Role::PREDICATE )
248
-			->withEntityId( $objectId, Role::OBJECT )
249
-			->withDataValue( $minEndValue, Role::OBJECT )
250
-			->withDataValue( $maxStartValue, Role::OBJECT );
243
+			'wbqc-violation-message-contemporary-subject-earlier' : 'wbqc-violation-message-contemporary-value-earlier';
244
+		return (new ViolationMessage($messageKey))
245
+			->withEntityId($subjectId, Role::SUBJECT)
246
+			->withEntityId($propertyId, Role::PREDICATE)
247
+			->withEntityId($objectId, Role::OBJECT)
248
+			->withDataValue($minEndValue, Role::OBJECT)
249
+			->withDataValue($maxStartValue, Role::OBJECT);
251 250
 	}
252 251
 
253
-	public function checkConstraintParameters( Constraint $constraint ) {
252
+	public function checkConstraintParameters(Constraint $constraint) {
254 253
 		// no parameters
255 254
 		return [];
256 255
 	}
Please login to merge, or discard this patch.