@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @codeCoverageIgnore This method is purely declarative. |
78 | 78 | */ |
79 | 79 | public function getDefaultContextTypes() { |
80 | - return [ Context::TYPE_STATEMENT ]; |
|
80 | + return [Context::TYPE_STATEMENT]; |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -89,21 +89,21 @@ discard block |
||
89 | 89 | * @return CheckResult |
90 | 90 | * @throws \ConfigException |
91 | 91 | */ |
92 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
93 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
94 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
92 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
93 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
94 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
95 | 95 | } |
96 | 96 | $snak = $context->getSnak(); |
97 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
97 | + if (!$snak instanceof PropertyValueSnak) { |
|
98 | 98 | // nothing to check |
99 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
99 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
100 | 100 | } |
101 | - if ( $snak->getDataValue()->getType() !== 'wikibase-entityid' ) { |
|
101 | + if ($snak->getDataValue()->getType() !== 'wikibase-entityid') { |
|
102 | 102 | // wrong data type |
103 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
104 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ) |
|
105 | - ->withDataValueType( 'wikibase-entityid' ); |
|
106 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
103 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
104 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM) |
|
105 | + ->withDataValueType('wikibase-entityid'); |
|
106 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
107 | 107 | } |
108 | 108 | /** @var EntityId $subjectId */ |
109 | 109 | $subjectId = $context->getEntity()->getId(); |
@@ -112,11 +112,11 @@ discard block |
||
112 | 112 | /** @var Statement[] $subjectStatements */ |
113 | 113 | $subjectStatements = $context->getEntity()->getStatements()->toArray(); |
114 | 114 | /** @var Statement[] $objectStatements */ |
115 | - $objectStatements = $this->entityLookup->getEntity( $objectId )->getStatements()->toArray(); |
|
115 | + $objectStatements = $this->entityLookup->getEntity($objectId)->getStatements()->toArray(); |
|
116 | 116 | /** @var String[] $startPropertyIds */ |
117 | - $startPropertyIds = $this->config->get( self::CONFIG_VARIABLE_START_PROPERTY_IDS ); |
|
117 | + $startPropertyIds = $this->config->get(self::CONFIG_VARIABLE_START_PROPERTY_IDS); |
|
118 | 118 | /** @var String[] $endPropertyIds */ |
119 | - $endPropertyIds = $this->config->get( self::CONFIG_VARIABLE_END_PROPERTY_IDS ); |
|
119 | + $endPropertyIds = $this->config->get(self::CONFIG_VARIABLE_END_PROPERTY_IDS); |
|
120 | 120 | $subjectStartValue = $this->getExtremeValue( |
121 | 121 | $startPropertyIds, |
122 | 122 | $subjectStatements, |
@@ -138,15 +138,15 @@ discard block |
||
138 | 138 | 'end' |
139 | 139 | ); |
140 | 140 | if ( |
141 | - $this->rangeCheckerHelper->getComparison( $subjectStartValue, $subjectEndValue ) <= 0 && |
|
142 | - $this->rangeCheckerHelper->getComparison( $objectStartValue, $objectEndValue ) <= 0 && ( |
|
143 | - $this->rangeCheckerHelper->getComparison( $subjectEndValue, $objectStartValue ) < 0 || |
|
144 | - $this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectStartValue ) < 0 |
|
141 | + $this->rangeCheckerHelper->getComparison($subjectStartValue, $subjectEndValue) <= 0 && |
|
142 | + $this->rangeCheckerHelper->getComparison($objectStartValue, $objectEndValue) <= 0 && ( |
|
143 | + $this->rangeCheckerHelper->getComparison($subjectEndValue, $objectStartValue) < 0 || |
|
144 | + $this->rangeCheckerHelper->getComparison($objectEndValue, $subjectStartValue) < 0 |
|
145 | 145 | ) |
146 | 146 | ) { |
147 | 147 | if ( |
148 | 148 | $subjectEndValue == null || |
149 | - $this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectEndValue ) < 0 |
|
149 | + $this->rangeCheckerHelper->getComparison($objectEndValue, $subjectEndValue) < 0 |
|
150 | 150 | ) { |
151 | 151 | $earlierEntityId = $objectId; |
152 | 152 | $minEndValue = $objectEndValue; |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | $message = null; |
170 | 170 | $status = CheckResult::STATUS_COMPLIANCE; |
171 | 171 | } |
172 | - return new CheckResult( $context, $constraint, [], $status, $message ); |
|
172 | + return new CheckResult($context, $constraint, [], $status, $message); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -179,19 +179,19 @@ discard block |
||
179 | 179 | * |
180 | 180 | * @return DataValue|null |
181 | 181 | */ |
182 | - private function getExtremeValue( $extremePropertyIds, $statements, $startOrEnd ) { |
|
183 | - if ( $startOrEnd !== 'start' && $startOrEnd !== 'end' ) { |
|
184 | - throw new \InvalidArgumentException( '$startOrEnd must be \'start\' or \'end\'.' ); |
|
182 | + private function getExtremeValue($extremePropertyIds, $statements, $startOrEnd) { |
|
183 | + if ($startOrEnd !== 'start' && $startOrEnd !== 'end') { |
|
184 | + throw new \InvalidArgumentException('$startOrEnd must be \'start\' or \'end\'.'); |
|
185 | 185 | } |
186 | 186 | $extremeValue = null; |
187 | - foreach ( $extremePropertyIds as $extremePropertyId ) { |
|
188 | - $statementList = new StatementList( $statements ); |
|
189 | - $extremeStatements = $statementList->getByPropertyId( new PropertyId( $extremePropertyId ) ); |
|
187 | + foreach ($extremePropertyIds as $extremePropertyId) { |
|
188 | + $statementList = new StatementList($statements); |
|
189 | + $extremeStatements = $statementList->getByPropertyId(new PropertyId($extremePropertyId)); |
|
190 | 190 | /** @var Statement $extremeStatement */ |
191 | - foreach ( $extremeStatements as $extremeStatement ) { |
|
192 | - if ( $extremeStatement->getRank() !== Statement::RANK_DEPRECATED ) { |
|
191 | + foreach ($extremeStatements as $extremeStatement) { |
|
192 | + if ($extremeStatement->getRank() !== Statement::RANK_DEPRECATED) { |
|
193 | 193 | $snak = $extremeStatement->getMainSnak(); |
194 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
194 | + if (!$snak instanceof PropertyValueSnak) { |
|
195 | 195 | return null; |
196 | 196 | } else { |
197 | 197 | $comparison = $this->rangeCheckerHelper->getComparison( |
@@ -200,8 +200,8 @@ discard block |
||
200 | 200 | ); |
201 | 201 | if ( |
202 | 202 | $extremeValue === null || |
203 | - ( $startOrEnd === 'start' && $comparison < 0 ) || |
|
204 | - ( $startOrEnd === 'end' && $comparison > 0 ) |
|
203 | + ($startOrEnd === 'start' && $comparison < 0) || |
|
204 | + ($startOrEnd === 'end' && $comparison > 0) |
|
205 | 205 | ) { |
206 | 206 | $extremeValue = $snak->getDataValue(); |
207 | 207 | } |
@@ -231,17 +231,16 @@ discard block |
||
231 | 231 | DataValue $maxStartValue |
232 | 232 | ) { |
233 | 233 | $messageKey = $earlierEntityId === $subjectId ? |
234 | - 'wbqc-violation-message-contemporary-subject-earlier' : |
|
235 | - 'wbqc-violation-message-contemporary-value-earlier'; |
|
236 | - return ( new ViolationMessage( $messageKey ) ) |
|
237 | - ->withEntityId( $subjectId, Role::SUBJECT ) |
|
238 | - ->withEntityId( $propertyId, Role::PREDICATE ) |
|
239 | - ->withEntityId( $objectId, Role::OBJECT ) |
|
240 | - ->withDataValue( $minEndValue, Role::OBJECT ) |
|
241 | - ->withDataValue( $maxStartValue, Role::OBJECT ); |
|
234 | + 'wbqc-violation-message-contemporary-subject-earlier' : 'wbqc-violation-message-contemporary-value-earlier'; |
|
235 | + return (new ViolationMessage($messageKey)) |
|
236 | + ->withEntityId($subjectId, Role::SUBJECT) |
|
237 | + ->withEntityId($propertyId, Role::PREDICATE) |
|
238 | + ->withEntityId($objectId, Role::OBJECT) |
|
239 | + ->withDataValue($minEndValue, Role::OBJECT) |
|
240 | + ->withDataValue($maxStartValue, Role::OBJECT); |
|
242 | 241 | } |
243 | 242 | |
244 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
243 | + public function checkConstraintParameters(Constraint $constraint) { |
|
245 | 244 | // no parameters |
246 | 245 | return []; |
247 | 246 | } |