@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | return self::ALL_ENTITY_TYPES_SUPPORTED; |
55 | 55 | } |
56 | 56 | |
57 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
57 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
58 | 58 | $constraintParameters = $constraint->getConstraintParameters(); |
59 | 59 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
60 | 60 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | $constraintTypeItemId |
64 | 64 | ); |
65 | 65 | |
66 | - if ( in_array( $context->getType(), $allowedContextTypes ) ) { |
|
66 | + if (in_array($context->getType(), $allowedContextTypes)) { |
|
67 | 67 | return new CheckResult( |
68 | 68 | $context->getCursor(), |
69 | 69 | $constraint, |
@@ -76,15 +76,15 @@ discard block |
||
76 | 76 | $constraint, |
77 | 77 | [], |
78 | 78 | CheckResult::STATUS_VIOLATION, |
79 | - ( new ViolationMessage( 'wbqc-violation-message-property-scope' ) ) |
|
80 | - ->withEntityId( $context->getSnak()->getPropertyId() ) |
|
81 | - ->withPropertyScope( $context->getType() ) |
|
82 | - ->withPropertyScopeList( $allowedContextTypes ) |
|
79 | + (new ViolationMessage('wbqc-violation-message-property-scope')) |
|
80 | + ->withEntityId($context->getSnak()->getPropertyId()) |
|
81 | + ->withPropertyScope($context->getType()) |
|
82 | + ->withPropertyScopeList($allowedContextTypes) |
|
83 | 83 | ); |
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
87 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
87 | + public function checkConstraintParameters(Constraint $constraint) { |
|
88 | 88 | $constraintParameters = $constraint->getConstraintParameters(); |
89 | 89 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
90 | 90 | $exceptions = []; |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | $constraintParameters, |
94 | 94 | $constraintTypeItemId |
95 | 95 | ); |
96 | - } catch ( ConstraintParameterException $e ) { |
|
96 | + } catch (ConstraintParameterException $e) { |
|
97 | 97 | $exceptions[] = $e; |
98 | 98 | } |
99 | 99 | return $exceptions; |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @codeCoverageIgnore This method is purely declarative. |
80 | 80 | */ |
81 | 81 | public function getDefaultContextTypes() { |
82 | - return [ Context::TYPE_STATEMENT ]; |
|
82 | + return [Context::TYPE_STATEMENT]; |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** @codeCoverageIgnore This method is purely declarative. */ |
@@ -96,31 +96,31 @@ discard block |
||
96 | 96 | * @return CheckResult |
97 | 97 | * @throws \ConfigException |
98 | 98 | */ |
99 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
100 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
101 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
99 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
100 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
101 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
102 | 102 | } |
103 | 103 | $snak = $context->getSnak(); |
104 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
104 | + if (!$snak instanceof PropertyValueSnak) { |
|
105 | 105 | // nothing to check |
106 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
106 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | $dataValue = $snak->getDataValue(); |
110 | - if ( !$dataValue instanceof EntityIdValue ) { |
|
110 | + if (!$dataValue instanceof EntityIdValue) { |
|
111 | 111 | // wrong data type |
112 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
113 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ) |
|
114 | - ->withDataValueType( 'wikibase-entityid' ); |
|
115 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
112 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
113 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM) |
|
114 | + ->withDataValueType('wikibase-entityid'); |
|
115 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | $objectId = $dataValue->getEntityId(); |
119 | - $objectItem = $this->entityLookup->getEntity( $objectId ); |
|
120 | - if ( !( $objectItem instanceof StatementListProvider ) ) { |
|
119 | + $objectItem = $this->entityLookup->getEntity($objectId); |
|
120 | + if (!($objectItem instanceof StatementListProvider)) { |
|
121 | 121 | // object was deleted/doesn't exist |
122 | - $message = new ViolationMessage( 'wbqc-violation-message-value-entity-must-exist' ); |
|
123 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
122 | + $message = new ViolationMessage('wbqc-violation-message-value-entity-must-exist'); |
|
123 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
124 | 124 | } |
125 | 125 | /** @var Statement[] $objectStatements */ |
126 | 126 | $objectStatements = $objectItem->getStatements()->toArray(); |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | $subjectId = $context->getEntity()->getId(); |
129 | 129 | $subjectStatements = $context->getEntity()->getStatements()->toArray(); |
130 | 130 | /** @var String[] $startPropertyIds */ |
131 | - $startPropertyIds = $this->config->get( self::CONFIG_VARIABLE_START_PROPERTY_IDS ); |
|
131 | + $startPropertyIds = $this->config->get(self::CONFIG_VARIABLE_START_PROPERTY_IDS); |
|
132 | 132 | /** @var String[] $endPropertyIds */ |
133 | - $endPropertyIds = $this->config->get( self::CONFIG_VARIABLE_END_PROPERTY_IDS ); |
|
133 | + $endPropertyIds = $this->config->get(self::CONFIG_VARIABLE_END_PROPERTY_IDS); |
|
134 | 134 | $subjectStartValue = $this->getExtremeValue( |
135 | 135 | $startPropertyIds, |
136 | 136 | $subjectStatements, |
@@ -152,15 +152,15 @@ discard block |
||
152 | 152 | 'end' |
153 | 153 | ); |
154 | 154 | if ( |
155 | - $this->rangeCheckerHelper->getComparison( $subjectStartValue, $subjectEndValue ) <= 0 && |
|
156 | - $this->rangeCheckerHelper->getComparison( $objectStartValue, $objectEndValue ) <= 0 && ( |
|
157 | - $this->rangeCheckerHelper->getComparison( $subjectEndValue, $objectStartValue ) < 0 || |
|
158 | - $this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectStartValue ) < 0 |
|
155 | + $this->rangeCheckerHelper->getComparison($subjectStartValue, $subjectEndValue) <= 0 && |
|
156 | + $this->rangeCheckerHelper->getComparison($objectStartValue, $objectEndValue) <= 0 && ( |
|
157 | + $this->rangeCheckerHelper->getComparison($subjectEndValue, $objectStartValue) < 0 || |
|
158 | + $this->rangeCheckerHelper->getComparison($objectEndValue, $subjectStartValue) < 0 |
|
159 | 159 | ) |
160 | 160 | ) { |
161 | 161 | if ( |
162 | 162 | $subjectEndValue == null || |
163 | - $this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectEndValue ) < 0 |
|
163 | + $this->rangeCheckerHelper->getComparison($objectEndValue, $subjectEndValue) < 0 |
|
164 | 164 | ) { |
165 | 165 | $earlierEntityId = $objectId; |
166 | 166 | $minEndValue = $objectEndValue; |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | $message = null; |
184 | 184 | $status = CheckResult::STATUS_COMPLIANCE; |
185 | 185 | } |
186 | - return new CheckResult( $context, $constraint, [], $status, $message ); |
|
186 | + return new CheckResult($context, $constraint, [], $status, $message); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -193,19 +193,19 @@ discard block |
||
193 | 193 | * |
194 | 194 | * @return DataValue|null |
195 | 195 | */ |
196 | - private function getExtremeValue( $extremePropertyIds, $statements, $startOrEnd ) { |
|
197 | - if ( $startOrEnd !== 'start' && $startOrEnd !== 'end' ) { |
|
198 | - throw new \InvalidArgumentException( '$startOrEnd must be \'start\' or \'end\'.' ); |
|
196 | + private function getExtremeValue($extremePropertyIds, $statements, $startOrEnd) { |
|
197 | + if ($startOrEnd !== 'start' && $startOrEnd !== 'end') { |
|
198 | + throw new \InvalidArgumentException('$startOrEnd must be \'start\' or \'end\'.'); |
|
199 | 199 | } |
200 | 200 | $extremeValue = null; |
201 | - foreach ( $extremePropertyIds as $extremePropertyId ) { |
|
202 | - $statementList = new StatementList( ...$statements ); |
|
203 | - $extremeStatements = $statementList->getByPropertyId( new PropertyId( $extremePropertyId ) ); |
|
201 | + foreach ($extremePropertyIds as $extremePropertyId) { |
|
202 | + $statementList = new StatementList(...$statements); |
|
203 | + $extremeStatements = $statementList->getByPropertyId(new PropertyId($extremePropertyId)); |
|
204 | 204 | /** @var Statement $extremeStatement */ |
205 | - foreach ( $extremeStatements as $extremeStatement ) { |
|
206 | - if ( $extremeStatement->getRank() !== Statement::RANK_DEPRECATED ) { |
|
205 | + foreach ($extremeStatements as $extremeStatement) { |
|
206 | + if ($extremeStatement->getRank() !== Statement::RANK_DEPRECATED) { |
|
207 | 207 | $snak = $extremeStatement->getMainSnak(); |
208 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
208 | + if (!$snak instanceof PropertyValueSnak) { |
|
209 | 209 | return null; |
210 | 210 | } else { |
211 | 211 | $comparison = $this->rangeCheckerHelper->getComparison( |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | ); |
215 | 215 | if ( |
216 | 216 | $extremeValue === null || |
217 | - ( $startOrEnd === 'start' && $comparison < 0 ) || |
|
218 | - ( $startOrEnd === 'end' && $comparison > 0 ) |
|
217 | + ($startOrEnd === 'start' && $comparison < 0) || |
|
218 | + ($startOrEnd === 'end' && $comparison > 0) |
|
219 | 219 | ) { |
220 | 220 | $extremeValue = $snak->getDataValue(); |
221 | 221 | } |
@@ -245,17 +245,16 @@ discard block |
||
245 | 245 | DataValue $maxStartValue |
246 | 246 | ) { |
247 | 247 | $messageKey = $earlierEntityId === $subjectId ? |
248 | - 'wbqc-violation-message-contemporary-subject-earlier' : |
|
249 | - 'wbqc-violation-message-contemporary-value-earlier'; |
|
250 | - return ( new ViolationMessage( $messageKey ) ) |
|
251 | - ->withEntityId( $subjectId, Role::SUBJECT ) |
|
252 | - ->withEntityId( $propertyId, Role::PREDICATE ) |
|
253 | - ->withEntityId( $objectId, Role::OBJECT ) |
|
254 | - ->withDataValue( $minEndValue, Role::OBJECT ) |
|
255 | - ->withDataValue( $maxStartValue, Role::OBJECT ); |
|
248 | + 'wbqc-violation-message-contemporary-subject-earlier' : 'wbqc-violation-message-contemporary-value-earlier'; |
|
249 | + return (new ViolationMessage($messageKey)) |
|
250 | + ->withEntityId($subjectId, Role::SUBJECT) |
|
251 | + ->withEntityId($propertyId, Role::PREDICATE) |
|
252 | + ->withEntityId($objectId, Role::OBJECT) |
|
253 | + ->withDataValue($minEndValue, Role::OBJECT) |
|
254 | + ->withDataValue($maxStartValue, Role::OBJECT); |
|
256 | 255 | } |
257 | 256 | |
258 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
257 | + public function checkConstraintParameters(Constraint $constraint) { |
|
259 | 258 | // no parameters |
260 | 259 | return []; |
261 | 260 | } |
@@ -46,23 +46,22 @@ discard block |
||
46 | 46 | return self::ALL_ENTITY_TYPES_SUPPORTED; |
47 | 47 | } |
48 | 48 | |
49 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
49 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
50 | 50 | $snak = $context->getSnak(); |
51 | 51 | |
52 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
52 | + if (!$snak instanceof PropertyValueSnak) { |
|
53 | 53 | // nothing to check |
54 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
54 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
55 | 55 | } |
56 | 56 | |
57 | - $violationMessage = $this->checkSnak( $snak ); |
|
57 | + $violationMessage = $this->checkSnak($snak); |
|
58 | 58 | |
59 | 59 | return new CheckResult( |
60 | 60 | $context, |
61 | 61 | $constraint, |
62 | 62 | [], |
63 | 63 | $violationMessage === null ? |
64 | - CheckResult::STATUS_COMPLIANCE : |
|
65 | - CheckResult::STATUS_VIOLATION, |
|
64 | + CheckResult::STATUS_COMPLIANCE : CheckResult::STATUS_VIOLATION, |
|
66 | 65 | $violationMessage |
67 | 66 | ); |
68 | 67 | } |
@@ -71,23 +70,23 @@ discard block |
||
71 | 70 | * @param PropertyValueSnak $snak |
72 | 71 | * @return ViolationMessage|null |
73 | 72 | */ |
74 | - public function checkSnak( PropertyValueSnak $snak ) { |
|
73 | + public function checkSnak(PropertyValueSnak $snak) { |
|
75 | 74 | $dataValue = $snak->getDataValue(); |
76 | 75 | |
77 | - if ( $dataValue instanceof DecimalValue ) { |
|
78 | - if ( !$this->isInteger( $dataValue ) ) { |
|
79 | - return $this->getViolationMessage( 'wbqc-violation-message-integer', $snak ); |
|
76 | + if ($dataValue instanceof DecimalValue) { |
|
77 | + if (!$this->isInteger($dataValue)) { |
|
78 | + return $this->getViolationMessage('wbqc-violation-message-integer', $snak); |
|
80 | 79 | } |
81 | - } elseif ( $dataValue instanceof UnboundedQuantityValue ) { |
|
82 | - if ( !$this->isInteger( $dataValue->getAmount() ) ) { |
|
83 | - return $this->getViolationMessage( 'wbqc-violation-message-integer', $snak ); |
|
80 | + } elseif ($dataValue instanceof UnboundedQuantityValue) { |
|
81 | + if (!$this->isInteger($dataValue->getAmount())) { |
|
82 | + return $this->getViolationMessage('wbqc-violation-message-integer', $snak); |
|
84 | 83 | } elseif ( |
85 | 84 | $dataValue instanceof QuantityValue && ( |
86 | - !$this->isInteger( $dataValue->getLowerBound() ) || |
|
87 | - !$this->isInteger( $dataValue->getUpperBound() ) |
|
85 | + !$this->isInteger($dataValue->getLowerBound()) || |
|
86 | + !$this->isInteger($dataValue->getUpperBound()) |
|
88 | 87 | ) |
89 | 88 | ) { |
90 | - return $this->getViolationMessage( 'wbqc-violation-message-integer-bounds', $snak ); |
|
89 | + return $this->getViolationMessage('wbqc-violation-message-integer-bounds', $snak); |
|
91 | 90 | } |
92 | 91 | } |
93 | 92 | |
@@ -98,7 +97,7 @@ discard block |
||
98 | 97 | * @param DecimalValue $decimalValue |
99 | 98 | * @return bool |
100 | 99 | */ |
101 | - private function isInteger( DecimalValue $decimalValue ) { |
|
100 | + private function isInteger(DecimalValue $decimalValue) { |
|
102 | 101 | return $decimalValue->getTrimmed()->getFractionalPart() === ''; |
103 | 102 | } |
104 | 103 | |
@@ -107,13 +106,13 @@ discard block |
||
107 | 106 | * @param PropertyValueSnak $snak |
108 | 107 | * @return ViolationMessage |
109 | 108 | */ |
110 | - private function getViolationMessage( $messageKey, PropertyValueSnak $snak ) { |
|
111 | - return ( new ViolationMessage( $messageKey ) ) |
|
112 | - ->withEntityId( $snak->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
113 | - ->withDataValue( $snak->getDataValue() ); |
|
109 | + private function getViolationMessage($messageKey, PropertyValueSnak $snak) { |
|
110 | + return (new ViolationMessage($messageKey)) |
|
111 | + ->withEntityId($snak->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
112 | + ->withDataValue($snak->getDataValue()); |
|
114 | 113 | } |
115 | 114 | |
116 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
115 | + public function checkConstraintParameters(Constraint $constraint) { |
|
117 | 116 | // no parameters |
118 | 117 | return []; |
119 | 118 | } |
@@ -41,16 +41,16 @@ |
||
41 | 41 | return self::ALL_ENTITY_TYPES_SUPPORTED; |
42 | 42 | } |
43 | 43 | |
44 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
45 | - if ( $context->getType() === Context::TYPE_REFERENCE ) { |
|
46 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
44 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
45 | + if ($context->getType() === Context::TYPE_REFERENCE) { |
|
46 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
47 | 47 | } else { |
48 | - $message = new ViolationMessage( 'wbqc-violation-message-reference' ); |
|
49 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
48 | + $message = new ViolationMessage('wbqc-violation-message-reference'); |
|
49 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
53 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
53 | + public function checkConstraintParameters(Constraint $constraint) { |
|
54 | 54 | // no parameters |
55 | 55 | return []; |
56 | 56 | } |
@@ -44,17 +44,17 @@ discard block |
||
44 | 44 | return self::ALL_ENTITY_TYPES_SUPPORTED; |
45 | 45 | } |
46 | 46 | |
47 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
47 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
48 | 48 | $snak = $context->getSnak(); |
49 | 49 | |
50 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
50 | + if (!$snak instanceof PropertyValueSnak) { |
|
51 | 51 | // nothing to check |
52 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
52 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
53 | 53 | } |
54 | 54 | |
55 | - if ( $snak->getDataValue() instanceof QuantityValue ) { |
|
56 | - $message = ( new ViolationMessage( 'wbqc-violation-message-noBounds' ) ) |
|
57 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ); |
|
55 | + if ($snak->getDataValue() instanceof QuantityValue) { |
|
56 | + $message = (new ViolationMessage('wbqc-violation-message-noBounds')) |
|
57 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY); |
|
58 | 58 | return new CheckResult( |
59 | 59 | $context, |
60 | 60 | $constraint, |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | ); |
65 | 65 | } |
66 | 66 | |
67 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
67 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
68 | 68 | } |
69 | 69 | |
70 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
70 | + public function checkConstraintParameters(Constraint $constraint) { |
|
71 | 71 | // no parameters |
72 | 72 | return []; |
73 | 73 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @codeCoverageIgnore This method is purely declarative. |
31 | 31 | */ |
32 | 32 | public function getDefaultContextTypes() { |
33 | - return [ Context::TYPE_STATEMENT ]; |
|
33 | + return [Context::TYPE_STATEMENT]; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** @codeCoverageIgnore This method is purely declarative. */ |
@@ -38,12 +38,12 @@ discard block |
||
38 | 38 | return self::ALL_ENTITY_TYPES_SUPPORTED; |
39 | 39 | } |
40 | 40 | |
41 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
41 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
42 | 42 | $referenceList = $context->getSnakStatement()->getReferences(); |
43 | 43 | |
44 | - if ( $referenceList->isEmpty() ) { |
|
45 | - $message = ( new ViolationMessage( 'wbqc-violation-message-citationNeeded' ) ) |
|
46 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ); |
|
44 | + if ($referenceList->isEmpty()) { |
|
45 | + $message = (new ViolationMessage('wbqc-violation-message-citationNeeded')) |
|
46 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY); |
|
47 | 47 | return new CheckResult( |
48 | 48 | $context, |
49 | 49 | $constraint, |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | ); |
54 | 54 | } |
55 | 55 | |
56 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
56 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
57 | 57 | } |
58 | 58 | |
59 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
59 | + public function checkConstraintParameters(Constraint $constraint) { |
|
60 | 60 | // no parameters |
61 | 61 | return []; |
62 | 62 | } |
@@ -41,16 +41,16 @@ |
||
41 | 41 | return self::ALL_ENTITY_TYPES_SUPPORTED; |
42 | 42 | } |
43 | 43 | |
44 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
45 | - if ( $context->getType() === Context::TYPE_STATEMENT ) { |
|
46 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
44 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
45 | + if ($context->getType() === Context::TYPE_STATEMENT) { |
|
46 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
47 | 47 | } else { |
48 | - $message = new ViolationMessage( 'wbqc-violation-message-valueOnly' ); |
|
49 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
48 | + $message = new ViolationMessage('wbqc-violation-message-valueOnly'); |
|
49 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
53 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
53 | + public function checkConstraintParameters(Constraint $constraint) { |
|
54 | 54 | // no parameters |
55 | 55 | return []; |
56 | 56 | } |
@@ -56,9 +56,9 @@ discard block |
||
56 | 56 | return self::ALL_ENTITY_TYPES_SUPPORTED; |
57 | 57 | } |
58 | 58 | |
59 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
60 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
61 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
59 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
60 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
61 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | $constraintParameters = $constraint->getConstraintParameters(); |
@@ -70,10 +70,10 @@ discard block |
||
70 | 70 | 'item' => $entityTypes->getEntityTypes(), |
71 | 71 | ]; |
72 | 72 | |
73 | - if ( !in_array( $context->getEntity()->getType(), $entityTypes->getEntityTypes() ) ) { |
|
74 | - $message = ( new ViolationMessage( 'wbqc-violation-message-entityType' ) ) |
|
75 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
76 | - ->withEntityIdList( $entityTypes->getEntityTypeItemIds(), Role::CONSTRAINT_PARAMETER_VALUE ); |
|
73 | + if (!in_array($context->getEntity()->getType(), $entityTypes->getEntityTypes())) { |
|
74 | + $message = (new ViolationMessage('wbqc-violation-message-entityType')) |
|
75 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
76 | + ->withEntityIdList($entityTypes->getEntityTypeItemIds(), Role::CONSTRAINT_PARAMETER_VALUE); |
|
77 | 77 | |
78 | 78 | return new CheckResult( |
79 | 79 | $context, |
@@ -84,10 +84,10 @@ discard block |
||
84 | 84 | ); |
85 | 85 | } |
86 | 86 | |
87 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
87 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
88 | 88 | } |
89 | 89 | |
90 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
90 | + public function checkConstraintParameters(Constraint $constraint) { |
|
91 | 91 | $constraintParameters = $constraint->getConstraintParameters(); |
92 | 92 | $exceptions = []; |
93 | 93 | try { |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $constraintParameters, |
96 | 96 | $constraint->getConstraintTypeItemId() |
97 | 97 | ); |
98 | - } catch ( ConstraintParameterException $e ) { |
|
98 | + } catch (ConstraintParameterException $e) { |
|
99 | 99 | $exceptions[] = $e; |
100 | 100 | } |
101 | 101 | return $exceptions; |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | callable $defaultResultsPerEntity = null |
144 | 144 | ) { |
145 | 145 | $checkResults = []; |
146 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
146 | + $entity = $this->entityLookup->getEntity($entityId); |
|
147 | 147 | |
148 | - if ( $entity instanceof StatementListProvidingEntity ) { |
|
149 | - $startTime = microtime( true ); |
|
148 | + if ($entity instanceof StatementListProvidingEntity) { |
|
149 | + $startTime = microtime(true); |
|
150 | 150 | |
151 | 151 | $checkResults = $this->checkEveryStatement( |
152 | 152 | $entity, |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | $defaultResultsPerContext |
155 | 155 | ); |
156 | 156 | |
157 | - $endTime = microtime( true ); |
|
157 | + $endTime = microtime(true); |
|
158 | 158 | |
159 | - if ( $constraintIds === null ) { // only log full constraint checks |
|
159 | + if ($constraintIds === null) { // only log full constraint checks |
|
160 | 160 | $this->loggingHelper->logConstraintCheckOnEntity( |
161 | 161 | $entityId, |
162 | 162 | $checkResults, |
@@ -166,11 +166,11 @@ discard block |
||
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
169 | - if ( $defaultResultsPerEntity !== null ) { |
|
170 | - $checkResults = array_merge( $defaultResultsPerEntity( $entityId ), $checkResults ); |
|
169 | + if ($defaultResultsPerEntity !== null) { |
|
170 | + $checkResults = array_merge($defaultResultsPerEntity($entityId), $checkResults); |
|
171 | 171 | } |
172 | 172 | |
173 | - return $this->sortResult( $checkResults ); |
|
173 | + return $this->sortResult($checkResults); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -192,19 +192,19 @@ discard block |
||
192 | 192 | callable $defaultResults = null |
193 | 193 | ) { |
194 | 194 | |
195 | - $parsedGuid = $this->statementGuidParser->parse( $guid ); |
|
195 | + $parsedGuid = $this->statementGuidParser->parse($guid); |
|
196 | 196 | $entityId = $parsedGuid->getEntityId(); |
197 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
198 | - if ( $entity instanceof StatementListProvidingEntity ) { |
|
199 | - $statement = $entity->getStatements()->getFirstStatementWithGuid( $guid ); |
|
200 | - if ( $statement ) { |
|
197 | + $entity = $this->entityLookup->getEntity($entityId); |
|
198 | + if ($entity instanceof StatementListProvidingEntity) { |
|
199 | + $statement = $entity->getStatements()->getFirstStatementWithGuid($guid); |
|
200 | + if ($statement) { |
|
201 | 201 | $result = $this->checkStatement( |
202 | 202 | $entity, |
203 | 203 | $statement, |
204 | 204 | $constraintIds, |
205 | 205 | $defaultResults |
206 | 206 | ); |
207 | - $output = $this->sortResult( $result ); |
|
207 | + $output = $this->sortResult($result); |
|
208 | 208 | return $output; |
209 | 209 | } |
210 | 210 | } |
@@ -212,8 +212,8 @@ discard block |
||
212 | 212 | return []; |
213 | 213 | } |
214 | 214 | |
215 | - private function getValidContextTypes( Constraint $constraint ) { |
|
216 | - if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
215 | + private function getValidContextTypes(Constraint $constraint) { |
|
216 | + if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
217 | 217 | return [ |
218 | 218 | Context::TYPE_STATEMENT, |
219 | 219 | Context::TYPE_QUALIFIER, |
@@ -221,25 +221,25 @@ discard block |
||
221 | 221 | ]; |
222 | 222 | } |
223 | 223 | |
224 | - return array_keys( array_filter( |
|
224 | + return array_keys(array_filter( |
|
225 | 225 | $this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedContextTypes(), |
226 | - static function ( $resultStatus ) { |
|
226 | + static function($resultStatus) { |
|
227 | 227 | return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE; |
228 | 228 | } |
229 | - ) ); |
|
229 | + )); |
|
230 | 230 | } |
231 | 231 | |
232 | - private function getValidEntityTypes( Constraint $constraint ) { |
|
233 | - if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
234 | - return array_keys( ConstraintChecker::ALL_ENTITY_TYPES_SUPPORTED ); |
|
232 | + private function getValidEntityTypes(Constraint $constraint) { |
|
233 | + if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
234 | + return array_keys(ConstraintChecker::ALL_ENTITY_TYPES_SUPPORTED); |
|
235 | 235 | } |
236 | 236 | |
237 | - return array_keys( array_filter( |
|
237 | + return array_keys(array_filter( |
|
238 | 238 | $this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedEntityTypes(), |
239 | - static function ( $resultStatus ) { |
|
239 | + static function($resultStatus) { |
|
240 | 240 | return $resultStatus !== CheckResult::STATUS_NOT_IN_SCOPE; |
241 | 241 | } |
242 | - ) ); |
|
242 | + )); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -250,33 +250,33 @@ discard block |
||
250 | 250 | * |
251 | 251 | * @return ConstraintParameterException[] |
252 | 252 | */ |
253 | - private function checkCommonConstraintParameters( Constraint $constraint ) { |
|
253 | + private function checkCommonConstraintParameters(Constraint $constraint) { |
|
254 | 254 | $constraintParameters = $constraint->getConstraintParameters(); |
255 | 255 | try { |
256 | - $this->constraintParameterParser->checkError( $constraintParameters ); |
|
257 | - } catch ( ConstraintParameterException $e ) { |
|
258 | - return [ $e ]; |
|
256 | + $this->constraintParameterParser->checkError($constraintParameters); |
|
257 | + } catch (ConstraintParameterException $e) { |
|
258 | + return [$e]; |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | $problems = []; |
262 | 262 | try { |
263 | - $this->constraintParameterParser->parseExceptionParameter( $constraintParameters ); |
|
264 | - } catch ( ConstraintParameterException $e ) { |
|
263 | + $this->constraintParameterParser->parseExceptionParameter($constraintParameters); |
|
264 | + } catch (ConstraintParameterException $e) { |
|
265 | 265 | $problems[] = $e; |
266 | 266 | } |
267 | 267 | try { |
268 | - $this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters ); |
|
269 | - } catch ( ConstraintParameterException $e ) { |
|
268 | + $this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters); |
|
269 | + } catch (ConstraintParameterException $e) { |
|
270 | 270 | $problems[] = $e; |
271 | 271 | } |
272 | 272 | try { |
273 | 273 | $this->constraintParameterParser->parseConstraintScopeParameters( |
274 | 274 | $constraintParameters, |
275 | 275 | $constraint->getConstraintTypeItemId(), |
276 | - $this->getValidContextTypes( $constraint ), |
|
277 | - $this->getValidEntityTypes( $constraint ) |
|
276 | + $this->getValidContextTypes($constraint), |
|
277 | + $this->getValidEntityTypes($constraint) |
|
278 | 278 | ); |
279 | - } catch ( ConstraintParameterException $e ) { |
|
279 | + } catch (ConstraintParameterException $e) { |
|
280 | 280 | $problems[] = $e; |
281 | 281 | } |
282 | 282 | return $problems; |
@@ -289,16 +289,16 @@ discard block |
||
289 | 289 | * @return ConstraintParameterException[][] first level indexed by constraint ID, |
290 | 290 | * second level like checkConstraintParametersOnConstraintId (but without possibility of null) |
291 | 291 | */ |
292 | - public function checkConstraintParametersOnPropertyId( PropertyId $propertyId ) { |
|
293 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
292 | + public function checkConstraintParametersOnPropertyId(PropertyId $propertyId) { |
|
293 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
294 | 294 | $result = []; |
295 | 295 | |
296 | - foreach ( $constraints as $constraint ) { |
|
297 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
296 | + foreach ($constraints as $constraint) { |
|
297 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
298 | 298 | |
299 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
299 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
300 | 300 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
301 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
301 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | $result[$constraint->getConstraintId()] = $problems; |
@@ -315,18 +315,18 @@ discard block |
||
315 | 315 | * @return ConstraintParameterException[]|null list of constraint parameter exceptions |
316 | 316 | * (empty means all parameters okay), or null if constraint is not found |
317 | 317 | */ |
318 | - public function checkConstraintParametersOnConstraintId( $constraintId ) { |
|
319 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
318 | + public function checkConstraintParametersOnConstraintId($constraintId) { |
|
319 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
320 | 320 | '@phan-var PropertyId $propertyId'; |
321 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
321 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
322 | 322 | |
323 | - foreach ( $constraints as $constraint ) { |
|
324 | - if ( $constraint->getConstraintId() === $constraintId ) { |
|
325 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
323 | + foreach ($constraints as $constraint) { |
|
324 | + if ($constraint->getConstraintId() === $constraintId) { |
|
325 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
326 | 326 | |
327 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
327 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
328 | 328 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
329 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
329 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | return $problems; |
@@ -351,14 +351,14 @@ discard block |
||
351 | 351 | $result = []; |
352 | 352 | |
353 | 353 | /** @var Statement $statement */ |
354 | - foreach ( $entity->getStatements() as $statement ) { |
|
355 | - $result = array_merge( $result, |
|
354 | + foreach ($entity->getStatements() as $statement) { |
|
355 | + $result = array_merge($result, |
|
356 | 356 | $this->checkStatement( |
357 | 357 | $entity, |
358 | 358 | $statement, |
359 | 359 | $constraintIds, |
360 | 360 | $defaultResultsPerContext |
361 | - ) ); |
|
361 | + )); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | return $result; |
@@ -380,32 +380,32 @@ discard block |
||
380 | 380 | ) { |
381 | 381 | $result = []; |
382 | 382 | |
383 | - $result = array_merge( $result, |
|
383 | + $result = array_merge($result, |
|
384 | 384 | $this->checkConstraintsForMainSnak( |
385 | 385 | $entity, |
386 | 386 | $statement, |
387 | 387 | $constraintIds, |
388 | 388 | $defaultResultsPerContext |
389 | - ) ); |
|
389 | + )); |
|
390 | 390 | |
391 | - if ( $this->checkQualifiers ) { |
|
392 | - $result = array_merge( $result, |
|
391 | + if ($this->checkQualifiers) { |
|
392 | + $result = array_merge($result, |
|
393 | 393 | $this->checkConstraintsForQualifiers( |
394 | 394 | $entity, |
395 | 395 | $statement, |
396 | 396 | $constraintIds, |
397 | 397 | $defaultResultsPerContext |
398 | - ) ); |
|
398 | + )); |
|
399 | 399 | } |
400 | 400 | |
401 | - if ( $this->checkReferences ) { |
|
402 | - $result = array_merge( $result, |
|
401 | + if ($this->checkReferences) { |
|
402 | + $result = array_merge($result, |
|
403 | 403 | $this->checkConstraintsForReferences( |
404 | 404 | $entity, |
405 | 405 | $statement, |
406 | 406 | $constraintIds, |
407 | 407 | $defaultResultsPerContext |
408 | - ) ); |
|
408 | + )); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | return $result; |
@@ -420,12 +420,12 @@ discard block |
||
420 | 420 | * @param string[]|null $constraintIds |
421 | 421 | * @return Constraint[] |
422 | 422 | */ |
423 | - private function getConstraintsToUse( PropertyId $propertyId, array $constraintIds = null ) { |
|
424 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
425 | - if ( $constraintIds !== null ) { |
|
423 | + private function getConstraintsToUse(PropertyId $propertyId, array $constraintIds = null) { |
|
424 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
425 | + if ($constraintIds !== null) { |
|
426 | 426 | $constraintsToUse = []; |
427 | - foreach ( $constraints as $constraint ) { |
|
428 | - if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) { |
|
427 | + foreach ($constraints as $constraint) { |
|
428 | + if (in_array($constraint->getConstraintId(), $constraintIds)) { |
|
429 | 429 | $constraintsToUse[] = $constraint; |
430 | 430 | } |
431 | 431 | } |
@@ -449,18 +449,18 @@ discard block |
||
449 | 449 | array $constraintIds = null, |
450 | 450 | callable $defaultResults = null |
451 | 451 | ) { |
452 | - $context = new MainSnakContext( $entity, $statement ); |
|
452 | + $context = new MainSnakContext($entity, $statement); |
|
453 | 453 | $constraints = $this->getConstraintsToUse( |
454 | 454 | $statement->getPropertyId(), |
455 | 455 | $constraintIds |
456 | 456 | ); |
457 | - $result = $defaultResults !== null ? $defaultResults( $context ) : []; |
|
457 | + $result = $defaultResults !== null ? $defaultResults($context) : []; |
|
458 | 458 | |
459 | - foreach ( $constraints as $constraint ) { |
|
459 | + foreach ($constraints as $constraint) { |
|
460 | 460 | $parameters = $constraint->getConstraintParameters(); |
461 | 461 | try { |
462 | - $exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters ); |
|
463 | - } catch ( ConstraintParameterException $e ) { |
|
462 | + $exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters); |
|
463 | + } catch (ConstraintParameterException $e) { |
|
464 | 464 | $result[] = new CheckResult( |
465 | 465 | $context, |
466 | 466 | $constraint, |
@@ -470,13 +470,13 @@ discard block |
||
470 | 470 | continue; |
471 | 471 | } |
472 | 472 | |
473 | - if ( in_array( $entity->getId(), $exceptions ) ) { |
|
474 | - $message = new ViolationMessage( 'wbqc-violation-message-exception' ); |
|
475 | - $result[] = new CheckResult( $context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message ); |
|
473 | + if (in_array($entity->getId(), $exceptions)) { |
|
474 | + $message = new ViolationMessage('wbqc-violation-message-exception'); |
|
475 | + $result[] = new CheckResult($context, $constraint, [], CheckResult::STATUS_EXCEPTION, $message); |
|
476 | 476 | continue; |
477 | 477 | } |
478 | 478 | |
479 | - $result[] = $this->getCheckResultFor( $context, $constraint ); |
|
479 | + $result[] = $this->getCheckResultFor($context, $constraint); |
|
480 | 480 | } |
481 | 481 | |
482 | 482 | return $result; |
@@ -498,24 +498,24 @@ discard block |
||
498 | 498 | ) { |
499 | 499 | $result = []; |
500 | 500 | |
501 | - if ( in_array( |
|
501 | + if (in_array( |
|
502 | 502 | $statement->getPropertyId()->getSerialization(), |
503 | 503 | $this->propertiesWithViolatingQualifiers |
504 | - ) ) { |
|
504 | + )) { |
|
505 | 505 | return $result; |
506 | 506 | } |
507 | 507 | |
508 | - foreach ( $statement->getQualifiers() as $qualifier ) { |
|
509 | - $qualifierContext = new QualifierContext( $entity, $statement, $qualifier ); |
|
510 | - if ( $defaultResultsPerContext !== null ) { |
|
511 | - $result = array_merge( $result, $defaultResultsPerContext( $qualifierContext ) ); |
|
508 | + foreach ($statement->getQualifiers() as $qualifier) { |
|
509 | + $qualifierContext = new QualifierContext($entity, $statement, $qualifier); |
|
510 | + if ($defaultResultsPerContext !== null) { |
|
511 | + $result = array_merge($result, $defaultResultsPerContext($qualifierContext)); |
|
512 | 512 | } |
513 | 513 | $qualifierConstraints = $this->getConstraintsToUse( |
514 | 514 | $qualifierContext->getSnak()->getPropertyId(), |
515 | 515 | $constraintIds |
516 | 516 | ); |
517 | - foreach ( $qualifierConstraints as $qualifierConstraint ) { |
|
518 | - $result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint ); |
|
517 | + foreach ($qualifierConstraints as $qualifierConstraint) { |
|
518 | + $result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint); |
|
519 | 519 | } |
520 | 520 | } |
521 | 521 | |
@@ -539,19 +539,19 @@ discard block |
||
539 | 539 | $result = []; |
540 | 540 | |
541 | 541 | /** @var Reference $reference */ |
542 | - foreach ( $statement->getReferences() as $reference ) { |
|
543 | - foreach ( $reference->getSnaks() as $snak ) { |
|
542 | + foreach ($statement->getReferences() as $reference) { |
|
543 | + foreach ($reference->getSnaks() as $snak) { |
|
544 | 544 | $referenceContext = new ReferenceContext( |
545 | 545 | $entity, $statement, $reference, $snak |
546 | 546 | ); |
547 | - if ( $defaultResultsPerContext !== null ) { |
|
548 | - $result = array_merge( $result, $defaultResultsPerContext( $referenceContext ) ); |
|
547 | + if ($defaultResultsPerContext !== null) { |
|
548 | + $result = array_merge($result, $defaultResultsPerContext($referenceContext)); |
|
549 | 549 | } |
550 | 550 | $referenceConstraints = $this->getConstraintsToUse( |
551 | 551 | $referenceContext->getSnak()->getPropertyId(), |
552 | 552 | $constraintIds |
553 | 553 | ); |
554 | - foreach ( $referenceConstraints as $referenceConstraint ) { |
|
554 | + foreach ($referenceConstraints as $referenceConstraint) { |
|
555 | 555 | $result[] = $this->getCheckResultFor( |
556 | 556 | $referenceContext, |
557 | 557 | $referenceConstraint |
@@ -570,20 +570,20 @@ discard block |
||
570 | 570 | * @throws InvalidArgumentException |
571 | 571 | * @return CheckResult |
572 | 572 | */ |
573 | - private function getCheckResultFor( Context $context, Constraint $constraint ) { |
|
574 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
573 | + private function getCheckResultFor(Context $context, Constraint $constraint) { |
|
574 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
575 | 575 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
576 | - $result = $this->handleScope( $checker, $context, $constraint ); |
|
576 | + $result = $this->handleScope($checker, $context, $constraint); |
|
577 | 577 | |
578 | - if ( $result !== null ) { |
|
579 | - $this->addMetadata( $context, $result ); |
|
578 | + if ($result !== null) { |
|
579 | + $this->addMetadata($context, $result); |
|
580 | 580 | return $result; |
581 | 581 | } |
582 | 582 | |
583 | - $startTime = microtime( true ); |
|
583 | + $startTime = microtime(true); |
|
584 | 584 | try { |
585 | - $result = $checker->checkConstraint( $context, $constraint ); |
|
586 | - } catch ( ConstraintParameterException $e ) { |
|
585 | + $result = $checker->checkConstraint($context, $constraint); |
|
586 | + } catch (ConstraintParameterException $e) { |
|
587 | 587 | $result = new CheckResult( |
588 | 588 | $context, |
589 | 589 | $constraint, |
@@ -591,28 +591,28 @@ discard block |
||
591 | 591 | CheckResult::STATUS_BAD_PARAMETERS, |
592 | 592 | $e->getViolationMessage() |
593 | 593 | ); |
594 | - } catch ( SparqlHelperException $e ) { |
|
595 | - $message = new ViolationMessage( 'wbqc-violation-message-sparql-error' ); |
|
596 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, $message ); |
|
594 | + } catch (SparqlHelperException $e) { |
|
595 | + $message = new ViolationMessage('wbqc-violation-message-sparql-error'); |
|
596 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, $message); |
|
597 | 597 | } |
598 | - $endTime = microtime( true ); |
|
598 | + $endTime = microtime(true); |
|
599 | 599 | |
600 | - $this->addMetadata( $context, $result ); |
|
600 | + $this->addMetadata($context, $result); |
|
601 | 601 | |
602 | - $this->downgradeResultStatus( $context, $result ); |
|
602 | + $this->downgradeResultStatus($context, $result); |
|
603 | 603 | |
604 | 604 | $this->loggingHelper->logConstraintCheck( |
605 | 605 | $context, |
606 | 606 | $constraint, |
607 | 607 | $result, |
608 | - get_class( $checker ), |
|
608 | + get_class($checker), |
|
609 | 609 | $endTime - $startTime, |
610 | 610 | __METHOD__ |
611 | 611 | ); |
612 | 612 | |
613 | 613 | return $result; |
614 | 614 | } else { |
615 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
615 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
616 | 616 | } |
617 | 617 | } |
618 | 618 | |
@@ -621,84 +621,84 @@ discard block |
||
621 | 621 | Context $context, |
622 | 622 | Constraint $constraint |
623 | 623 | ): ?CheckResult { |
624 | - $validContextTypes = $this->getValidContextTypes( $constraint ); |
|
625 | - $validEntityTypes = $this->getValidEntityTypes( $constraint ); |
|
624 | + $validContextTypes = $this->getValidContextTypes($constraint); |
|
625 | + $validEntityTypes = $this->getValidEntityTypes($constraint); |
|
626 | 626 | try { |
627 | - [ $checkedContextTypes, $checkedEntityTypes ] = $this->constraintParameterParser->parseConstraintScopeParameters( |
|
627 | + [$checkedContextTypes, $checkedEntityTypes] = $this->constraintParameterParser->parseConstraintScopeParameters( |
|
628 | 628 | $constraint->getConstraintParameters(), |
629 | 629 | $constraint->getConstraintTypeItemId(), |
630 | 630 | $validContextTypes, |
631 | 631 | $validEntityTypes |
632 | 632 | ); |
633 | - } catch ( ConstraintParameterException $e ) { |
|
634 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
633 | + } catch (ConstraintParameterException $e) { |
|
634 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
635 | 635 | } |
636 | 636 | |
637 | - if ( $checkedContextTypes === null ) { |
|
637 | + if ($checkedContextTypes === null) { |
|
638 | 638 | $checkedContextTypes = $checker->getDefaultContextTypes(); |
639 | 639 | } |
640 | 640 | $contextType = $context->getType(); |
641 | - if ( !in_array( $contextType, $checkedContextTypes ) ) { |
|
642 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null ); |
|
641 | + if (!in_array($contextType, $checkedContextTypes)) { |
|
642 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null); |
|
643 | 643 | } |
644 | - if ( $checker->getSupportedContextTypes()[$contextType] === CheckResult::STATUS_TODO ) { |
|
645 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
644 | + if ($checker->getSupportedContextTypes()[$contextType] === CheckResult::STATUS_TODO) { |
|
645 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
646 | 646 | } |
647 | 647 | |
648 | - if ( $checkedEntityTypes === null ) { |
|
648 | + if ($checkedEntityTypes === null) { |
|
649 | 649 | $checkedEntityTypes = $validEntityTypes; |
650 | 650 | } |
651 | 651 | $entityType = $context->getEntity()->getType(); |
652 | - if ( !in_array( $entityType, $checkedEntityTypes ) ) { |
|
653 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null ); |
|
652 | + if (!in_array($entityType, $checkedEntityTypes)) { |
|
653 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE, null); |
|
654 | 654 | } |
655 | - if ( $checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO ) { |
|
656 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_TODO, null ); |
|
655 | + if ($checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO) { |
|
656 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_TODO, null); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | return null; |
660 | 660 | } |
661 | 661 | |
662 | - private function addMetadata( Context $context, CheckResult $result ) { |
|
663 | - $result->withMetadata( Metadata::merge( [ |
|
662 | + private function addMetadata(Context $context, CheckResult $result) { |
|
663 | + $result->withMetadata(Metadata::merge([ |
|
664 | 664 | $result->getMetadata(), |
665 | - Metadata::ofDependencyMetadata( DependencyMetadata::merge( [ |
|
666 | - DependencyMetadata::ofEntityId( $context->getEntity()->getId() ), |
|
667 | - DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ), |
|
668 | - ] ) ), |
|
669 | - ] ) ); |
|
665 | + Metadata::ofDependencyMetadata(DependencyMetadata::merge([ |
|
666 | + DependencyMetadata::ofEntityId($context->getEntity()->getId()), |
|
667 | + DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()), |
|
668 | + ])), |
|
669 | + ])); |
|
670 | 670 | } |
671 | 671 | |
672 | - private function downgradeResultStatus( Context $context, CheckResult &$result ) { |
|
672 | + private function downgradeResultStatus(Context $context, CheckResult &$result) { |
|
673 | 673 | $constraint = $result->getConstraint(); |
674 | 674 | try { |
675 | 675 | $constraintStatus = $this->constraintParameterParser |
676 | - ->parseConstraintStatusParameter( $constraint->getConstraintParameters() ); |
|
677 | - } catch ( ConstraintParameterException $e ) { |
|
678 | - $result = new CheckResult( $context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
676 | + ->parseConstraintStatusParameter($constraint->getConstraintParameters()); |
|
677 | + } catch (ConstraintParameterException $e) { |
|
678 | + $result = new CheckResult($context, $constraint, [], CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
679 | 679 | $constraintStatus = null; |
680 | 680 | } |
681 | - if ( $constraintStatus === null ) { |
|
681 | + if ($constraintStatus === null) { |
|
682 | 682 | // downgrade violation to warning |
683 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
684 | - $result->setStatus( CheckResult::STATUS_WARNING ); |
|
683 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
684 | + $result->setStatus(CheckResult::STATUS_WARNING); |
|
685 | 685 | } |
686 | - } elseif ( $constraintStatus === 'suggestion' ) { |
|
686 | + } elseif ($constraintStatus === 'suggestion') { |
|
687 | 687 | // downgrade violation to suggestion |
688 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
689 | - $result->setStatus( CheckResult::STATUS_SUGGESTION ); |
|
688 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
689 | + $result->setStatus(CheckResult::STATUS_SUGGESTION); |
|
690 | 690 | } |
691 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
691 | + $result->addParameter('constraint_status', $constraintStatus); |
|
692 | 692 | } else { |
693 | - if ( $constraintStatus !== 'mandatory' ) { |
|
693 | + if ($constraintStatus !== 'mandatory') { |
|
694 | 694 | // @codeCoverageIgnoreStart |
695 | 695 | throw new LogicException( |
696 | - "Unknown constraint status '$constraintStatus', " . |
|
696 | + "Unknown constraint status '$constraintStatus', ". |
|
697 | 697 | "only known statuses are 'mandatory' and 'suggestion'" |
698 | 698 | ); |
699 | 699 | // @codeCoverageIgnoreEnd |
700 | 700 | } |
701 | - $result->addParameter( 'constraint_status', $constraintStatus ); |
|
701 | + $result->addParameter('constraint_status', $constraintStatus); |
|
702 | 702 | } |
703 | 703 | } |
704 | 704 | |
@@ -707,12 +707,12 @@ discard block |
||
707 | 707 | * |
708 | 708 | * @return CheckResult[] |
709 | 709 | */ |
710 | - private function sortResult( array $result ) { |
|
711 | - if ( count( $result ) < 2 ) { |
|
710 | + private function sortResult(array $result) { |
|
711 | + if (count($result) < 2) { |
|
712 | 712 | return $result; |
713 | 713 | } |
714 | 714 | |
715 | - $sortFunction = static function ( CheckResult $a, CheckResult $b ) { |
|
715 | + $sortFunction = static function(CheckResult $a, CheckResult $b) { |
|
716 | 716 | $orderNum = 0; |
717 | 717 | $order = [ |
718 | 718 | CheckResult::STATUS_BAD_PARAMETERS => $orderNum++, |
@@ -729,55 +729,55 @@ discard block |
||
729 | 729 | $statusA = $a->getStatus(); |
730 | 730 | $statusB = $b->getStatus(); |
731 | 731 | |
732 | - $orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ]; |
|
733 | - $orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ]; |
|
732 | + $orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other']; |
|
733 | + $orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other']; |
|
734 | 734 | |
735 | - if ( $orderA === $orderB ) { |
|
735 | + if ($orderA === $orderB) { |
|
736 | 736 | $cursorA = $a->getContextCursor(); |
737 | 737 | $cursorB = $b->getContextCursor(); |
738 | 738 | |
739 | - if ( $cursorA instanceof EntityContextCursor ) { |
|
739 | + if ($cursorA instanceof EntityContextCursor) { |
|
740 | 740 | return $cursorB instanceof EntityContextCursor ? 0 : -1; |
741 | 741 | } |
742 | - if ( $cursorB instanceof EntityContextCursor ) { |
|
742 | + if ($cursorB instanceof EntityContextCursor) { |
|
743 | 743 | return $cursorA instanceof EntityContextCursor ? 0 : 1; |
744 | 744 | } |
745 | 745 | |
746 | 746 | $pidA = $cursorA->getSnakPropertyId(); |
747 | 747 | $pidB = $cursorB->getSnakPropertyId(); |
748 | 748 | |
749 | - if ( $pidA === $pidB ) { |
|
749 | + if ($pidA === $pidB) { |
|
750 | 750 | $hashA = $cursorA->getSnakHash(); |
751 | 751 | $hashB = $cursorB->getSnakHash(); |
752 | 752 | |
753 | - if ( $hashA === $hashB ) { |
|
754 | - if ( $a instanceof NullResult ) { |
|
753 | + if ($hashA === $hashB) { |
|
754 | + if ($a instanceof NullResult) { |
|
755 | 755 | return $b instanceof NullResult ? 0 : -1; |
756 | 756 | } |
757 | - if ( $b instanceof NullResult ) { |
|
757 | + if ($b instanceof NullResult) { |
|
758 | 758 | return $a instanceof NullResult ? 0 : 1; |
759 | 759 | } |
760 | 760 | |
761 | 761 | $typeA = $a->getConstraint()->getConstraintTypeItemId(); |
762 | 762 | $typeB = $b->getConstraint()->getConstraintTypeItemId(); |
763 | 763 | |
764 | - if ( $typeA == $typeB ) { |
|
764 | + if ($typeA == $typeB) { |
|
765 | 765 | return 0; |
766 | 766 | } else { |
767 | - return ( $typeA > $typeB ) ? 1 : -1; |
|
767 | + return ($typeA > $typeB) ? 1 : -1; |
|
768 | 768 | } |
769 | 769 | } else { |
770 | - return ( $hashA > $hashB ) ? 1 : -1; |
|
770 | + return ($hashA > $hashB) ? 1 : -1; |
|
771 | 771 | } |
772 | 772 | } else { |
773 | - return ( $pidA > $pidB ) ? 1 : -1; |
|
773 | + return ($pidA > $pidB) ? 1 : -1; |
|
774 | 774 | } |
775 | 775 | } else { |
776 | - return ( $orderA > $orderB ) ? 1 : -1; |
|
776 | + return ($orderA > $orderB) ? 1 : -1; |
|
777 | 777 | } |
778 | 778 | }; |
779 | 779 | |
780 | - uasort( $result, $sortFunction ); |
|
780 | + uasort($result, $sortFunction); |
|
781 | 781 | |
782 | 782 | return $result; |
783 | 783 | } |