@@ -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 | |
@@ -118,36 +118,36 @@ discard block |
||
118 | 118 | * @throws ConstraintParameterException |
119 | 119 | * @return CheckResult |
120 | 120 | */ |
121 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
122 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
123 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
121 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
122 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
123 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
124 | 124 | } |
125 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
125 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
126 | 126 | // TODO T175565 |
127 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK ); |
|
127 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | $parameters = []; |
131 | 131 | |
132 | 132 | $snak = $context->getSnak(); |
133 | 133 | |
134 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
134 | + if (!$snak instanceof PropertyValueSnak) { |
|
135 | 135 | // nothing to check |
136 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
136 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | $minuend = $snak->getDataValue(); |
140 | 140 | |
141 | 141 | /** @var PropertyId $property */ |
142 | - list ( $min, $max, $property, $parameters ) = $this->parseConstraintParameters( $constraint ); |
|
142 | + list ($min, $max, $property, $parameters) = $this->parseConstraintParameters($constraint); |
|
143 | 143 | |
144 | 144 | // checks only the first occurrence of the referenced property (this constraint implies a single value constraint on that property) |
145 | 145 | /** @var Statement $otherStatement */ |
146 | - foreach ( $context->getEntity()->getStatements() as $otherStatement ) { |
|
146 | + foreach ($context->getEntity()->getStatements() as $otherStatement) { |
|
147 | 147 | $otherMainSnak = $otherStatement->getMainSnak(); |
148 | 148 | |
149 | 149 | if ( |
150 | - !$property->equals( $otherStatement->getPropertyId() ) || |
|
150 | + !$property->equals($otherStatement->getPropertyId()) || |
|
151 | 151 | $otherStatement->getRank() === Statement::RANK_DEPRECATED || |
152 | 152 | !$otherMainSnak instanceof PropertyValueSnak |
153 | 153 | ) { |
@@ -155,28 +155,27 @@ discard block |
||
155 | 155 | } |
156 | 156 | |
157 | 157 | $subtrahend = $otherMainSnak->getDataValue(); |
158 | - if ( $subtrahend->getType() === $minuend->getType() ) { |
|
159 | - $diff = $this->rangeInYears( $min, $max ) ? |
|
160 | - $this->rangeCheckerHelper->getDifferenceInYears( $minuend, $subtrahend ) : |
|
161 | - $this->rangeCheckerHelper->getDifference( $minuend, $subtrahend ); |
|
158 | + if ($subtrahend->getType() === $minuend->getType()) { |
|
159 | + $diff = $this->rangeInYears($min, $max) ? |
|
160 | + $this->rangeCheckerHelper->getDifferenceInYears($minuend, $subtrahend) : $this->rangeCheckerHelper->getDifference($minuend, $subtrahend); |
|
162 | 161 | |
163 | - if ( $this->rangeCheckerHelper->getComparison( $min, $diff ) > 0 || |
|
164 | - $this->rangeCheckerHelper->getComparison( $diff, $max ) > 0 |
|
162 | + if ($this->rangeCheckerHelper->getComparison($min, $diff) > 0 || |
|
163 | + $this->rangeCheckerHelper->getComparison($diff, $max) > 0 |
|
165 | 164 | ) { |
166 | 165 | // at least one of $min, $max is set at this point, otherwise there could be no violation |
167 | - $openness = $min !== null ? ( $max !== null ? '' : '-rightopen' ) : '-leftopen'; |
|
168 | - $message = wfMessage( "wbqc-violation-message-diff-within-range$openness" ); |
|
166 | + $openness = $min !== null ? ($max !== null ? '' : '-rightopen') : '-leftopen'; |
|
167 | + $message = wfMessage("wbqc-violation-message-diff-within-range$openness"); |
|
169 | 168 | $message->rawParams( |
170 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ), |
|
171 | - $this->constraintParameterRenderer->formatDataValue( $minuend, Role::OBJECT ), |
|
172 | - $this->constraintParameterRenderer->formatEntityId( $otherStatement->getPropertyId(), Role::PREDICATE ), |
|
173 | - $this->constraintParameterRenderer->formatDataValue( $subtrahend, Role::OBJECT ) |
|
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) |
|
174 | 173 | ); |
175 | - if ( $min !== null ) { |
|
176 | - $message->rawParams( $this->constraintParameterRenderer->formatDataValue( $min, Role::OBJECT ) ); |
|
174 | + if ($min !== null) { |
|
175 | + $message->rawParams($this->constraintParameterRenderer->formatDataValue($min, Role::OBJECT)); |
|
177 | 176 | } |
178 | - if ( $max !== null ) { |
|
179 | - $message->rawParams( $this->constraintParameterRenderer->formatDataValue( $max, Role::OBJECT ) ); |
|
177 | + if ($max !== null) { |
|
178 | + $message->rawParams($this->constraintParameterRenderer->formatDataValue($max, Role::OBJECT)); |
|
180 | 179 | } |
181 | 180 | $message = $message->escaped(); |
182 | 181 | $status = CheckResult::STATUS_VIOLATION; |
@@ -185,19 +184,19 @@ discard block |
||
185 | 184 | $status = CheckResult::STATUS_COMPLIANCE; |
186 | 185 | } |
187 | 186 | } else { |
188 | - $message = wfMessage( "wbqc-violation-message-diff-within-range-must-have-equal-types" )->escaped(); |
|
187 | + $message = wfMessage("wbqc-violation-message-diff-within-range-must-have-equal-types")->escaped(); |
|
189 | 188 | $status = CheckResult::STATUS_VIOLATION; |
190 | 189 | } |
191 | 190 | |
192 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
191 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
193 | 192 | } |
194 | 193 | |
195 | - $message = wfMessage( "wbqc-violation-message-diff-within-range-property-must-exist" )->escaped(); |
|
194 | + $message = wfMessage("wbqc-violation-message-diff-within-range-property-must-exist")->escaped(); |
|
196 | 195 | $status = CheckResult::STATUS_VIOLATION; |
197 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
196 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
198 | 197 | } |
199 | 198 | |
200 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
199 | + public function checkConstraintParameters(Constraint $constraint) { |
|
201 | 200 | $constraintParameters = $constraint->getConstraintParameters(); |
202 | 201 | $exceptions = []; |
203 | 202 | try { |
@@ -206,12 +205,12 @@ discard block |
||
206 | 205 | $constraint->getConstraintTypeItemId(), |
207 | 206 | 'quantity' |
208 | 207 | ); |
209 | - } catch ( ConstraintParameterException $e ) { |
|
208 | + } catch (ConstraintParameterException $e) { |
|
210 | 209 | $exceptions[] = $e; |
211 | 210 | } |
212 | 211 | try { |
213 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
214 | - } catch ( ConstraintParameterException $e ) { |
|
212 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
213 | + } catch (ConstraintParameterException $e) { |
|
215 | 214 | $exceptions[] = $e; |
216 | 215 | } |
217 | 216 | return $exceptions; |
@@ -68,22 +68,22 @@ discard block |
||
68 | 68 | * @throws ConstraintParameterException |
69 | 69 | * @return CheckResult |
70 | 70 | */ |
71 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
72 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
73 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
71 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
72 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
73 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
74 | 74 | } |
75 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
75 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
76 | 76 | // TODO T175562 |
77 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK ); |
|
77 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | $parameters = []; |
81 | 81 | $constraintParameters = $constraint->getConstraintParameters(); |
82 | 82 | |
83 | - $propertyId = $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
84 | - $parameters['property'] = [ $propertyId ]; |
|
83 | + $propertyId = $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
84 | + $parameters['property'] = [$propertyId]; |
|
85 | 85 | |
86 | - $items = $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), false ); |
|
86 | + $items = $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), false); |
|
87 | 87 | $parameters['items'] = $items; |
88 | 88 | |
89 | 89 | /* |
@@ -91,16 +91,16 @@ discard block |
||
91 | 91 | * a) a property only |
92 | 92 | * b) a property and a number of items (each combination of property and item forming an individual claim) |
93 | 93 | */ |
94 | - if ( $items === [] ) { |
|
94 | + if ($items === []) { |
|
95 | 95 | $offendingStatement = $this->connectionCheckerHelper->findStatementWithProperty( |
96 | 96 | $context->getEntity()->getStatements(), |
97 | 97 | $propertyId |
98 | 98 | ); |
99 | - if ( $offendingStatement !== null ) { |
|
100 | - $message = wfMessage( "wbqc-violation-message-conflicts-with-property" ) |
|
99 | + if ($offendingStatement !== null) { |
|
100 | + $message = wfMessage("wbqc-violation-message-conflicts-with-property") |
|
101 | 101 | ->rawParams( |
102 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ), |
|
103 | - $this->constraintParameterRenderer->formatEntityId( $propertyId, Role::PREDICATE ) |
|
102 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY), |
|
103 | + $this->constraintParameterRenderer->formatEntityId($propertyId, Role::PREDICATE) |
|
104 | 104 | ) |
105 | 105 | ->escaped(); |
106 | 106 | $status = CheckResult::STATUS_VIOLATION; |
@@ -114,13 +114,13 @@ discard block |
||
114 | 114 | $propertyId, |
115 | 115 | $items |
116 | 116 | ); |
117 | - if ( $offendingStatement !== null ) { |
|
118 | - $offendingValue = ItemIdSnakValue::fromSnak( $offendingStatement->getMainSnak() ); |
|
119 | - $message = wfMessage( "wbqc-violation-message-conflicts-with-claim" ) |
|
117 | + if ($offendingStatement !== null) { |
|
118 | + $offendingValue = ItemIdSnakValue::fromSnak($offendingStatement->getMainSnak()); |
|
119 | + $message = wfMessage("wbqc-violation-message-conflicts-with-claim") |
|
120 | 120 | ->rawParams( |
121 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ), |
|
122 | - $this->constraintParameterRenderer->formatEntityId( $propertyId, Role::PREDICATE ), |
|
123 | - $this->constraintParameterRenderer->formatItemIdSnakValue( $offendingValue, Role::OBJECT ) |
|
121 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY), |
|
122 | + $this->constraintParameterRenderer->formatEntityId($propertyId, Role::PREDICATE), |
|
123 | + $this->constraintParameterRenderer->formatItemIdSnakValue($offendingValue, Role::OBJECT) |
|
124 | 124 | ) |
125 | 125 | ->escaped(); |
126 | 126 | $status = CheckResult::STATUS_VIOLATION; |
@@ -130,20 +130,20 @@ discard block |
||
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
133 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
134 | 134 | } |
135 | 135 | |
136 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
136 | + public function checkConstraintParameters(Constraint $constraint) { |
|
137 | 137 | $constraintParameters = $constraint->getConstraintParameters(); |
138 | 138 | $exceptions = []; |
139 | 139 | try { |
140 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
141 | - } catch ( ConstraintParameterException $e ) { |
|
140 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
141 | + } catch (ConstraintParameterException $e) { |
|
142 | 142 | $exceptions[] = $e; |
143 | 143 | } |
144 | 144 | try { |
145 | - $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), false ); |
|
146 | - } catch ( ConstraintParameterException $e ) { |
|
145 | + $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), false); |
|
146 | + } catch (ConstraintParameterException $e) { |
|
147 | 147 | $exceptions[] = $e; |
148 | 148 | } |
149 | 149 | return $exceptions; |
@@ -49,43 +49,43 @@ |
||
49 | 49 | * @throws ConstraintParameterException |
50 | 50 | * @return CheckResult |
51 | 51 | */ |
52 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
53 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
54 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
52 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
53 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
54 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | $parameters = []; |
58 | 58 | $constraintParameters = $constraint->getConstraintParameters(); |
59 | 59 | |
60 | - $items = $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), true ); |
|
60 | + $items = $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), true); |
|
61 | 61 | $parameters['item'] = $items; |
62 | 62 | |
63 | 63 | $snak = $context->getSnak(); |
64 | 64 | |
65 | - $message = wfMessage( 'wbqc-violation-message-one-of' ); |
|
66 | - $message->rawParams( $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ) ); |
|
67 | - $message->numParams( count( $items ) ); |
|
68 | - $message->rawParams( $this->constraintParameterRenderer->formatItemIdSnakValueList( $items, Role::OBJECT ) ); |
|
65 | + $message = wfMessage('wbqc-violation-message-one-of'); |
|
66 | + $message->rawParams($this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE)); |
|
67 | + $message->numParams(count($items)); |
|
68 | + $message->rawParams($this->constraintParameterRenderer->formatItemIdSnakValueList($items, Role::OBJECT)); |
|
69 | 69 | $message = $message->escaped(); |
70 | 70 | $status = CheckResult::STATUS_VIOLATION; |
71 | 71 | |
72 | - foreach ( $items as $item ) { |
|
73 | - if ( $item->matchesSnak( $snak ) ) { |
|
72 | + foreach ($items as $item) { |
|
73 | + if ($item->matchesSnak($snak)) { |
|
74 | 74 | $message = ''; |
75 | 75 | $status = CheckResult::STATUS_COMPLIANCE; |
76 | 76 | break; |
77 | 77 | } |
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 | $constraintParameters = $constraint->getConstraintParameters(); |
85 | 85 | $exceptions = []; |
86 | 86 | try { |
87 | - $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), true ); |
|
88 | - } catch ( ConstraintParameterException $e ) { |
|
87 | + $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), true); |
|
88 | + } catch (ConstraintParameterException $e) { |
|
89 | 89 | $exceptions[] = $e; |
90 | 90 | } |
91 | 91 | return $exceptions; |
@@ -50,46 +50,46 @@ |
||
50 | 50 | * @throws ConstraintParameterException |
51 | 51 | * @return CheckResult |
52 | 52 | */ |
53 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
54 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
55 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
53 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
54 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
55 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
56 | 56 | } |
57 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
58 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK ); |
|
57 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
58 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | $parameters = []; |
62 | 62 | $constraintParameters = $constraint->getConstraintParameters(); |
63 | 63 | |
64 | - $propertyId = $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
65 | - $parameters['property'] = [ $propertyId ]; |
|
64 | + $propertyId = $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
65 | + $parameters['property'] = [$propertyId]; |
|
66 | 66 | |
67 | - $message = wfMessage( "wbqc-violation-message-mandatory-qualifier" ) |
|
67 | + $message = wfMessage("wbqc-violation-message-mandatory-qualifier") |
|
68 | 68 | ->rawParams( |
69 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ), |
|
70 | - $this->constraintParameterRenderer->formatEntityId( $propertyId, Role::QUALIFIER_PREDICATE ) |
|
69 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY), |
|
70 | + $this->constraintParameterRenderer->formatEntityId($propertyId, Role::QUALIFIER_PREDICATE) |
|
71 | 71 | ) |
72 | 72 | ->escaped(); |
73 | 73 | $status = CheckResult::STATUS_VIOLATION; |
74 | 74 | |
75 | 75 | /** @var Snak $qualifier */ |
76 | - foreach ( $context->getSnakStatement()->getQualifiers() as $qualifier ) { |
|
77 | - if ( $propertyId->equals( $qualifier->getPropertyId() ) ) { |
|
76 | + foreach ($context->getSnakStatement()->getQualifiers() as $qualifier) { |
|
77 | + if ($propertyId->equals($qualifier->getPropertyId())) { |
|
78 | 78 | $message = ''; |
79 | 79 | $status = CheckResult::STATUS_COMPLIANCE; |
80 | 80 | break; |
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
84 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
84 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
85 | 85 | } |
86 | 86 | |
87 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
87 | + public function checkConstraintParameters(Constraint $constraint) { |
|
88 | 88 | $constraintParameters = $constraint->getConstraintParameters(); |
89 | 89 | $exceptions = []; |
90 | 90 | try { |
91 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
92 | - } catch ( ConstraintParameterException $e ) { |
|
91 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
92 | + } catch (ConstraintParameterException $e) { |
|
93 | 93 | $exceptions[] = $e; |
94 | 94 | } |
95 | 95 | return $exceptions; |
@@ -50,46 +50,46 @@ discard block |
||
50 | 50 | * @throws ConstraintParameterException |
51 | 51 | * @return CheckResult |
52 | 52 | */ |
53 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
54 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
55 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
53 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
54 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
55 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
56 | 56 | } |
57 | - if ( $context->getType() !== Context::TYPE_STATEMENT ) { |
|
58 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK ); |
|
57 | + if ($context->getType() !== Context::TYPE_STATEMENT) { |
|
58 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_MAIN_SNAK); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | $parameters = []; |
62 | 62 | $constraintParameters = $constraint->getConstraintParameters(); |
63 | 63 | |
64 | - $properties = $this->constraintParameterParser->parsePropertiesParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
64 | + $properties = $this->constraintParameterParser->parsePropertiesParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
65 | 65 | $parameters['property'] = $properties; |
66 | 66 | |
67 | 67 | $message = ''; |
68 | 68 | $status = CheckResult::STATUS_COMPLIANCE; |
69 | 69 | |
70 | 70 | /** @var Snak $qualifier */ |
71 | - foreach ( $context->getSnakStatement()->getQualifiers() as $qualifier ) { |
|
71 | + foreach ($context->getSnakStatement()->getQualifiers() as $qualifier) { |
|
72 | 72 | $allowedQualifier = false; |
73 | - foreach ( $properties as $property ) { |
|
74 | - if ( $qualifier->getPropertyId()->equals( $property ) ) { |
|
73 | + foreach ($properties as $property) { |
|
74 | + if ($qualifier->getPropertyId()->equals($property)) { |
|
75 | 75 | $allowedQualifier = true; |
76 | 76 | break; |
77 | 77 | } |
78 | 78 | } |
79 | - if ( !$allowedQualifier ) { |
|
80 | - if ( empty( $properties ) || $properties === [ '' ] ) { |
|
81 | - $message = wfMessage( 'wbqc-violation-message-no-qualifiers' ); |
|
79 | + if (!$allowedQualifier) { |
|
80 | + if (empty($properties) || $properties === ['']) { |
|
81 | + $message = wfMessage('wbqc-violation-message-no-qualifiers'); |
|
82 | 82 | $message->rawParams( |
83 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
83 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
84 | 84 | ); |
85 | 85 | } else { |
86 | - $message = wfMessage( "wbqc-violation-message-qualifiers" ); |
|
86 | + $message = wfMessage("wbqc-violation-message-qualifiers"); |
|
87 | 87 | $message->rawParams( |
88 | - $this->constraintParameterRenderer->formatEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ), |
|
89 | - $this->constraintParameterRenderer->formatEntityId( $qualifier->getPropertyId(), Role::QUALIFIER_PREDICATE ) |
|
88 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY), |
|
89 | + $this->constraintParameterRenderer->formatEntityId($qualifier->getPropertyId(), Role::QUALIFIER_PREDICATE) |
|
90 | 90 | ); |
91 | - $message->numParams( count( $properties ) ); |
|
92 | - $message->rawParams( $this->constraintParameterRenderer->formatPropertyIdList( $properties, Role::QUALIFIER_PREDICATE ) ); |
|
91 | + $message->numParams(count($properties)); |
|
92 | + $message->rawParams($this->constraintParameterRenderer->formatPropertyIdList($properties, Role::QUALIFIER_PREDICATE)); |
|
93 | 93 | } |
94 | 94 | $message = $message->escaped(); |
95 | 95 | $status = CheckResult::STATUS_VIOLATION; |
@@ -97,15 +97,15 @@ discard block |
||
97 | 97 | } |
98 | 98 | } |
99 | 99 | |
100 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
100 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
101 | 101 | } |
102 | 102 | |
103 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
103 | + public function checkConstraintParameters(Constraint $constraint) { |
|
104 | 104 | $constraintParameters = $constraint->getConstraintParameters(); |
105 | 105 | $exceptions = []; |
106 | 106 | try { |
107 | - $this->constraintParameterParser->parsePropertiesParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
108 | - } catch ( ConstraintParameterException $e ) { |
|
107 | + $this->constraintParameterParser->parsePropertiesParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
108 | + } catch (ConstraintParameterException $e) { |
|
109 | 109 | $exceptions[] = $e; |
110 | 110 | } |
111 | 111 | return $exceptions; |
@@ -71,25 +71,25 @@ discard block |
||
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 | - $items = $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), false ); |
|
85 | + $items = $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), false); |
|
86 | 86 | $parameters['items'] = $items; |
87 | 87 | |
88 | 88 | $snak = $context->getSnak(); |
89 | 89 | |
90 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
90 | + if (!$snak instanceof PropertyValueSnak) { |
|
91 | 91 | // nothing to check |
92 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
92 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | $dataValue = $snak->getDataValue(); |
@@ -98,22 +98,22 @@ discard block |
||
98 | 98 | * error handling: |
99 | 99 | * type of $dataValue for properties with 'Target required claim' constraint has to be 'wikibase-entityid' |
100 | 100 | */ |
101 | - if ( $dataValue->getType() !== 'wikibase-entityid' ) { |
|
102 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
101 | + if ($dataValue->getType() !== 'wikibase-entityid') { |
|
102 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
103 | 103 | ->rawParams( |
104 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
104 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
105 | 105 | 'wikibase-entityid' // TODO is there a message for this type so we can localize it? |
106 | 106 | ) |
107 | 107 | ->escaped(); |
108 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
108 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
109 | 109 | } |
110 | 110 | /** @var EntityIdValue $dataValue */ |
111 | 111 | |
112 | 112 | $targetEntityId = $dataValue->getEntityId(); |
113 | - $targetEntity = $this->entityLookup->getEntity( $targetEntityId ); |
|
114 | - if ( $targetEntity === null ) { |
|
115 | - $message = wfMessage( "wbqc-violation-message-target-entity-must-exist" )->escaped(); |
|
116 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
113 | + $targetEntity = $this->entityLookup->getEntity($targetEntityId); |
|
114 | + if ($targetEntity === null) { |
|
115 | + $message = wfMessage("wbqc-violation-message-target-entity-must-exist")->escaped(); |
|
116 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /* |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * a) a property only |
122 | 122 | * b) a property and a number of items (each combination forming an individual claim) |
123 | 123 | */ |
124 | - if ( $items === [] ) { |
|
124 | + if ($items === []) { |
|
125 | 125 | $requiredStatement = $this->connectionCheckerHelper->findStatementWithProperty( |
126 | 126 | $targetEntity->getStatements(), |
127 | 127 | $propertyId |
@@ -134,37 +134,37 @@ discard block |
||
134 | 134 | ); |
135 | 135 | } |
136 | 136 | |
137 | - if ( $requiredStatement !== null ) { |
|
137 | + if ($requiredStatement !== null) { |
|
138 | 138 | $status = CheckResult::STATUS_COMPLIANCE; |
139 | 139 | $message = ''; |
140 | 140 | } else { |
141 | 141 | $status = CheckResult::STATUS_VIOLATION; |
142 | - $message = wfMessage( 'wbqc-violation-message-target-required-claim' ); |
|
142 | + $message = wfMessage('wbqc-violation-message-target-required-claim'); |
|
143 | 143 | $message->rawParams( |
144 | - $this->constraintParameterRenderer->formatEntityId( $targetEntityId, Role::SUBJECT ), |
|
145 | - $this->constraintParameterRenderer->formatEntityId( $propertyId, Role::PREDICATE ) |
|
144 | + $this->constraintParameterRenderer->formatEntityId($targetEntityId, Role::SUBJECT), |
|
145 | + $this->constraintParameterRenderer->formatEntityId($propertyId, Role::PREDICATE) |
|
146 | 146 | ); |
147 | - $message->numParams( count( $items ) ); |
|
148 | - $message->rawParams( $this->constraintParameterRenderer->formatItemIdSnakValueList( $items, Role::OBJECT ) ); |
|
147 | + $message->numParams(count($items)); |
|
148 | + $message->rawParams($this->constraintParameterRenderer->formatItemIdSnakValueList($items, Role::OBJECT)); |
|
149 | 149 | $message = $message->escaped(); |
150 | 150 | } |
151 | 151 | |
152 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
153 | - ->withMetadata( Metadata::ofDependencyMetadata( |
|
154 | - DependencyMetadata::ofEntityId( $targetEntityId ) ) ); |
|
152 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
153 | + ->withMetadata(Metadata::ofDependencyMetadata( |
|
154 | + DependencyMetadata::ofEntityId($targetEntityId) )); |
|
155 | 155 | } |
156 | 156 | |
157 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
157 | + public function checkConstraintParameters(Constraint $constraint) { |
|
158 | 158 | $constraintParameters = $constraint->getConstraintParameters(); |
159 | 159 | $exceptions = []; |
160 | 160 | try { |
161 | - $this->constraintParameterParser->parsePropertyParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
162 | - } catch ( ConstraintParameterException $e ) { |
|
161 | + $this->constraintParameterParser->parsePropertyParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
162 | + } catch (ConstraintParameterException $e) { |
|
163 | 163 | $exceptions[] = $e; |
164 | 164 | } |
165 | 165 | try { |
166 | - $this->constraintParameterParser->parseItemsParameter( $constraintParameters, $constraint->getConstraintTypeItemId(), false ); |
|
167 | - } catch ( ConstraintParameterException $e ) { |
|
166 | + $this->constraintParameterParser->parseItemsParameter($constraintParameters, $constraint->getConstraintTypeItemId(), false); |
|
167 | + } catch (ConstraintParameterException $e) { |
|
168 | 168 | $exceptions[] = $e; |
169 | 169 | } |
170 | 170 | return $exceptions; |
@@ -71,26 +71,26 @@ discard block |
||
71 | 71 | * @throws ConstraintParameterException |
72 | 72 | * @return CheckResult |
73 | 73 | */ |
74 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
74 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
75 | 75 | $parameters = []; |
76 | 76 | $constraintParameters = $constraint->getConstraintParameters(); |
77 | 77 | |
78 | - $format = $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
79 | - $parameters['pattern'] = [ $format ]; |
|
78 | + $format = $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
79 | + $parameters['pattern'] = [$format]; |
|
80 | 80 | |
81 | 81 | $syntaxClarification = $this->constraintParameterParser->parseSyntaxClarificationParameter( |
82 | 82 | $constraintParameters, |
83 | 83 | WikibaseRepo::getDefaultInstance()->getUserLanguage() // TODO make this part of the Context? |
84 | 84 | ); |
85 | - if ( $syntaxClarification !== null ) { |
|
86 | - $parameters['clarification'] = [ $syntaxClarification ]; |
|
85 | + if ($syntaxClarification !== null) { |
|
86 | + $parameters['clarification'] = [$syntaxClarification]; |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | $snak = $context->getSnak(); |
90 | 90 | |
91 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
91 | + if (!$snak instanceof PropertyValueSnak) { |
|
92 | 92 | // nothing to check |
93 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
93 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | $dataValue = $snak->getDataValue(); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * error handling: |
100 | 100 | * type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext' |
101 | 101 | */ |
102 | - switch ( $dataValue->getType() ) { |
|
102 | + switch ($dataValue->getType()) { |
|
103 | 103 | case 'string': |
104 | 104 | $text = $dataValue->getValue(); |
105 | 105 | break; |
@@ -108,60 +108,59 @@ discard block |
||
108 | 108 | $text = $dataValue->getText(); |
109 | 109 | break; |
110 | 110 | default: |
111 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
111 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
112 | 112 | ->rawParams( |
113 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
114 | - wfMessage( 'datatypes-type-string' )->escaped(), |
|
115 | - wfMessage( 'datatypes-type-monolingualtext' )->escaped() |
|
113 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
114 | + wfMessage('datatypes-type-string')->escaped(), |
|
115 | + wfMessage('datatypes-type-monolingualtext')->escaped() |
|
116 | 116 | ) |
117 | 117 | ->escaped(); |
118 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
118 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
119 | 119 | } |
120 | 120 | |
121 | - if ( $this->sparqlHelper !== null && $this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) ) { |
|
122 | - if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) { |
|
121 | + if ($this->sparqlHelper !== null && $this->config->get('WBQualityConstraintsCheckFormatConstraint')) { |
|
122 | + if ($this->sparqlHelper->matchesRegularExpression($text, $format)) { |
|
123 | 123 | $message = ''; |
124 | 124 | $status = CheckResult::STATUS_COMPLIANCE; |
125 | 125 | } else { |
126 | 126 | $message = wfMessage( |
127 | 127 | $syntaxClarification !== null ? |
128 | - 'wbqc-violation-message-format-clarification' : |
|
129 | - 'wbqc-violation-message-format' |
|
128 | + 'wbqc-violation-message-format-clarification' : 'wbqc-violation-message-format' |
|
130 | 129 | )->rawParams( |
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>' ) |
|
130 | + $this->constraintParameterRenderer->formatEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY), |
|
131 | + $this->constraintParameterRenderer->formatDataValue(new StringValue($text), Role::OBJECT), |
|
132 | + $this->constraintParameterRenderer->formatByRole(Role::CONSTRAINT_PARAMETER_VALUE, |
|
133 | + '<code><nowiki>'.htmlspecialchars($format).'</nowiki></code>') |
|
135 | 134 | ); |
136 | - if ( $syntaxClarification !== null ) { |
|
137 | - $message->params( $syntaxClarification ); |
|
135 | + if ($syntaxClarification !== null) { |
|
136 | + $message->params($syntaxClarification); |
|
138 | 137 | } |
139 | 138 | $message = $message->escaped(); |
140 | 139 | $status = CheckResult::STATUS_VIOLATION; |
141 | 140 | } |
142 | 141 | } else { |
143 | - $message = wfMessage( "wbqc-violation-message-security-reason" ) |
|
144 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ) ) |
|
142 | + $message = wfMessage("wbqc-violation-message-security-reason") |
|
143 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM)) |
|
145 | 144 | ->escaped(); |
146 | 145 | $status = CheckResult::STATUS_TODO; |
147 | 146 | } |
148 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
147 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
149 | 148 | } |
150 | 149 | |
151 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
150 | + public function checkConstraintParameters(Constraint $constraint) { |
|
152 | 151 | $constraintParameters = $constraint->getConstraintParameters(); |
153 | 152 | $exceptions = []; |
154 | 153 | try { |
155 | - $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
156 | - } catch ( ConstraintParameterException $e ) { |
|
154 | + $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
155 | + } catch (ConstraintParameterException $e) { |
|
157 | 156 | $exceptions[] = $e; |
158 | 157 | } |
159 | 158 | try { |
160 | 159 | $this->constraintParameterParser->parseSyntaxClarificationParameter( |
161 | 160 | $constraintParameters, |
162 | - Language::factory( 'en' ) // errors are reported independent of language requested |
|
161 | + Language::factory('en') // errors are reported independent of language requested |
|
163 | 162 | ); |
164 | - } catch ( ConstraintParameterException $e ) { |
|
163 | + } catch (ConstraintParameterException $e) { |
|
165 | 164 | $exceptions[] = $e; |
166 | 165 | } |
167 | 166 | return $exceptions; |
@@ -82,35 +82,35 @@ discard block |
||
82 | 82 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
83 | 83 | * @return CheckResult |
84 | 84 | */ |
85 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
86 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
87 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
85 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
86 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
87 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | $parameters = []; |
91 | 91 | $constraintParameters = $constraint->getConstraintParameters(); |
92 | 92 | |
93 | - $classes = $this->constraintParameterParser->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
93 | + $classes = $this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
94 | 94 | $parameters['class'] = array_map( |
95 | - function( $id ) { |
|
96 | - return new ItemId( $id ); |
|
95 | + function($id) { |
|
96 | + return new ItemId($id); |
|
97 | 97 | }, |
98 | 98 | $classes |
99 | 99 | ); |
100 | 100 | |
101 | - $relation = $this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
102 | - if ( $relation === 'instance' ) { |
|
103 | - $relationId = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
104 | - } elseif ( $relation === 'subclass' ) { |
|
105 | - $relationId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
101 | + $relation = $this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
102 | + if ($relation === 'instance') { |
|
103 | + $relationId = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
104 | + } elseif ($relation === 'subclass') { |
|
105 | + $relationId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
106 | 106 | } |
107 | - $parameters['relation'] = [ $relation ]; |
|
107 | + $parameters['relation'] = [$relation]; |
|
108 | 108 | |
109 | 109 | $snak = $context->getSnak(); |
110 | 110 | |
111 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
111 | + if (!$snak instanceof PropertyValueSnak) { |
|
112 | 112 | // nothing to check |
113 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, '' ); |
|
113 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, ''); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | $dataValue = $snak->getDataValue(); |
@@ -119,22 +119,22 @@ discard block |
||
119 | 119 | * error handling: |
120 | 120 | * type of $dataValue for properties with 'Value type' constraint has to be 'wikibase-entityid' |
121 | 121 | */ |
122 | - if ( $dataValue->getType() !== 'wikibase-entityid' ) { |
|
123 | - $message = wfMessage( "wbqc-violation-message-value-needed-of-type" ) |
|
122 | + if ($dataValue->getType() !== 'wikibase-entityid') { |
|
123 | + $message = wfMessage("wbqc-violation-message-value-needed-of-type") |
|
124 | 124 | ->rawParams( |
125 | - $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ), |
|
125 | + $this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM), |
|
126 | 126 | 'wikibase-entityid' // TODO is there a message for this type so we can localize it? |
127 | 127 | ) |
128 | 128 | ->escaped(); |
129 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
129 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
130 | 130 | } |
131 | 131 | /** @var EntityIdValue $dataValue */ |
132 | 132 | |
133 | - $item = $this->entityLookup->getEntity( $dataValue->getEntityId() ); |
|
133 | + $item = $this->entityLookup->getEntity($dataValue->getEntityId()); |
|
134 | 134 | |
135 | - if ( !( $item instanceof StatementListProvider ) ) { |
|
136 | - $message = wfMessage( "wbqc-violation-message-value-entity-must-exist" )->escaped(); |
|
137 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
135 | + if (!($item instanceof StatementListProvider)) { |
|
136 | + $message = wfMessage("wbqc-violation-message-value-entity-must-exist")->escaped(); |
|
137 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | $statements = $item->getStatements(); |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $classes |
146 | 146 | ); |
147 | 147 | |
148 | - if ( $result->getBool() ) { |
|
148 | + if ($result->getBool()) { |
|
149 | 149 | $message = ''; |
150 | 150 | $status = CheckResult::STATUS_COMPLIANCE; |
151 | 151 | } else { |
@@ -159,21 +159,21 @@ discard block |
||
159 | 159 | $status = CheckResult::STATUS_VIOLATION; |
160 | 160 | } |
161 | 161 | |
162 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
163 | - ->withMetadata( $result->getMetadata() ); |
|
162 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
163 | + ->withMetadata($result->getMetadata()); |
|
164 | 164 | } |
165 | 165 | |
166 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
166 | + public function checkConstraintParameters(Constraint $constraint) { |
|
167 | 167 | $constraintParameters = $constraint->getConstraintParameters(); |
168 | 168 | $exceptions = []; |
169 | 169 | try { |
170 | - $this->constraintParameterParser->parseClassParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
171 | - } catch ( ConstraintParameterException $e ) { |
|
170 | + $this->constraintParameterParser->parseClassParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
171 | + } catch (ConstraintParameterException $e) { |
|
172 | 172 | $exceptions[] = $e; |
173 | 173 | } |
174 | 174 | try { |
175 | - $this->constraintParameterParser->parseRelationParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
176 | - } catch ( ConstraintParameterException $e ) { |
|
175 | + $this->constraintParameterParser->parseRelationParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
176 | + } catch (ConstraintParameterException $e) { |
|
177 | 177 | $exceptions[] = $e; |
178 | 178 | } |
179 | 179 | return $exceptions; |
@@ -50,22 +50,22 @@ discard block |
||
50 | 50 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
51 | 51 | * @return CheckResult |
52 | 52 | */ |
53 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
54 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
55 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
53 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
54 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
55 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | $parameters = []; |
59 | 59 | |
60 | - if ( $this->sparqlHelper !== null ) { |
|
61 | - if ( $context->getType() === 'statement' ) { |
|
60 | + if ($this->sparqlHelper !== null) { |
|
61 | + if ($context->getType() === 'statement') { |
|
62 | 62 | $result = $this->sparqlHelper->findEntitiesWithSameStatement( |
63 | 63 | $context->getSnakStatement(), |
64 | 64 | true // ignore deprecated statements |
65 | 65 | ); |
66 | 66 | } else { |
67 | - if ( $context->getSnak()->getType() !== 'value' ) { |
|
68 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
67 | + if ($context->getSnak()->getType() !== 'value') { |
|
68 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
69 | 69 | } |
70 | 70 | $result = $this->sparqlHelper->findEntitiesWithSameQualifierOrReference( |
71 | 71 | $context->getEntity()->getId(), |
@@ -78,29 +78,29 @@ discard block |
||
78 | 78 | $otherEntities = $result->getArray(); |
79 | 79 | $metadata = $result->getMetadata(); |
80 | 80 | |
81 | - if ( $otherEntities === [] ) { |
|
81 | + if ($otherEntities === []) { |
|
82 | 82 | $status = CheckResult::STATUS_COMPLIANCE; |
83 | 83 | $message = ''; |
84 | 84 | } else { |
85 | 85 | $status = CheckResult::STATUS_VIOLATION; |
86 | - $message = wfMessage( 'wbqc-violation-message-unique-value' ) |
|
87 | - ->numParams( count( $otherEntities ) ) |
|
88 | - ->rawParams( $this->constraintParameterRenderer->formatEntityIdList( $otherEntities, Role::SUBJECT ) ) |
|
86 | + $message = wfMessage('wbqc-violation-message-unique-value') |
|
87 | + ->numParams(count($otherEntities)) |
|
88 | + ->rawParams($this->constraintParameterRenderer->formatEntityIdList($otherEntities, Role::SUBJECT)) |
|
89 | 89 | ->escaped(); |
90 | 90 | } |
91 | 91 | } else { |
92 | 92 | $status = CheckResult::STATUS_TODO; |
93 | - $message = wfMessage( "wbqc-violation-message-not-yet-implemented" ) |
|
94 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM ) ) |
|
93 | + $message = wfMessage("wbqc-violation-message-not-yet-implemented") |
|
94 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraint->getConstraintTypeItemId(), Role::CONSTRAINT_TYPE_ITEM)) |
|
95 | 95 | ->escaped(); |
96 | 96 | $metadata = Metadata::blank(); |
97 | 97 | } |
98 | 98 | |
99 | - return ( new CheckResult( $context, $constraint, $parameters, $status, $message ) ) |
|
100 | - ->withMetadata( $metadata ); |
|
99 | + return (new CheckResult($context, $constraint, $parameters, $status, $message)) |
|
100 | + ->withMetadata($metadata); |
|
101 | 101 | } |
102 | 102 | |
103 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
103 | + public function checkConstraintParameters(Constraint $constraint) { |
|
104 | 104 | // no parameters |
105 | 105 | return []; |
106 | 106 | } |