@@ -35,33 +35,33 @@ |
||
35 | 35 | * |
36 | 36 | * @return CheckResult |
37 | 37 | */ |
38 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
39 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
40 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
38 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
39 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
40 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
41 | 41 | } |
42 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
42 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
43 | 43 | // TODO T175566 |
44 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK ); |
|
44 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | $propertyId = $context->getSnak()->getPropertyId(); |
48 | 48 | |
49 | 49 | $parameters = []; |
50 | 50 | |
51 | - $propertyCountArray = $this->valueCountCheckerHelper->getPropertyCount( $context->getEntity()->getStatements() ); |
|
51 | + $propertyCountArray = $this->valueCountCheckerHelper->getPropertyCount($context->getEntity()->getStatements()); |
|
52 | 52 | |
53 | - if ( $propertyCountArray[$propertyId->getSerialization()] > 1 ) { |
|
54 | - $message = wfMessage( "wbqc-violation-message-single-value" )->escaped(); |
|
53 | + if ($propertyCountArray[$propertyId->getSerialization()] > 1) { |
|
54 | + $message = wfMessage("wbqc-violation-message-single-value")->escaped(); |
|
55 | 55 | $status = CheckResult::STATUS_VIOLATION; |
56 | 56 | } else { |
57 | 57 | $message = ''; |
58 | 58 | $status = CheckResult::STATUS_COMPLIANCE; |
59 | 59 | } |
60 | 60 | |
61 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
61 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
62 | 62 | } |
63 | 63 | |
64 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
64 | + public function checkConstraintParameters(Constraint $constraint) { |
|
65 | 65 | // no parameters |
66 | 66 | return []; |
67 | 67 | } |
@@ -70,9 +70,9 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return CheckResult |
72 | 72 | */ |
73 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
74 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
75 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
73 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
74 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
75 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | $parameters = []; |
@@ -80,42 +80,42 @@ discard block |
||
80 | 80 | |
81 | 81 | $snak = $context->getSnak(); |
82 | 82 | |
83 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
83 | + if (!$snak instanceof PropertyValueSnak) { |
|
84 | 84 | // nothing to check |
85 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
85 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | $dataValue = $snak->getDataValue(); |
89 | 89 | |
90 | - list( $min, $max ) = $this->constraintParameterParser->parseRangeParameter( |
|
90 | + list($min, $max) = $this->constraintParameterParser->parseRangeParameter( |
|
91 | 91 | $constraintParameters, |
92 | 92 | $constraint->getConstraintTypeItemId(), |
93 | 93 | $dataValue->getType() |
94 | 94 | ); |
95 | 95 | $parameterKey = $dataValue->getType() === 'quantity' ? 'quantity' : 'date'; |
96 | - if ( $min !== null ) { |
|
97 | - $parameters['minimum_' . $parameterKey] = [ $min ]; |
|
96 | + if ($min !== null) { |
|
97 | + $parameters['minimum_'.$parameterKey] = [$min]; |
|
98 | 98 | } |
99 | - if ( $max !== null ) { |
|
100 | - $parameters['maximum_' . $parameterKey] = [ $max ]; |
|
99 | + if ($max !== null) { |
|
100 | + $parameters['maximum_'.$parameterKey] = [$max]; |
|
101 | 101 | } |
102 | 102 | |
103 | - if ( $this->rangeCheckerHelper->getComparison( $min, $dataValue ) > 0 || |
|
104 | - $this->rangeCheckerHelper->getComparison( $dataValue, $max ) > 0 |
|
103 | + if ($this->rangeCheckerHelper->getComparison($min, $dataValue) > 0 || |
|
104 | + $this->rangeCheckerHelper->getComparison($dataValue, $max) > 0 |
|
105 | 105 | ) { |
106 | 106 | // at least one of $min, $max is set at this point, otherwise there could be no violation |
107 | 107 | $type = $dataValue->getType(); |
108 | - $openness = $min !== null ? ( $max !== null ? 'closed' : 'rightopen' ) : 'leftopen'; |
|
109 | - $message = wfMessage( "wbqc-violation-message-range-$type-$openness" ); |
|
108 | + $openness = $min !== null ? ($max !== null ? 'closed' : 'rightopen') : 'leftopen'; |
|
109 | + $message = wfMessage("wbqc-violation-message-range-$type-$openness"); |
|
110 | 110 | $message->rawParams( |
111 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ), |
|
112 | - $this->constraintParameterRenderer->formatDataValue( $dataValue, Role::OBJECT ) |
|
111 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE), |
|
112 | + $this->constraintParameterRenderer->formatDataValue($dataValue, Role::OBJECT) |
|
113 | 113 | ); |
114 | - if ( $min !== null ) { |
|
115 | - $message->rawParams( $this->constraintParameterRenderer->formatDataValue( $min, Role::OBJECT ) ); |
|
114 | + if ($min !== null) { |
|
115 | + $message->rawParams($this->constraintParameterRenderer->formatDataValue($min, Role::OBJECT)); |
|
116 | 116 | } |
117 | - if ( $max !== null ) { |
|
118 | - $message->rawParams( $this->constraintParameterRenderer->formatDataValue( $max, Role::OBJECT ) ); |
|
117 | + if ($max !== null) { |
|
118 | + $message->rawParams($this->constraintParameterRenderer->formatDataValue($max, Role::OBJECT)); |
|
119 | 119 | } |
120 | 120 | $message = $message->escaped(); |
121 | 121 | $status = CheckResult::STATUS_VIOLATION; |
@@ -124,22 +124,22 @@ discard block |
||
124 | 124 | $status = CheckResult::STATUS_COMPLIANCE; |
125 | 125 | } |
126 | 126 | |
127 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
127 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
128 | 128 | } |
129 | 129 | |
130 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
130 | + public function checkConstraintParameters(Constraint $constraint) { |
|
131 | 131 | $constraintParameters = $constraint->getConstraintParameters(); |
132 | 132 | $exceptions = []; |
133 | 133 | try { |
134 | 134 | // we don’t have a data value here, so get the type from the property instead |
135 | 135 | // (the distinction between data type and data value type is irrelevant for 'quantity' and 'time') |
136 | - $type = $this->propertyDataTypeLookup->getDataTypeIdForProperty( $constraint->getPropertyId() ); |
|
136 | + $type = $this->propertyDataTypeLookup->getDataTypeIdForProperty($constraint->getPropertyId()); |
|
137 | 137 | $this->constraintParameterParser->parseRangeParameter( |
138 | 138 | $constraintParameters, |
139 | 139 | $constraint->getConstraintTypeItemId(), |
140 | 140 | $type |
141 | 141 | ); |
142 | - } catch ( ConstraintParameterException $e ) { |
|
142 | + } catch (ConstraintParameterException $e) { |
|
143 | 143 | $exceptions[] = $e; |
144 | 144 | } |
145 | 145 | return $exceptions; |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | * @throws ConstraintParameterException |
68 | 68 | * @return array [ DataValue|null $min, DataValue|null $max, PropertyId $property, array $parameters ] |
69 | 69 | */ |
70 | - private function parseConstraintParameters( Constraint $constraint ) { |
|
71 | - list( $min, $max ) = $this->constraintParameterParser->parseRangeParameter( |
|
70 | + private function parseConstraintParameters(Constraint $constraint) { |
|
71 | + list($min, $max) = $this->constraintParameterParser->parseRangeParameter( |
|
72 | 72 | $constraint->getConstraintParameters(), |
73 | 73 | $constraint->getConstraintTypeItemId(), |
74 | 74 | 'quantity' |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | $constraint->getConstraintTypeItemId() |
79 | 79 | ); |
80 | 80 | |
81 | - if ( $min !== null ) { |
|
82 | - $parameters['minimum_quantity'] = [ $min ]; |
|
81 | + if ($min !== null) { |
|
82 | + $parameters['minimum_quantity'] = [$min]; |
|
83 | 83 | } |
84 | - if ( $max !== null ) { |
|
85 | - $parameters['maximum_quantity'] = [ $max ]; |
|
84 | + if ($max !== null) { |
|
85 | + $parameters['maximum_quantity'] = [$max]; |
|
86 | 86 | } |
87 | - $parameters['property'] = [ $property ]; |
|
87 | + $parameters['property'] = [$property]; |
|
88 | 88 | |
89 | - return [ $min, $max, $property, $parameters ]; |
|
89 | + return [$min, $max, $property, $parameters]; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -96,13 +96,13 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @return bool |
98 | 98 | */ |
99 | - private function rangeInYears( $min, $max ) { |
|
100 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
99 | + private function rangeInYears($min, $max) { |
|
100 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
101 | 101 | |
102 | - if ( $min !== null && $min->getUnit() === $yearUnit ) { |
|
102 | + if ($min !== null && $min->getUnit() === $yearUnit) { |
|
103 | 103 | return true; |
104 | 104 | } |
105 | - if ( $max !== null && $max->getUnit() === $yearUnit ) { |
|
105 | + if ($max !== null && $max->getUnit() === $yearUnit) { |
|
106 | 106 | return true; |
107 | 107 | } |
108 | 108 | |
@@ -117,36 +117,36 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @return CheckResult |
119 | 119 | */ |
120 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
121 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
122 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
120 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
121 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
122 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
123 | 123 | } |
124 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
124 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
125 | 125 | // TODO T175565 |
126 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK ); |
|
126 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | $parameters = []; |
130 | 130 | |
131 | 131 | $snak = $context->getSnak(); |
132 | 132 | |
133 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
133 | + if (!$snak instanceof PropertyValueSnak) { |
|
134 | 134 | // nothing to check |
135 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
135 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | $minuend = $snak->getDataValue(); |
139 | 139 | |
140 | 140 | /** @var PropertyId $property */ |
141 | - list ( $min, $max, $property, $parameters ) = $this->parseConstraintParameters( $constraint ); |
|
141 | + list ($min, $max, $property, $parameters) = $this->parseConstraintParameters($constraint); |
|
142 | 142 | |
143 | 143 | // checks only the first occurrence of the referenced property (this constraint implies a single value constraint on that property) |
144 | 144 | /** @var Statement $otherStatement */ |
145 | - foreach ( $context->getEntity()->getStatements() as $otherStatement ) { |
|
145 | + foreach ($context->getEntity()->getStatements() as $otherStatement) { |
|
146 | 146 | $otherMainSnak = $otherStatement->getMainSnak(); |
147 | 147 | |
148 | 148 | if ( |
149 | - !$property->equals( $otherStatement->getPropertyId() ) || |
|
149 | + !$property->equals($otherStatement->getPropertyId()) || |
|
150 | 150 | $otherStatement->getRank() === Statement::RANK_DEPRECATED || |
151 | 151 | !$otherMainSnak instanceof PropertyValueSnak |
152 | 152 | ) { |
@@ -154,28 +154,27 @@ discard block |
||
154 | 154 | } |
155 | 155 | |
156 | 156 | $subtrahend = $otherMainSnak->getDataValue(); |
157 | - if ( $subtrahend->getType() === $minuend->getType() ) { |
|
158 | - $diff = $this->rangeInYears( $min, $max ) ? |
|
159 | - $this->rangeCheckerHelper->getDifferenceInYears( $minuend, $subtrahend ) : |
|
160 | - $this->rangeCheckerHelper->getDifference( $minuend, $subtrahend ); |
|
157 | + if ($subtrahend->getType() === $minuend->getType()) { |
|
158 | + $diff = $this->rangeInYears($min, $max) ? |
|
159 | + $this->rangeCheckerHelper->getDifferenceInYears($minuend, $subtrahend) : $this->rangeCheckerHelper->getDifference($minuend, $subtrahend); |
|
161 | 160 | |
162 | - if ( $this->rangeCheckerHelper->getComparison( $min, $diff ) > 0 || |
|
163 | - $this->rangeCheckerHelper->getComparison( $diff, $max ) > 0 |
|
161 | + if ($this->rangeCheckerHelper->getComparison($min, $diff) > 0 || |
|
162 | + $this->rangeCheckerHelper->getComparison($diff, $max) > 0 |
|
164 | 163 | ) { |
165 | 164 | // at least one of $min, $max is set at this point, otherwise there could be no violation |
166 | - $openness = $min !== null ? ( $max !== null ? '' : '-rightopen' ) : '-leftopen'; |
|
167 | - $message = wfMessage( "wbqc-violation-message-diff-within-range$openness" ); |
|
165 | + $openness = $min !== null ? ($max !== null ? '' : '-rightopen') : '-leftopen'; |
|
166 | + $message = wfMessage("wbqc-violation-message-diff-within-range$openness"); |
|
168 | 167 | $message->rawParams( |
169 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ), |
|
170 | - $this->constraintParameterRenderer->formatDataValue( $minuend, Role::OBJECT ), |
|
171 | - $this->constraintParameterRenderer->formatEntityId( $otherStatement->getPropertyId(), Role::PREDICATE ), |
|
172 | - $this->constraintParameterRenderer->formatDataValue( $subtrahend, Role::OBJECT ) |
|
168 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE), |
|
169 | + $this->constraintParameterRenderer->formatDataValue($minuend, Role::OBJECT), |
|
170 | + $this->constraintParameterRenderer->formatEntityId($otherStatement->getPropertyId(), Role::PREDICATE), |
|
171 | + $this->constraintParameterRenderer->formatDataValue($subtrahend, Role::OBJECT) |
|
173 | 172 | ); |
174 | - if ( $min !== null ) { |
|
175 | - $message->rawParams( $this->constraintParameterRenderer->formatDataValue( $min, Role::OBJECT ) ); |
|
173 | + if ($min !== null) { |
|
174 | + $message->rawParams($this->constraintParameterRenderer->formatDataValue($min, Role::OBJECT)); |
|
176 | 175 | } |
177 | - if ( $max !== null ) { |
|
178 | - $message->rawParams( $this->constraintParameterRenderer->formatDataValue( $max, Role::OBJECT ) ); |
|
176 | + if ($max !== null) { |
|
177 | + $message->rawParams($this->constraintParameterRenderer->formatDataValue($max, Role::OBJECT)); |
|
179 | 178 | } |
180 | 179 | $message = $message->escaped(); |
181 | 180 | $status = CheckResult::STATUS_VIOLATION; |
@@ -184,19 +183,19 @@ discard block |
||
184 | 183 | $status = CheckResult::STATUS_COMPLIANCE; |
185 | 184 | } |
186 | 185 | } else { |
187 | - $message = wfMessage( "wbqc-violation-message-diff-within-range-must-have-equal-types" )->escaped(); |
|
186 | + $message = wfMessage("wbqc-violation-message-diff-within-range-must-have-equal-types")->escaped(); |
|
188 | 187 | $status = CheckResult::STATUS_VIOLATION; |
189 | 188 | } |
190 | 189 | |
191 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
190 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
192 | 191 | } |
193 | 192 | |
194 | - $message = wfMessage( "wbqc-violation-message-diff-within-range-property-must-exist" )->escaped(); |
|
193 | + $message = wfMessage("wbqc-violation-message-diff-within-range-property-must-exist")->escaped(); |
|
195 | 194 | $status = CheckResult::STATUS_VIOLATION; |
196 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
195 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
197 | 196 | } |
198 | 197 | |
199 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
198 | + public function checkConstraintParameters(Constraint $constraint) { |
|
200 | 199 | $constraintParameters = $constraint->getConstraintParameters(); |
201 | 200 | $exceptions = []; |
202 | 201 | try { |
@@ -205,12 +204,12 @@ discard block |
||
205 | 204 | $constraint->getConstraintTypeItemId(), |
206 | 205 | 'quantity' |
207 | 206 | ); |
208 | - } catch ( ConstraintParameterException $e ) { |
|
207 | + } catch (ConstraintParameterException $e) { |
|
209 | 208 | $exceptions[] = $e; |
210 | 209 | } |
211 | 210 | try { |
212 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
213 | - } catch ( ConstraintParameterException $e ) { |
|
211 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
212 | + } catch (ConstraintParameterException $e) { |
|
214 | 213 | $exceptions[] = $e; |
215 | 214 | } |
216 | 215 | return $exceptions; |
@@ -35,33 +35,33 @@ |
||
35 | 35 | * |
36 | 36 | * @return CheckResult |
37 | 37 | */ |
38 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
39 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
40 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
38 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
39 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
40 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
41 | 41 | } |
42 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
42 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
43 | 43 | // TODO T175566 |
44 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK ); |
|
44 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | $propertyId = $context->getSnak()->getPropertyId(); |
48 | 48 | |
49 | 49 | $parameters = []; |
50 | 50 | |
51 | - $propertyCountArray = $this->valueCountCheckerHelper->getPropertyCount( $context->getEntity()->getStatements() ); |
|
51 | + $propertyCountArray = $this->valueCountCheckerHelper->getPropertyCount($context->getEntity()->getStatements()); |
|
52 | 52 | |
53 | - if ( $propertyCountArray[$propertyId->getSerialization()] <= 1 ) { |
|
54 | - $message = wfMessage( "wbqc-violation-message-multi-value" )->escaped(); |
|
53 | + if ($propertyCountArray[$propertyId->getSerialization()] <= 1) { |
|
54 | + $message = wfMessage("wbqc-violation-message-multi-value")->escaped(); |
|
55 | 55 | $status = CheckResult::STATUS_VIOLATION; |
56 | 56 | } else { |
57 | 57 | $message = ''; |
58 | 58 | $status = CheckResult::STATUS_COMPLIANCE; |
59 | 59 | } |
60 | 60 | |
61 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
61 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
62 | 62 | } |
63 | 63 | |
64 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
64 | + public function checkConstraintParameters(Constraint $constraint) { |
|
65 | 65 | // no parameters |
66 | 66 | return []; |
67 | 67 | } |
@@ -69,22 +69,22 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return CheckResult |
71 | 71 | */ |
72 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
73 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
74 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
72 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
73 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
74 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
75 | 75 | } |
76 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
76 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
77 | 77 | // TODO T175562 |
78 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK ); |
|
78 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | $parameters = []; |
82 | 82 | $constraintParameters = $constraint->getConstraintParameters(); |
83 | 83 | |
84 | - $propertyId = $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
85 | - $parameters['property'] = [ $propertyId ]; |
|
84 | + $propertyId = $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
85 | + $parameters['property'] = [$propertyId]; |
|
86 | 86 | |
87 | - $items = $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), false ); |
|
87 | + $items = $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), false); |
|
88 | 88 | $parameters['items'] = $items; |
89 | 89 | |
90 | 90 | /* |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * a) a property only |
93 | 93 | * b) a property and a number of items (each combination of property and item forming an individual claim) |
94 | 94 | */ |
95 | - if ( $items === [] ) { |
|
95 | + if ($items === []) { |
|
96 | 96 | $requiredStatement = $this->connectionCheckerHelper->findStatementWithProperty( |
97 | 97 | $context->getEntity()->getStatements(), |
98 | 98 | $propertyId |
@@ -105,35 +105,35 @@ discard block |
||
105 | 105 | ); |
106 | 106 | } |
107 | 107 | |
108 | - if ( $requiredStatement !== null ) { |
|
108 | + if ($requiredStatement !== null) { |
|
109 | 109 | $status = CheckResult::STATUS_COMPLIANCE; |
110 | 110 | $message = ''; |
111 | 111 | } else { |
112 | 112 | $status = CheckResult::STATUS_VIOLATION; |
113 | - $message = wfMessage( 'wbqc-violation-message-item' ); |
|
113 | + $message = wfMessage('wbqc-violation-message-item'); |
|
114 | 114 | $message->rawParams( |
115 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ), |
|
116 | - $this->constraintParameterRenderer->formatEntityId( $propertyId, Role::PREDICATE ) |
|
115 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY), |
|
116 | + $this->constraintParameterRenderer->formatEntityId($propertyId, Role::PREDICATE) |
|
117 | 117 | ); |
118 | - $message->numParams( count( $items ) ); |
|
119 | - $message->rawParams( $this->constraintParameterRenderer->formatItemIdSnakValueList( $items, Role::OBJECT ) ); |
|
118 | + $message->numParams(count($items)); |
|
119 | + $message->rawParams($this->constraintParameterRenderer->formatItemIdSnakValueList($items, Role::OBJECT)); |
|
120 | 120 | $message = $message->escaped(); |
121 | 121 | } |
122 | 122 | |
123 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
123 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
124 | 124 | } |
125 | 125 | |
126 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
126 | + public function checkConstraintParameters(Constraint $constraint) { |
|
127 | 127 | $constraintParameters = $constraint->getConstraintParameters(); |
128 | 128 | $exceptions = []; |
129 | 129 | try { |
130 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
131 | - } catch ( ConstraintParameterException $e ) { |
|
130 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
131 | + } catch (ConstraintParameterException $e) { |
|
132 | 132 | $exceptions[] = $e; |
133 | 133 | } |
134 | 134 | try { |
135 | - $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), false ); |
|
136 | - } catch ( ConstraintParameterException $e ) { |
|
135 | + $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), false); |
|
136 | + } catch (ConstraintParameterException $e) { |
|
137 | 137 | $exceptions[] = $e; |
138 | 138 | } |
139 | 139 | return $exceptions; |
@@ -73,26 +73,26 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @return CheckResult |
75 | 75 | */ |
76 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
76 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
77 | 77 | $parameters = []; |
78 | 78 | $constraintParameters = $constraint->getConstraintParameters(); |
79 | 79 | |
80 | - $format = $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
81 | - $parameters['pattern'] = [ $format ]; |
|
80 | + $format = $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
81 | + $parameters['pattern'] = [$format]; |
|
82 | 82 | |
83 | 83 | $syntaxClarification = $this->constraintParameterParser->parseSyntaxClarificationParameter( |
84 | 84 | $constraintParameters, |
85 | 85 | WikibaseRepo::getDefaultInstance()->getUserLanguage() // TODO make this part of the Context? |
86 | 86 | ); |
87 | - if ( $syntaxClarification !== null ) { |
|
88 | - $parameters['clarification'] = [ $syntaxClarification ]; |
|
87 | + if ($syntaxClarification !== null) { |
|
88 | + $parameters['clarification'] = [$syntaxClarification]; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | $snak = $context->getSnak(); |
92 | 92 | |
93 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
93 | + if (!$snak instanceof PropertyValueSnak) { |
|
94 | 94 | // nothing to check |
95 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
95 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | $dataValue = $snak->getDataValue(); |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * error handling: |
102 | 102 | * type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext' |
103 | 103 | */ |
104 | - switch ( $dataValue->getType() ) { |
|
104 | + switch ($dataValue->getType()) { |
|
105 | 105 | case 'string': |
106 | 106 | $text = $dataValue->getValue(); |
107 | 107 | break; |
@@ -109,60 +109,59 @@ discard block |
||
109 | 109 | $text = $dataValue->getText(); |
110 | 110 | break; |
111 | 111 | default: |
112 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
112 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
113 | 113 | ->rawParams( |
114 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
115 | - wfMessage( 'datatypes-type-string' )->escaped(), |
|
116 | - wfMessage( 'datatypes-type-monolingualtext' )->escaped() |
|
114 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
115 | + wfMessage('datatypes-type-string')->escaped(), |
|
116 | + wfMessage('datatypes-type-monolingualtext')->escaped() |
|
117 | 117 | ) |
118 | 118 | ->escaped(); |
119 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
119 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
120 | 120 | } |
121 | 121 | |
122 | - if ( $this->sparqlHelper !== null && $this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) ) { |
|
123 | - if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) { |
|
122 | + if ($this->sparqlHelper !== null && $this->config->get('WBQualityConstraintsCheckFormatConstraint')) { |
|
123 | + if ($this->sparqlHelper->matchesRegularExpression($text, $format)) { |
|
124 | 124 | $message = ''; |
125 | 125 | $status = CheckResult::STATUS_COMPLIANCE; |
126 | 126 | } else { |
127 | 127 | $message = wfMessage( |
128 | 128 | $syntaxClarification !== null ? |
129 | - 'wbqc-violation-message-format-clarification' : |
|
130 | - 'wbqc-violation-message-format' |
|
129 | + 'wbqc-violation-message-format-clarification' : 'wbqc-violation-message-format' |
|
131 | 130 | )->rawParams( |
132 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ), |
|
133 | - $this->constraintParameterRenderer->formatDataValue( new StringValue( $text ), Role::OBJECT ), |
|
134 | - $this->constraintParameterRenderer->formatByRole( Role::CONSTRAINT_PARAMETER_VALUE, |
|
135 | - '<code><nowiki>' . htmlspecialchars( $format ) . '</nowiki></code>' ) |
|
131 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY), |
|
132 | + $this->constraintParameterRenderer->formatDataValue(new StringValue($text), Role::OBJECT), |
|
133 | + $this->constraintParameterRenderer->formatByRole(Role::CONSTRAINT_PARAMETER_VALUE, |
|
134 | + '<code><nowiki>'.htmlspecialchars($format).'</nowiki></code>') |
|
136 | 135 | ); |
137 | - if ( $syntaxClarification !== null ) { |
|
138 | - $message->params( $syntaxClarification ); |
|
136 | + if ($syntaxClarification !== null) { |
|
137 | + $message->params($syntaxClarification); |
|
139 | 138 | } |
140 | 139 | $message = $message->escaped(); |
141 | 140 | $status = CheckResult::STATUS_VIOLATION; |
142 | 141 | } |
143 | 142 | } else { |
144 | - $message = wfMessage( "wbqc-violation-message-security-reason" ) |
|
145 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ) ) |
|
143 | + $message = wfMessage("wbqc-violation-message-security-reason") |
|
144 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM)) |
|
146 | 145 | ->escaped(); |
147 | 146 | $status = CheckResult::STATUS_TODO; |
148 | 147 | } |
149 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
148 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
150 | 149 | } |
151 | 150 | |
152 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
151 | + public function checkConstraintParameters(Constraint $constraint) { |
|
153 | 152 | $constraintParameters = $constraint->getConstraintParameters(); |
154 | 153 | $exceptions = []; |
155 | 154 | try { |
156 | - $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
157 | - } catch ( ConstraintParameterException $e ) { |
|
155 | + $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
156 | + } catch (ConstraintParameterException $e) { |
|
158 | 157 | $exceptions[] = $e; |
159 | 158 | } |
160 | 159 | try { |
161 | 160 | $this->constraintParameterParser->parseSyntaxClarificationParameter( |
162 | 161 | $constraintParameters, |
163 | - Language::factory( 'en' ) // errors are reported independent of language requested |
|
162 | + Language::factory('en') // errors are reported independent of language requested |
|
164 | 163 | ); |
165 | - } catch ( ConstraintParameterException $e ) { |
|
164 | + } catch (ConstraintParameterException $e) { |
|
166 | 165 | $exceptions[] = $e; |
167 | 166 | } |
168 | 167 | return $exceptions; |
@@ -14,16 +14,16 @@ |
||
14 | 14 | */ |
15 | 15 | class ValueOnlyChecker implements ConstraintChecker { |
16 | 16 | |
17 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
18 | - if ( $context->getType() === Context::TYPE_STATEMENT ) { |
|
19 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE, '' ); |
|
17 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
18 | + if ($context->getType() === Context::TYPE_STATEMENT) { |
|
19 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE, ''); |
|
20 | 20 | } else { |
21 | - $message = wfMessage( 'wbqc-violation-message-valueOnly' )->escaped(); |
|
22 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
21 | + $message = wfMessage('wbqc-violation-message-valueOnly')->escaped(); |
|
22 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
23 | 23 | } |
24 | 24 | } |
25 | 25 | |
26 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
26 | + public function checkConstraintParameters(Constraint $constraint) { |
|
27 | 27 | // no parameters |
28 | 28 | return []; |
29 | 29 | } |
@@ -52,46 +52,46 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return CheckResult |
54 | 54 | */ |
55 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
56 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
57 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
55 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
56 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
57 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
58 | 58 | } |
59 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
60 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK ); |
|
59 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
60 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | $parameters = []; |
64 | 64 | $constraintParameters = $constraint->getConstraintParameters(); |
65 | 65 | |
66 | - $properties = $this->constraintParameterParser->parsePropertiesParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
66 | + $properties = $this->constraintParameterParser->parsePropertiesParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
67 | 67 | $parameters['property'] = $properties; |
68 | 68 | |
69 | 69 | $message = ''; |
70 | 70 | $status = CheckResult::STATUS_COMPLIANCE; |
71 | 71 | |
72 | 72 | /** @var Snak $qualifier */ |
73 | - foreach ( $context->getSnakStatement()->getQualifiers() as $qualifier ) { |
|
73 | + foreach ($context->getSnakStatement()->getQualifiers() as $qualifier) { |
|
74 | 74 | $allowedQualifier = false; |
75 | - foreach ( $properties as $property ) { |
|
76 | - if ( $qualifier->getPropertyId()->equals( $property ) ) { |
|
75 | + foreach ($properties as $property) { |
|
76 | + if ($qualifier->getPropertyId()->equals($property)) { |
|
77 | 77 | $allowedQualifier = true; |
78 | 78 | break; |
79 | 79 | } |
80 | 80 | } |
81 | - if ( !$allowedQualifier ) { |
|
82 | - if ( empty( $properties ) || $properties === [ '' ] ) { |
|
83 | - $message = wfMessage( 'wbqc-violation-message-no-qualifiers' ); |
|
81 | + if (!$allowedQualifier) { |
|
82 | + if (empty($properties) || $properties === ['']) { |
|
83 | + $message = wfMessage('wbqc-violation-message-no-qualifiers'); |
|
84 | 84 | $message->rawParams( |
85 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
85 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
86 | 86 | ); |
87 | 87 | } else { |
88 | - $message = wfMessage( "wbqc-violation-message-qualifiers" ); |
|
88 | + $message = wfMessage("wbqc-violation-message-qualifiers"); |
|
89 | 89 | $message->rawParams( |
90 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ), |
|
91 | - $this->constraintParameterRenderer->formatEntityId( $qualifier->getPropertyId(), Role::QUALIFIER_PREDICATE ) |
|
90 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY), |
|
91 | + $this->constraintParameterRenderer->formatEntityId($qualifier->getPropertyId(), Role::QUALIFIER_PREDICATE) |
|
92 | 92 | ); |
93 | - $message->numParams( count( $properties ) ); |
|
94 | - $message->rawParams( $this->constraintParameterRenderer->formatPropertyIdList( $properties, Role::QUALIFIER_PREDICATE ) ); |
|
93 | + $message->numParams(count($properties)); |
|
94 | + $message->rawParams($this->constraintParameterRenderer->formatPropertyIdList($properties, Role::QUALIFIER_PREDICATE)); |
|
95 | 95 | } |
96 | 96 | $message = $message->escaped(); |
97 | 97 | $status = CheckResult::STATUS_VIOLATION; |
@@ -99,15 +99,15 @@ discard block |
||
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
102 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
102 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
103 | 103 | } |
104 | 104 | |
105 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
105 | + public function checkConstraintParameters(Constraint $constraint) { |
|
106 | 106 | $constraintParameters = $constraint->getConstraintParameters(); |
107 | 107 | $exceptions = []; |
108 | 108 | try { |
109 | - $this->constraintParameterParser->parsePropertiesParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
110 | - } catch ( ConstraintParameterException $e ) { |
|
109 | + $this->constraintParameterParser->parsePropertiesParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
110 | + } catch (ConstraintParameterException $e) { |
|
111 | 111 | $exceptions[] = $e; |
112 | 112 | } |
113 | 113 | return $exceptions; |
@@ -14,16 +14,16 @@ |
||
14 | 14 | */ |
15 | 15 | class ReferenceChecker implements ConstraintChecker { |
16 | 16 | |
17 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
18 | - if ( $context->getType() === Context::TYPE_REFERENCE ) { |
|
19 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE, '' ); |
|
17 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
18 | + if ($context->getType() === Context::TYPE_REFERENCE) { |
|
19 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE, ''); |
|
20 | 20 | } else { |
21 | - $message = wfMessage( 'wbqc-violation-message-reference' )->escaped(); |
|
22 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
21 | + $message = wfMessage('wbqc-violation-message-reference')->escaped(); |
|
22 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
23 | 23 | } |
24 | 24 | } |
25 | 25 | |
26 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
26 | + public function checkConstraintParameters(Constraint $constraint) { |
|
27 | 27 | // no parameters |
28 | 28 | return []; |
29 | 29 | } |