@@ -55,9 +55,9 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @return CheckResult |
57 | 57 | */ |
58 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
59 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
60 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
58 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
59 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
60 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | $propertyId = $context->getSnak()->getPropertyId(); |
@@ -69,18 +69,18 @@ discard block |
||
69 | 69 | $propertyId |
70 | 70 | ); |
71 | 71 | |
72 | - if ( $propertyCount <= 1 ) { |
|
73 | - $message = new ViolationMessage( 'wbqc-violation-message-multi-value' ); |
|
72 | + if ($propertyCount <= 1) { |
|
73 | + $message = new ViolationMessage('wbqc-violation-message-multi-value'); |
|
74 | 74 | $status = CheckResult::STATUS_VIOLATION; |
75 | 75 | } else { |
76 | 76 | $message = null; |
77 | 77 | $status = CheckResult::STATUS_COMPLIANCE; |
78 | 78 | } |
79 | 79 | |
80 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
80 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
81 | 81 | } |
82 | 82 | |
83 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
83 | + public function checkConstraintParameters(Constraint $constraint) { |
|
84 | 84 | // no parameters |
85 | 85 | return []; |
86 | 86 | } |
@@ -36,16 +36,16 @@ |
||
36 | 36 | ]; |
37 | 37 | } |
38 | 38 | |
39 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
40 | - if ( $context->getType() === Context::TYPE_STATEMENT ) { |
|
41 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
39 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
40 | + if ($context->getType() === Context::TYPE_STATEMENT) { |
|
41 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
42 | 42 | } else { |
43 | - $message = new ViolationMessage( 'wbqc-violation-message-valueOnly' ); |
|
44 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
43 | + $message = new ViolationMessage('wbqc-violation-message-valueOnly'); |
|
44 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
45 | 45 | } |
46 | 46 | } |
47 | 47 | |
48 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
48 | + public function checkConstraintParameters(Constraint $constraint) { |
|
49 | 49 | // no parameters |
50 | 50 | return []; |
51 | 51 | } |
@@ -36,16 +36,16 @@ |
||
36 | 36 | ]; |
37 | 37 | } |
38 | 38 | |
39 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
40 | - if ( $context->getType() === Context::TYPE_REFERENCE ) { |
|
41 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
39 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
40 | + if ($context->getType() === Context::TYPE_REFERENCE) { |
|
41 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
42 | 42 | } else { |
43 | - $message = new ViolationMessage( 'wbqc-violation-message-reference' ); |
|
44 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
43 | + $message = new ViolationMessage('wbqc-violation-message-reference'); |
|
44 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
45 | 45 | } |
46 | 46 | } |
47 | 47 | |
48 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
48 | + public function checkConstraintParameters(Constraint $constraint) { |
|
49 | 49 | // no parameters |
50 | 50 | return []; |
51 | 51 | } |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | * @throws ConstraintParameterException |
85 | 85 | * @return array [ DataValue|null $min, DataValue|null $max, PropertyId $property, array $parameters ] |
86 | 86 | */ |
87 | - private function parseConstraintParameters( Constraint $constraint ) { |
|
88 | - list( $min, $max ) = $this->constraintParameterParser->parseRangeParameter( |
|
87 | + private function parseConstraintParameters(Constraint $constraint) { |
|
88 | + list($min, $max) = $this->constraintParameterParser->parseRangeParameter( |
|
89 | 89 | $constraint->getConstraintParameters(), |
90 | 90 | $constraint->getConstraintTypeItemId(), |
91 | 91 | 'quantity' |
@@ -95,15 +95,15 @@ discard block |
||
95 | 95 | $constraint->getConstraintTypeItemId() |
96 | 96 | ); |
97 | 97 | |
98 | - if ( $min !== null ) { |
|
99 | - $parameters['minimum_quantity'] = [ $min ]; |
|
98 | + if ($min !== null) { |
|
99 | + $parameters['minimum_quantity'] = [$min]; |
|
100 | 100 | } |
101 | - if ( $max !== null ) { |
|
102 | - $parameters['maximum_quantity'] = [ $max ]; |
|
101 | + if ($max !== null) { |
|
102 | + $parameters['maximum_quantity'] = [$max]; |
|
103 | 103 | } |
104 | - $parameters['property'] = [ $property ]; |
|
104 | + $parameters['property'] = [$property]; |
|
105 | 105 | |
106 | - return [ $min, $max, $property, $parameters ]; |
|
106 | + return [$min, $max, $property, $parameters]; |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -113,13 +113,13 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @return bool |
115 | 115 | */ |
116 | - private function rangeInYears( $min, $max ) { |
|
117 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
116 | + private function rangeInYears($min, $max) { |
|
117 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
118 | 118 | |
119 | - if ( $min !== null && $min->getUnit() === $yearUnit ) { |
|
119 | + if ($min !== null && $min->getUnit() === $yearUnit) { |
|
120 | 120 | return true; |
121 | 121 | } |
122 | - if ( $max !== null && $max->getUnit() === $yearUnit ) { |
|
122 | + if ($max !== null && $max->getUnit() === $yearUnit) { |
|
123 | 123 | return true; |
124 | 124 | } |
125 | 125 | |
@@ -135,57 +135,56 @@ discard block |
||
135 | 135 | * @throws ConstraintParameterException |
136 | 136 | * @return CheckResult |
137 | 137 | */ |
138 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
139 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
140 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
138 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
139 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
140 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | $parameters = []; |
144 | 144 | |
145 | 145 | $snak = $context->getSnak(); |
146 | 146 | |
147 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
147 | + if (!$snak instanceof PropertyValueSnak) { |
|
148 | 148 | // nothing to check |
149 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
149 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | $minuend = $snak->getDataValue(); |
153 | 153 | |
154 | 154 | /** @var PropertyId $property */ |
155 | - list( $min, $max, $property, $parameters ) = $this->parseConstraintParameters( $constraint ); |
|
155 | + list($min, $max, $property, $parameters) = $this->parseConstraintParameters($constraint); |
|
156 | 156 | |
157 | 157 | // checks only the first occurrence of the referenced property (this constraint implies a single value constraint on that property) |
158 | - foreach ( $context->getSnakGroup() as $otherSnak ) { |
|
158 | + foreach ($context->getSnakGroup() as $otherSnak) { |
|
159 | 159 | if ( |
160 | - !$property->equals( $otherSnak->getPropertyId() ) || |
|
160 | + !$property->equals($otherSnak->getPropertyId()) || |
|
161 | 161 | !$otherSnak instanceof PropertyValueSnak |
162 | 162 | ) { |
163 | 163 | continue; |
164 | 164 | } |
165 | 165 | |
166 | 166 | $subtrahend = $otherSnak->getDataValue(); |
167 | - if ( $subtrahend->getType() === $minuend->getType() ) { |
|
168 | - $diff = $this->rangeInYears( $min, $max ) ? |
|
169 | - $this->rangeCheckerHelper->getDifferenceInYears( $minuend, $subtrahend ) : |
|
170 | - $this->rangeCheckerHelper->getDifference( $minuend, $subtrahend ); |
|
167 | + if ($subtrahend->getType() === $minuend->getType()) { |
|
168 | + $diff = $this->rangeInYears($min, $max) ? |
|
169 | + $this->rangeCheckerHelper->getDifferenceInYears($minuend, $subtrahend) : $this->rangeCheckerHelper->getDifference($minuend, $subtrahend); |
|
171 | 170 | |
172 | - if ( $this->rangeCheckerHelper->getComparison( $min, $diff ) > 0 || |
|
173 | - $this->rangeCheckerHelper->getComparison( $diff, $max ) > 0 |
|
171 | + if ($this->rangeCheckerHelper->getComparison($min, $diff) > 0 || |
|
172 | + $this->rangeCheckerHelper->getComparison($diff, $max) > 0 |
|
174 | 173 | ) { |
175 | 174 | // at least one of $min, $max is set at this point, otherwise there could be no violation |
176 | - $openness = $min !== null ? ( $max !== null ? '' : '-rightopen' ) : '-leftopen'; |
|
177 | - $message = wfMessage( "wbqc-violation-message-diff-within-range$openness" ); |
|
175 | + $openness = $min !== null ? ($max !== null ? '' : '-rightopen') : '-leftopen'; |
|
176 | + $message = wfMessage("wbqc-violation-message-diff-within-range$openness"); |
|
178 | 177 | $message->rawParams( |
179 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ), |
|
180 | - $this->constraintParameterRenderer->formatDataValue( $minuend, Role::OBJECT ), |
|
181 | - $this->constraintParameterRenderer->formatEntityId( $otherSnak->getPropertyId(), Role::PREDICATE ), |
|
182 | - $this->constraintParameterRenderer->formatDataValue( $subtrahend, Role::OBJECT ) |
|
178 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE), |
|
179 | + $this->constraintParameterRenderer->formatDataValue($minuend, Role::OBJECT), |
|
180 | + $this->constraintParameterRenderer->formatEntityId($otherSnak->getPropertyId(), Role::PREDICATE), |
|
181 | + $this->constraintParameterRenderer->formatDataValue($subtrahend, Role::OBJECT) |
|
183 | 182 | ); |
184 | - if ( $min !== null ) { |
|
185 | - $message->rawParams( $this->constraintParameterRenderer->formatDataValue( $min, Role::OBJECT ) ); |
|
183 | + if ($min !== null) { |
|
184 | + $message->rawParams($this->constraintParameterRenderer->formatDataValue($min, Role::OBJECT)); |
|
186 | 185 | } |
187 | - if ( $max !== null ) { |
|
188 | - $message->rawParams( $this->constraintParameterRenderer->formatDataValue( $max, Role::OBJECT ) ); |
|
186 | + if ($max !== null) { |
|
187 | + $message->rawParams($this->constraintParameterRenderer->formatDataValue($max, Role::OBJECT)); |
|
189 | 188 | } |
190 | 189 | $message = $message->escaped(); |
191 | 190 | $status = CheckResult::STATUS_VIOLATION; |
@@ -194,19 +193,19 @@ discard block |
||
194 | 193 | $status = CheckResult::STATUS_COMPLIANCE; |
195 | 194 | } |
196 | 195 | } else { |
197 | - $message = new ViolationMessage( 'wbqc-violation-message-diff-within-range-must-have-equal-types' ); |
|
196 | + $message = new ViolationMessage('wbqc-violation-message-diff-within-range-must-have-equal-types'); |
|
198 | 197 | $status = CheckResult::STATUS_VIOLATION; |
199 | 198 | } |
200 | 199 | |
201 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
200 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
202 | 201 | } |
203 | 202 | |
204 | - $message = new ViolationMessage( 'wbqc-violation-message-diff-within-range-property-must-exist' ); |
|
203 | + $message = new ViolationMessage('wbqc-violation-message-diff-within-range-property-must-exist'); |
|
205 | 204 | $status = CheckResult::STATUS_VIOLATION; |
206 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
205 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
207 | 206 | } |
208 | 207 | |
209 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
208 | + public function checkConstraintParameters(Constraint $constraint) { |
|
210 | 209 | $constraintParameters = $constraint->getConstraintParameters(); |
211 | 210 | $exceptions = []; |
212 | 211 | try { |
@@ -215,12 +214,12 @@ discard block |
||
215 | 214 | $constraint->getConstraintTypeItemId(), |
216 | 215 | 'quantity' |
217 | 216 | ); |
218 | - } catch ( ConstraintParameterException $e ) { |
|
217 | + } catch (ConstraintParameterException $e) { |
|
219 | 218 | $exceptions[] = $e; |
220 | 219 | } |
221 | 220 | try { |
222 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
223 | - } catch ( ConstraintParameterException $e ) { |
|
221 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
222 | + } catch (ConstraintParameterException $e) { |
|
224 | 223 | $exceptions[] = $e; |
225 | 224 | } |
226 | 225 | return $exceptions; |
@@ -55,9 +55,9 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @return CheckResult |
57 | 57 | */ |
58 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
59 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
60 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
58 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
59 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
60 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | $propertyId = $context->getSnak()->getPropertyId(); |
@@ -69,18 +69,18 @@ discard block |
||
69 | 69 | $propertyId |
70 | 70 | ); |
71 | 71 | |
72 | - if ( $propertyCount > 1 ) { |
|
73 | - $message = new ViolationMessage( 'wbqc-violation-message-single-value' ); |
|
72 | + if ($propertyCount > 1) { |
|
73 | + $message = new ViolationMessage('wbqc-violation-message-single-value'); |
|
74 | 74 | $status = CheckResult::STATUS_VIOLATION; |
75 | 75 | } else { |
76 | 76 | $message = null; |
77 | 77 | $status = CheckResult::STATUS_COMPLIANCE; |
78 | 78 | } |
79 | 79 | |
80 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
80 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
81 | 81 | } |
82 | 82 | |
83 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
83 | + public function checkConstraintParameters(Constraint $constraint) { |
|
84 | 84 | // no parameters |
85 | 85 | return []; |
86 | 86 | } |
@@ -71,40 +71,40 @@ |
||
71 | 71 | * @throws ConstraintParameterException |
72 | 72 | * @return CheckResult |
73 | 73 | */ |
74 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
75 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
76 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
74 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
75 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
76 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | $parameters = []; |
80 | 80 | $constraintParameters = $constraint->getConstraintParameters(); |
81 | 81 | |
82 | - $propertyId = $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
83 | - $parameters['property'] = [ $propertyId ]; |
|
82 | + $propertyId = $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
83 | + $parameters['property'] = [$propertyId]; |
|
84 | 84 | |
85 | - $message = ( new ViolationMessage( 'wbqc-violation-message-mandatory-qualifier' ) ) |
|
86 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
87 | - ->withEntityId( $propertyId, Role::QUALIFIER_PREDICATE ); |
|
85 | + $message = (new ViolationMessage('wbqc-violation-message-mandatory-qualifier')) |
|
86 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
87 | + ->withEntityId($propertyId, Role::QUALIFIER_PREDICATE); |
|
88 | 88 | $status = CheckResult::STATUS_VIOLATION; |
89 | 89 | |
90 | 90 | /** @var Snak $qualifier */ |
91 | - foreach ( $context->getSnakStatement()->getQualifiers() as $qualifier ) { |
|
92 | - if ( $propertyId->equals( $qualifier->getPropertyId() ) ) { |
|
91 | + foreach ($context->getSnakStatement()->getQualifiers() as $qualifier) { |
|
92 | + if ($propertyId->equals($qualifier->getPropertyId())) { |
|
93 | 93 | $message = null; |
94 | 94 | $status = CheckResult::STATUS_COMPLIANCE; |
95 | 95 | break; |
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
99 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
99 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
100 | 100 | } |
101 | 101 | |
102 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
102 | + public function checkConstraintParameters(Constraint $constraint) { |
|
103 | 103 | $constraintParameters = $constraint->getConstraintParameters(); |
104 | 104 | $exceptions = []; |
105 | 105 | try { |
106 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
107 | - } catch ( ConstraintParameterException $e ) { |
|
106 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
107 | + } catch (ConstraintParameterException $e) { |
|
108 | 108 | $exceptions[] = $e; |
109 | 109 | } |
110 | 110 | return $exceptions; |
@@ -71,53 +71,53 @@ |
||
71 | 71 | * @throws ConstraintParameterException |
72 | 72 | * @return CheckResult |
73 | 73 | */ |
74 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
75 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
76 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
74 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
75 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
76 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | $parameters = []; |
80 | 80 | $constraintParameters = $constraint->getConstraintParameters(); |
81 | 81 | |
82 | - $properties = $this->constraintParameterParser->parsePropertiesParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
82 | + $properties = $this->constraintParameterParser->parsePropertiesParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
83 | 83 | $parameters['property'] = $properties; |
84 | 84 | |
85 | 85 | $message = null; |
86 | 86 | $status = CheckResult::STATUS_COMPLIANCE; |
87 | 87 | |
88 | 88 | /** @var Snak $qualifier */ |
89 | - foreach ( $context->getSnakStatement()->getQualifiers() as $qualifier ) { |
|
89 | + foreach ($context->getSnakStatement()->getQualifiers() as $qualifier) { |
|
90 | 90 | $allowedQualifier = false; |
91 | - foreach ( $properties as $property ) { |
|
92 | - if ( $qualifier->getPropertyId()->equals( $property ) ) { |
|
91 | + foreach ($properties as $property) { |
|
92 | + if ($qualifier->getPropertyId()->equals($property)) { |
|
93 | 93 | $allowedQualifier = true; |
94 | 94 | break; |
95 | 95 | } |
96 | 96 | } |
97 | - if ( !$allowedQualifier ) { |
|
98 | - if ( empty( $properties ) || $properties === [ '' ] ) { |
|
99 | - $message = ( new ViolationMessage( 'wbqc-violation-message-no-qualifiers' ) ) |
|
100 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ); |
|
97 | + if (!$allowedQualifier) { |
|
98 | + if (empty($properties) || $properties === ['']) { |
|
99 | + $message = (new ViolationMessage('wbqc-violation-message-no-qualifiers')) |
|
100 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY); |
|
101 | 101 | } else { |
102 | - $message = ( new ViolationMessage( 'wbqc-violation-message-qualifiers' ) ) |
|
103 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
104 | - ->withEntityId( $qualifier->getPropertyId(), Role::QUALIFIER_PREDICATE ) |
|
105 | - ->withEntityIdList( $properties, Role::QUALIFIER_PREDICATE ); |
|
102 | + $message = (new ViolationMessage('wbqc-violation-message-qualifiers')) |
|
103 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
104 | + ->withEntityId($qualifier->getPropertyId(), Role::QUALIFIER_PREDICATE) |
|
105 | + ->withEntityIdList($properties, Role::QUALIFIER_PREDICATE); |
|
106 | 106 | } |
107 | 107 | $status = CheckResult::STATUS_VIOLATION; |
108 | 108 | break; |
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
112 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
112 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
113 | 113 | } |
114 | 114 | |
115 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
115 | + public function checkConstraintParameters(Constraint $constraint) { |
|
116 | 116 | $constraintParameters = $constraint->getConstraintParameters(); |
117 | 117 | $exceptions = []; |
118 | 118 | try { |
119 | - $this->constraintParameterParser->parsePropertiesParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
120 | - } catch ( ConstraintParameterException $e ) { |
|
119 | + $this->constraintParameterParser->parsePropertiesParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
120 | + } catch (ConstraintParameterException $e) { |
|
121 | 121 | $exceptions[] = $e; |
122 | 122 | } |
123 | 123 | return $exceptions; |
@@ -74,22 +74,22 @@ discard block |
||
74 | 74 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
75 | 75 | * @return CheckResult |
76 | 76 | */ |
77 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
78 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
79 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
77 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
78 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
79 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | $parameters = []; |
83 | 83 | |
84 | - if ( $this->sparqlHelper !== null ) { |
|
85 | - if ( $context->getType() === 'statement' ) { |
|
84 | + if ($this->sparqlHelper !== null) { |
|
85 | + if ($context->getType() === 'statement') { |
|
86 | 86 | $result = $this->sparqlHelper->findEntitiesWithSameStatement( |
87 | 87 | $context->getSnakStatement(), |
88 | 88 | true // ignore deprecated statements |
89 | 89 | ); |
90 | 90 | } else { |
91 | - if ( $context->getSnak()->getType() !== 'value' ) { |
|
92 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
91 | + if ($context->getSnak()->getType() !== 'value') { |
|
92 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
93 | 93 | } |
94 | 94 | $result = $this->sparqlHelper->findEntitiesWithSameQualifierOrReference( |
95 | 95 | $context->getEntity()->getId(), |
@@ -102,27 +102,27 @@ discard block |
||
102 | 102 | $otherEntities = $result->getArray(); |
103 | 103 | $metadata = $result->getMetadata(); |
104 | 104 | |
105 | - if ( $otherEntities === [] ) { |
|
105 | + if ($otherEntities === []) { |
|
106 | 106 | $status = CheckResult::STATUS_COMPLIANCE; |
107 | 107 | $message = null; |
108 | 108 | } else { |
109 | - $otherEntities = array_values( array_filter( $otherEntities ) ); // remove nulls |
|
109 | + $otherEntities = array_values(array_filter($otherEntities)); // remove nulls |
|
110 | 110 | $status = CheckResult::STATUS_VIOLATION; |
111 | - $message = ( new ViolationMessage( 'wbqc-violation-message-unique-value' ) ) |
|
112 | - ->withEntityIdList( $otherEntities, Role::SUBJECT ); |
|
111 | + $message = (new ViolationMessage('wbqc-violation-message-unique-value')) |
|
112 | + ->withEntityIdList($otherEntities, Role::SUBJECT); |
|
113 | 113 | } |
114 | 114 | } else { |
115 | 115 | $status = CheckResult::STATUS_TODO; |
116 | - $message = ( new ViolationMessage( 'wbqc-violation-message-not-yet-implemented' ) ) |
|
117 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ); |
|
116 | + $message = (new ViolationMessage('wbqc-violation-message-not-yet-implemented')) |
|
117 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM); |
|
118 | 118 | $metadata = Metadata::blank(); |
119 | 119 | } |
120 | 120 | |
121 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
122 | - ->withMetadata( $metadata ); |
|
121 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
122 | + ->withMetadata($metadata); |
|
123 | 123 | } |
124 | 124 | |
125 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
125 | + public function checkConstraintParameters(Constraint $constraint) { |
|
126 | 126 | // no parameters |
127 | 127 | return []; |
128 | 128 | } |
@@ -89,23 +89,23 @@ discard block |
||
89 | 89 | * @return bool |
90 | 90 | * @throws OverflowException if $entitiesChecked exceeds the configured limit |
91 | 91 | */ |
92 | - private function isSubclassOf( EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0 ) { |
|
93 | - $maxEntities = $this->config->get( 'WBQualityConstraintsTypeCheckMaxEntities' ); |
|
92 | + private function isSubclassOf(EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0) { |
|
93 | + $maxEntities = $this->config->get('WBQualityConstraintsTypeCheckMaxEntities'); |
|
94 | 94 | if ( ++$entitiesChecked > $maxEntities ) { |
95 | - throw new OverflowException( 'Too many entities to check' ); |
|
95 | + throw new OverflowException('Too many entities to check'); |
|
96 | 96 | } |
97 | 97 | |
98 | - $item = $this->entityLookup->getEntity( $comparativeClass ); |
|
99 | - if ( !( $item instanceof StatementListProvider ) ) { |
|
98 | + $item = $this->entityLookup->getEntity($comparativeClass); |
|
99 | + if (!($item instanceof StatementListProvider)) { |
|
100 | 100 | return false; // lookup failed, probably because item doesn't exist |
101 | 101 | } |
102 | 102 | |
103 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
103 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
104 | 104 | /** @var Statement $statement */ |
105 | - foreach ( $item->getStatements()->getByPropertyId( new PropertyId( $subclassId ) ) as $statement ) { |
|
105 | + foreach ($item->getStatements()->getByPropertyId(new PropertyId($subclassId)) as $statement) { |
|
106 | 106 | $mainSnak = $statement->getMainSnak(); |
107 | 107 | |
108 | - if ( !( $this->hasCorrectType( $mainSnak ) ) ) { |
|
108 | + if (!($this->hasCorrectType($mainSnak))) { |
|
109 | 109 | continue; |
110 | 110 | } |
111 | 111 | /** @var PropertyValueSnak $mainSnak */ |
@@ -114,11 +114,11 @@ discard block |
||
114 | 114 | $dataValue = $mainSnak->getDataValue(); |
115 | 115 | $comparativeClass = $dataValue->getEntityId(); |
116 | 116 | |
117 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
117 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
118 | 118 | return true; |
119 | 119 | } |
120 | 120 | |
121 | - if ( $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ) ) { |
|
121 | + if ($this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked)) { |
|
122 | 122 | return true; |
123 | 123 | } |
124 | 124 | } |
@@ -139,14 +139,14 @@ discard block |
||
139 | 139 | * @return CachedBool |
140 | 140 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
141 | 141 | */ |
142 | - public function isSubclassOfWithSparqlFallback( EntityId $comparativeClass, array $classesToCheck ) { |
|
142 | + public function isSubclassOfWithSparqlFallback(EntityId $comparativeClass, array $classesToCheck) { |
|
143 | 143 | try { |
144 | 144 | return new CachedBool( |
145 | - $this->isSubclassOf( $comparativeClass, $classesToCheck ), |
|
145 | + $this->isSubclassOf($comparativeClass, $classesToCheck), |
|
146 | 146 | Metadata::blank() |
147 | 147 | ); |
148 | - } catch ( OverflowException $e ) { |
|
149 | - if ( $this->sparqlHelper !== null ) { |
|
148 | + } catch (OverflowException $e) { |
|
149 | + if ($this->sparqlHelper !== null) { |
|
150 | 150 | $this->dataFactory->increment( |
151 | 151 | 'wikibase.quality.constraints.sparql.typeFallback' |
152 | 152 | ); |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | /* withInstance = */ false |
157 | 157 | ); |
158 | 158 | } else { |
159 | - return new CachedBool( false, Metadata::blank() ); |
|
159 | + return new CachedBool(false, Metadata::blank()); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | } |
@@ -174,14 +174,14 @@ discard block |
||
174 | 174 | * @return CachedBool |
175 | 175 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
176 | 176 | */ |
177 | - public function hasClassInRelation( StatementList $statements, array $relationIds, array $classesToCheck ) { |
|
177 | + public function hasClassInRelation(StatementList $statements, array $relationIds, array $classesToCheck) { |
|
178 | 178 | $metadatas = []; |
179 | 179 | |
180 | 180 | /** @var Statement $statement */ |
181 | - foreach ( $this->getStatementsByPropertyIds( $statements, $relationIds ) as $statement ) { |
|
181 | + foreach ($this->getStatementsByPropertyIds($statements, $relationIds) as $statement) { |
|
182 | 182 | $mainSnak = $statement->getMainSnak(); |
183 | 183 | |
184 | - if ( !$this->hasCorrectType( $mainSnak ) ) { |
|
184 | + if (!$this->hasCorrectType($mainSnak)) { |
|
185 | 185 | continue; |
186 | 186 | } |
187 | 187 | /** @var PropertyValueSnak $mainSnak */ |
@@ -190,28 +190,28 @@ discard block |
||
190 | 190 | $dataValue = $mainSnak->getDataValue(); |
191 | 191 | $comparativeClass = $dataValue->getEntityId(); |
192 | 192 | |
193 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
193 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
194 | 194 | // discard $metadatas, we know this is fresh |
195 | - return new CachedBool( true, Metadata::blank() ); |
|
195 | + return new CachedBool(true, Metadata::blank()); |
|
196 | 196 | } |
197 | 197 | |
198 | - $result = $this->isSubclassOfWithSparqlFallback( $comparativeClass, $classesToCheck ); |
|
198 | + $result = $this->isSubclassOfWithSparqlFallback($comparativeClass, $classesToCheck); |
|
199 | 199 | $metadatas[] = $result->getMetadata(); |
200 | - if ( $result->getBool() ) { |
|
200 | + if ($result->getBool()) { |
|
201 | 201 | return new CachedBool( |
202 | 202 | true, |
203 | - Metadata::merge( $metadatas ) |
|
203 | + Metadata::merge($metadatas) |
|
204 | 204 | ); |
205 | 205 | } |
206 | 206 | } |
207 | 207 | |
208 | 208 | return new CachedBool( |
209 | 209 | false, |
210 | - Metadata::merge( $metadatas ) |
|
210 | + Metadata::merge($metadatas) |
|
211 | 211 | ); |
212 | 212 | } |
213 | 213 | |
214 | - private function hasCorrectType( Snak $mainSnak ) { |
|
214 | + private function hasCorrectType(Snak $mainSnak) { |
|
215 | 215 | return $mainSnak instanceof PropertyValueSnak |
216 | 216 | && $mainSnak->getDataValue()->getType() === 'wikibase-entityid'; |
217 | 217 | } |
@@ -226,12 +226,12 @@ discard block |
||
226 | 226 | array $propertyIdSerializations |
227 | 227 | ) { |
228 | 228 | $statementArrays = []; |
229 | - foreach ( $propertyIdSerializations as $propertyIdSerialization ) { |
|
230 | - $propertyId = new PropertyId( $propertyIdSerialization ); |
|
231 | - $statementArrays[] = $statements->getByPropertyId( $propertyId )->toArray(); |
|
229 | + foreach ($propertyIdSerializations as $propertyIdSerialization) { |
|
230 | + $propertyId = new PropertyId($propertyIdSerialization); |
|
231 | + $statementArrays[] = $statements->getByPropertyId($propertyId)->toArray(); |
|
232 | 232 | } |
233 | 233 | return new StatementList( |
234 | - call_user_func_array( 'array_merge', $statementArrays ) |
|
234 | + call_user_func_array('array_merge', $statementArrays) |
|
235 | 235 | ); |
236 | 236 | } |
237 | 237 | |
@@ -244,10 +244,10 @@ discard block |
||
244 | 244 | * |
245 | 245 | * @return ViolationMessage |
246 | 246 | */ |
247 | - public function getViolationMessage( PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation ) { |
|
247 | + public function getViolationMessage(PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation) { |
|
248 | 248 | $classes = array_map( |
249 | - function( $itemIdSerialization ) { |
|
250 | - return new ItemId( $itemIdSerialization ); |
|
249 | + function($itemIdSerialization) { |
|
250 | + return new ItemId($itemIdSerialization); |
|
251 | 251 | }, |
252 | 252 | $classes |
253 | 253 | ); |
@@ -259,10 +259,10 @@ discard block |
||
259 | 259 | // wbqc-violation-message-valueType-instance |
260 | 260 | // wbqc-violation-message-valueType-subclass |
261 | 261 | // wbqc-violation-message-valueType-instanceOrSubclass |
262 | - return ( new ViolationMessage( 'wbqc-violation-message-' . $checker . '-' . $relation ) ) |
|
263 | - ->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ) |
|
264 | - ->withEntityId( $entityId, Role::SUBJECT ) |
|
265 | - ->withEntityIdList( $classes, Role::OBJECT ); |
|
262 | + return (new ViolationMessage('wbqc-violation-message-'.$checker.'-'.$relation)) |
|
263 | + ->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY) |
|
264 | + ->withEntityId($entityId, Role::SUBJECT) |
|
265 | + ->withEntityIdList($classes, Role::OBJECT); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | } |