@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport; |
6 | 6 | |
@@ -25,9 +25,9 @@ discard block |
||
25 | 25 | public const ENTITY_LOOKUP = 'WBQC_EntityLookup'; |
26 | 26 | public const ENTITY_LOOKUP_WITHOUT_CACHE = 'WBQC_EntityLookupWithoutCache'; |
27 | 27 | |
28 | - private static function getService( ?MediaWikiServices $services, $name ) { |
|
28 | + private static function getService(?MediaWikiServices $services, $name) { |
|
29 | 29 | $services ??= MediaWikiServices::getInstance(); |
30 | - return $services->getService( $name ); |
|
30 | + return $services->getService($name); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | * this lookup ignores exceptions (such as unresolved redirects, T93273), |
38 | 38 | * as it is more convenient to treat them all as missing entities in WBQC. |
39 | 39 | */ |
40 | - public static function getEntityLookup( ?MediaWikiServices $services = null ): EntityLookup { |
|
41 | - return self::getService( $services, self::ENTITY_LOOKUP ); |
|
40 | + public static function getEntityLookup(?MediaWikiServices $services = null): EntityLookup { |
|
41 | + return self::getService($services, self::ENTITY_LOOKUP); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | * were exceeding the request memory limit when they were all added to the cache (T227450). |
49 | 49 | * Also, like {@link self::getEntityLookup()}, this lookup ignores exceptions. |
50 | 50 | */ |
51 | - public static function getEntityLookupWithoutCache( ?MediaWikiServices $services = null ): EntityLookup { |
|
52 | - return self::getService( $services, self::ENTITY_LOOKUP_WITHOUT_CACHE ); |
|
51 | + public static function getEntityLookupWithoutCache(?MediaWikiServices $services = null): EntityLookup { |
|
52 | + return self::getService($services, self::ENTITY_LOOKUP_WITHOUT_CACHE); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | } |
@@ -44,257 +44,257 @@ |
||
44 | 44 | public const LEXEME_LANGUAGE_CHECKER = 'WBQC_Lexeme_LanguageChecker'; |
45 | 45 | public const LABEL_IN_LANGUAGE_CHECKER = 'WBQC_LabelInLanguageChecker'; |
46 | 46 | |
47 | - private static function getService( ?MediaWikiServices $services, $name ) { |
|
47 | + private static function getService(?MediaWikiServices $services, $name) { |
|
48 | 48 | $services ??= MediaWikiServices::getInstance(); |
49 | - return $services->getService( $name ); |
|
49 | + return $services->getService($name); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | 53 | * @param MediaWikiServices|null $services |
54 | 54 | * @return ConstraintChecker |
55 | 55 | */ |
56 | - public static function getConflictsWithChecker( ?MediaWikiServices $services = null ) { |
|
57 | - return self::getService( $services, self::CONFLICTS_WITH_CHECKER ); |
|
56 | + public static function getConflictsWithChecker(?MediaWikiServices $services = null) { |
|
57 | + return self::getService($services, self::CONFLICTS_WITH_CHECKER); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
61 | 61 | * @param MediaWikiServices|null $services |
62 | 62 | * @return ConstraintChecker |
63 | 63 | */ |
64 | - public static function getItemChecker( ?MediaWikiServices $services = null ) { |
|
65 | - return self::getService( $services, self::ITEM_CHECKER ); |
|
64 | + public static function getItemChecker(?MediaWikiServices $services = null) { |
|
65 | + return self::getService($services, self::ITEM_CHECKER); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * @param MediaWikiServices|null $services |
70 | 70 | * @return ConstraintChecker |
71 | 71 | */ |
72 | - public static function getTargetRequiredClaimChecker( ?MediaWikiServices $services = null ) { |
|
73 | - return self::getService( $services, self::TARGET_REQUIRED_CLAIM_CHECKER ); |
|
72 | + public static function getTargetRequiredClaimChecker(?MediaWikiServices $services = null) { |
|
73 | + return self::getService($services, self::TARGET_REQUIRED_CLAIM_CHECKER); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
77 | 77 | * @param MediaWikiServices|null $services |
78 | 78 | * @return ConstraintChecker |
79 | 79 | */ |
80 | - public static function getSymmetricChecker( ?MediaWikiServices $services = null ) { |
|
81 | - return self::getService( $services, self::SYMMETRIC_CHECKER ); |
|
80 | + public static function getSymmetricChecker(?MediaWikiServices $services = null) { |
|
81 | + return self::getService($services, self::SYMMETRIC_CHECKER); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | 85 | * @param MediaWikiServices|null $services |
86 | 86 | * @return ConstraintChecker |
87 | 87 | */ |
88 | - public static function getInverseChecker( ?MediaWikiServices $services = null ) { |
|
89 | - return self::getService( $services, self::INVERSE_CHECKER ); |
|
88 | + public static function getInverseChecker(?MediaWikiServices $services = null) { |
|
89 | + return self::getService($services, self::INVERSE_CHECKER); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
93 | 93 | * @param MediaWikiServices|null $services |
94 | 94 | * @return ConstraintChecker |
95 | 95 | */ |
96 | - public static function getQualifierChecker( ?MediaWikiServices $services = null ) { |
|
97 | - return self::getService( $services, self::QUALIFIER_CHECKER ); |
|
96 | + public static function getQualifierChecker(?MediaWikiServices $services = null) { |
|
97 | + return self::getService($services, self::QUALIFIER_CHECKER); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * @param MediaWikiServices|null $services |
102 | 102 | * @return ConstraintChecker |
103 | 103 | */ |
104 | - public static function getQualifiersChecker( ?MediaWikiServices $services = null ) { |
|
105 | - return self::getService( $services, self::QUALIFIERS_CHECKER ); |
|
104 | + public static function getQualifiersChecker(?MediaWikiServices $services = null) { |
|
105 | + return self::getService($services, self::QUALIFIERS_CHECKER); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
109 | 109 | * @param MediaWikiServices|null $services |
110 | 110 | * @return ConstraintChecker |
111 | 111 | */ |
112 | - public static function getMandatoryQualifiersChecker( ?MediaWikiServices $services = null ) { |
|
113 | - return self::getService( $services, self::MANDATORY_QUALIFIERS_CHECKER ); |
|
112 | + public static function getMandatoryQualifiersChecker(?MediaWikiServices $services = null) { |
|
113 | + return self::getService($services, self::MANDATORY_QUALIFIERS_CHECKER); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
117 | 117 | * @param MediaWikiServices|null $services |
118 | 118 | * @return ConstraintChecker |
119 | 119 | */ |
120 | - public static function getRangeChecker( ?MediaWikiServices $services = null ) { |
|
121 | - return self::getService( $services, self::RANGE_CHECKER ); |
|
120 | + public static function getRangeChecker(?MediaWikiServices $services = null) { |
|
121 | + return self::getService($services, self::RANGE_CHECKER); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
125 | 125 | * @param MediaWikiServices|null $services |
126 | 126 | * @return ConstraintChecker |
127 | 127 | */ |
128 | - public static function getDiffWithinRangeChecker( ?MediaWikiServices $services = null ) { |
|
129 | - return self::getService( $services, self::DIFF_WITHIN_RANGE_CHECKER ); |
|
128 | + public static function getDiffWithinRangeChecker(?MediaWikiServices $services = null) { |
|
129 | + return self::getService($services, self::DIFF_WITHIN_RANGE_CHECKER); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
133 | 133 | * @param MediaWikiServices|null $services |
134 | 134 | * @return ConstraintChecker |
135 | 135 | */ |
136 | - public static function getTypeChecker( ?MediaWikiServices $services = null ) { |
|
137 | - return self::getService( $services, self::TYPE_CHECKER ); |
|
136 | + public static function getTypeChecker(?MediaWikiServices $services = null) { |
|
137 | + return self::getService($services, self::TYPE_CHECKER); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
141 | 141 | * @param MediaWikiServices|null $services |
142 | 142 | * @return ConstraintChecker |
143 | 143 | */ |
144 | - public static function getValueTypeChecker( ?MediaWikiServices $services = null ) { |
|
145 | - return self::getService( $services, self::VALUE_TYPE_CHECKER ); |
|
144 | + public static function getValueTypeChecker(?MediaWikiServices $services = null) { |
|
145 | + return self::getService($services, self::VALUE_TYPE_CHECKER); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
149 | 149 | * @param MediaWikiServices|null $services |
150 | 150 | * @return ConstraintChecker |
151 | 151 | */ |
152 | - public static function getSingleValueChecker( ?MediaWikiServices $services = null ) { |
|
153 | - return self::getService( $services, self::SINGLE_VALUE_CHECKER ); |
|
152 | + public static function getSingleValueChecker(?MediaWikiServices $services = null) { |
|
153 | + return self::getService($services, self::SINGLE_VALUE_CHECKER); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
157 | 157 | * @param MediaWikiServices|null $services |
158 | 158 | * @return ConstraintChecker |
159 | 159 | */ |
160 | - public static function getMultiValueChecker( ?MediaWikiServices $services = null ) { |
|
161 | - return self::getService( $services, self::MULTI_VALUE_CHECKER ); |
|
160 | + public static function getMultiValueChecker(?MediaWikiServices $services = null) { |
|
161 | + return self::getService($services, self::MULTI_VALUE_CHECKER); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
165 | 165 | * @param MediaWikiServices|null $services |
166 | 166 | * @return ConstraintChecker |
167 | 167 | */ |
168 | - public static function getUniqueValueChecker( ?MediaWikiServices $services = null ) { |
|
169 | - return self::getService( $services, self::UNIQUE_VALUE_CHECKER ); |
|
168 | + public static function getUniqueValueChecker(?MediaWikiServices $services = null) { |
|
169 | + return self::getService($services, self::UNIQUE_VALUE_CHECKER); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
173 | 173 | * @param MediaWikiServices|null $services |
174 | 174 | * @return ConstraintChecker |
175 | 175 | */ |
176 | - public static function getFormatChecker( ?MediaWikiServices $services = null ) { |
|
177 | - return self::getService( $services, self::FORMAT_CHECKER ); |
|
176 | + public static function getFormatChecker(?MediaWikiServices $services = null) { |
|
177 | + return self::getService($services, self::FORMAT_CHECKER); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
181 | 181 | * @param MediaWikiServices|null $services |
182 | 182 | * @return ConstraintChecker |
183 | 183 | */ |
184 | - public static function getCommonsLinkChecker( ?MediaWikiServices $services = null ) { |
|
185 | - return self::getService( $services, self::COMMONS_LINK_CHECKER ); |
|
184 | + public static function getCommonsLinkChecker(?MediaWikiServices $services = null) { |
|
185 | + return self::getService($services, self::COMMONS_LINK_CHECKER); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
189 | 189 | * @param MediaWikiServices|null $services |
190 | 190 | * @return ConstraintChecker |
191 | 191 | */ |
192 | - public static function getOneOfChecker( ?MediaWikiServices $services = null ) { |
|
193 | - return self::getService( $services, self::ONE_OF_CHECKER ); |
|
192 | + public static function getOneOfChecker(?MediaWikiServices $services = null) { |
|
193 | + return self::getService($services, self::ONE_OF_CHECKER); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
197 | 197 | * @param MediaWikiServices|null $services |
198 | 198 | * @return ConstraintChecker |
199 | 199 | */ |
200 | - public static function getValueOnlyChecker( ?MediaWikiServices $services = null ) { |
|
201 | - return self::getService( $services, self::VALUE_ONLY_CHECKER ); |
|
200 | + public static function getValueOnlyChecker(?MediaWikiServices $services = null) { |
|
201 | + return self::getService($services, self::VALUE_ONLY_CHECKER); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
205 | 205 | * @param MediaWikiServices|null $services |
206 | 206 | * @return ConstraintChecker |
207 | 207 | */ |
208 | - public static function getReferenceChecker( ?MediaWikiServices $services = null ) { |
|
209 | - return self::getService( $services, self::REFERENCE_CHECKER ); |
|
208 | + public static function getReferenceChecker(?MediaWikiServices $services = null) { |
|
209 | + return self::getService($services, self::REFERENCE_CHECKER); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
213 | 213 | * @param MediaWikiServices|null $services |
214 | 214 | * @return ConstraintChecker |
215 | 215 | */ |
216 | - public static function getNoBoundsChecker( ?MediaWikiServices $services = null ) { |
|
217 | - return self::getService( $services, self::NO_BOUNDS_CHECKER ); |
|
216 | + public static function getNoBoundsChecker(?MediaWikiServices $services = null) { |
|
217 | + return self::getService($services, self::NO_BOUNDS_CHECKER); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
221 | 221 | * @param MediaWikiServices|null $services |
222 | 222 | * @return ConstraintChecker |
223 | 223 | */ |
224 | - public static function getAllowedUnitsChecker( ?MediaWikiServices $services = null ) { |
|
225 | - return self::getService( $services, self::ALLOWED_UNITS_CHECKER ); |
|
224 | + public static function getAllowedUnitsChecker(?MediaWikiServices $services = null) { |
|
225 | + return self::getService($services, self::ALLOWED_UNITS_CHECKER); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
229 | 229 | * @param MediaWikiServices|null $services |
230 | 230 | * @return ConstraintChecker |
231 | 231 | */ |
232 | - public static function getSingleBestValueChecker( ?MediaWikiServices $services = null ) { |
|
233 | - return self::getService( $services, self::SINGLE_BEST_VALUE_CHECKER ); |
|
232 | + public static function getSingleBestValueChecker(?MediaWikiServices $services = null) { |
|
233 | + return self::getService($services, self::SINGLE_BEST_VALUE_CHECKER); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
237 | 237 | * @param MediaWikiServices|null $services |
238 | 238 | * @return ConstraintChecker |
239 | 239 | */ |
240 | - public static function getEntityTypeChecker( ?MediaWikiServices $services = null ) { |
|
241 | - return self::getService( $services, self::ENTITY_TYPE_CHECKER ); |
|
240 | + public static function getEntityTypeChecker(?MediaWikiServices $services = null) { |
|
241 | + return self::getService($services, self::ENTITY_TYPE_CHECKER); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
245 | 245 | * @param MediaWikiServices|null $services |
246 | 246 | * @return ConstraintChecker |
247 | 247 | */ |
248 | - public static function getNoneOfChecker( ?MediaWikiServices $services = null ) { |
|
249 | - return self::getService( $services, self::NONE_OF_CHECKER ); |
|
248 | + public static function getNoneOfChecker(?MediaWikiServices $services = null) { |
|
249 | + return self::getService($services, self::NONE_OF_CHECKER); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
253 | 253 | * @param MediaWikiServices|null $services |
254 | 254 | * @return ConstraintChecker |
255 | 255 | */ |
256 | - public static function getIntegerChecker( ?MediaWikiServices $services = null ) { |
|
257 | - return self::getService( $services, self::INTEGER_CHECKER ); |
|
256 | + public static function getIntegerChecker(?MediaWikiServices $services = null) { |
|
257 | + return self::getService($services, self::INTEGER_CHECKER); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
261 | 261 | * @param MediaWikiServices|null $services |
262 | 262 | * @return ConstraintChecker |
263 | 263 | */ |
264 | - public static function getCitationNeededChecker( ?MediaWikiServices $services = null ) { |
|
265 | - return self::getService( $services, self::CITATION_NEEDED_CHECKER ); |
|
264 | + public static function getCitationNeededChecker(?MediaWikiServices $services = null) { |
|
265 | + return self::getService($services, self::CITATION_NEEDED_CHECKER); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
269 | 269 | * @param MediaWikiServices|null $services |
270 | 270 | * @return ConstraintChecker |
271 | 271 | */ |
272 | - public static function getPropertyScopeChecker( ?MediaWikiServices $services = null ) { |
|
273 | - return self::getService( $services, self::PROPERTY_SCOPE_CHECKER ); |
|
272 | + public static function getPropertyScopeChecker(?MediaWikiServices $services = null) { |
|
273 | + return self::getService($services, self::PROPERTY_SCOPE_CHECKER); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
277 | 277 | * @param MediaWikiServices|null $services |
278 | 278 | * @return ConstraintChecker |
279 | 279 | */ |
280 | - public static function getContemporaryChecker( ?MediaWikiServices $services = null ) { |
|
281 | - return self::getService( $services, self::CONTEMPORARY_CHECKER ); |
|
280 | + public static function getContemporaryChecker(?MediaWikiServices $services = null) { |
|
281 | + return self::getService($services, self::CONTEMPORARY_CHECKER); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
285 | 285 | * @param MediaWikiServices|null $services |
286 | 286 | * @return LanguageChecker |
287 | 287 | */ |
288 | - public static function getLexemeLanguageChecker( ?MediaWikiServices $services = null ) { |
|
289 | - return self::getService( $services, self::LEXEME_LANGUAGE_CHECKER ); |
|
288 | + public static function getLexemeLanguageChecker(?MediaWikiServices $services = null) { |
|
289 | + return self::getService($services, self::LEXEME_LANGUAGE_CHECKER); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
293 | 293 | * @param MediaWikiServices|null $services |
294 | 294 | * @return LabelInLanguageChecker |
295 | 295 | */ |
296 | - public static function getLabelInLanguageChecker( ?MediaWikiServices $services = null ) { |
|
297 | - return self::getService( $services, self::LABEL_IN_LANGUAGE_CHECKER ); |
|
296 | + public static function getLabelInLanguageChecker(?MediaWikiServices $services = null) { |
|
297 | + return self::getService($services, self::LABEL_IN_LANGUAGE_CHECKER); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck; |
6 | 6 | |
@@ -123,10 +123,10 @@ discard block |
||
123 | 123 | ?callable $defaultResultsPerEntity = null |
124 | 124 | ): array { |
125 | 125 | $checkResults = []; |
126 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
126 | + $entity = $this->entityLookup->getEntity($entityId); |
|
127 | 127 | |
128 | - if ( $entity instanceof StatementListProvidingEntity ) { |
|
129 | - $startTime = microtime( true ); |
|
128 | + if ($entity instanceof StatementListProvidingEntity) { |
|
129 | + $startTime = microtime(true); |
|
130 | 130 | |
131 | 131 | $checkResults = $this->checkEveryStatement( |
132 | 132 | $entity, |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | $defaultResultsPerContext |
135 | 135 | ); |
136 | 136 | |
137 | - $endTime = microtime( true ); |
|
137 | + $endTime = microtime(true); |
|
138 | 138 | |
139 | - if ( $constraintIds === null ) { // only log full constraint checks |
|
139 | + if ($constraintIds === null) { // only log full constraint checks |
|
140 | 140 | $this->loggingHelper->logConstraintCheckOnEntity( |
141 | 141 | $entityId, |
142 | 142 | $checkResults, |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
149 | - if ( $defaultResultsPerEntity !== null ) { |
|
150 | - $checkResults = array_merge( $defaultResultsPerEntity( $entityId ), $checkResults ); |
|
149 | + if ($defaultResultsPerEntity !== null) { |
|
150 | + $checkResults = array_merge($defaultResultsPerEntity($entityId), $checkResults); |
|
151 | 151 | } |
152 | 152 | |
153 | - return $this->sortResult( $checkResults ); |
|
153 | + return $this->sortResult($checkResults); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -172,19 +172,19 @@ discard block |
||
172 | 172 | ?callable $defaultResults = null |
173 | 173 | ): array { |
174 | 174 | |
175 | - $parsedGuid = $this->statementGuidParser->parse( $guid ); |
|
175 | + $parsedGuid = $this->statementGuidParser->parse($guid); |
|
176 | 176 | $entityId = $parsedGuid->getEntityId(); |
177 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
178 | - if ( $entity instanceof StatementListProvidingEntity ) { |
|
179 | - $statement = $entity->getStatements()->getFirstStatementWithGuid( $guid ); |
|
180 | - if ( $statement ) { |
|
177 | + $entity = $this->entityLookup->getEntity($entityId); |
|
178 | + if ($entity instanceof StatementListProvidingEntity) { |
|
179 | + $statement = $entity->getStatements()->getFirstStatementWithGuid($guid); |
|
180 | + if ($statement) { |
|
181 | 181 | $result = $this->checkStatement( |
182 | 182 | $entity, |
183 | 183 | $statement, |
184 | 184 | $constraintIds, |
185 | 185 | $defaultResults |
186 | 186 | ); |
187 | - $output = $this->sortResult( $result ); |
|
187 | + $output = $this->sortResult($result); |
|
188 | 188 | return $output; |
189 | 189 | } |
190 | 190 | } |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | return []; |
193 | 193 | } |
194 | 194 | |
195 | - private function getValidContextTypes( Constraint $constraint ): array { |
|
196 | - if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
195 | + private function getValidContextTypes(Constraint $constraint): array { |
|
196 | + if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
197 | 197 | return [ |
198 | 198 | Context::TYPE_STATEMENT, |
199 | 199 | Context::TYPE_QUALIFIER, |
@@ -201,21 +201,21 @@ discard block |
||
201 | 201 | ]; |
202 | 202 | } |
203 | 203 | |
204 | - return array_keys( array_filter( |
|
204 | + return array_keys(array_filter( |
|
205 | 205 | $this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedContextTypes(), |
206 | - static fn ( $status ) => $status !== CheckResult::STATUS_NOT_IN_SCOPE |
|
207 | - ) ); |
|
206 | + static fn ($status) => $status !== CheckResult::STATUS_NOT_IN_SCOPE |
|
207 | + )); |
|
208 | 208 | } |
209 | 209 | |
210 | - private function getValidEntityTypes( Constraint $constraint ): array { |
|
211 | - if ( !array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
212 | - return array_keys( ConstraintChecker::ALL_ENTITY_TYPES_SUPPORTED ); |
|
210 | + private function getValidEntityTypes(Constraint $constraint): array { |
|
211 | + if (!array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
212 | + return array_keys(ConstraintChecker::ALL_ENTITY_TYPES_SUPPORTED); |
|
213 | 213 | } |
214 | 214 | |
215 | - return array_keys( array_filter( |
|
215 | + return array_keys(array_filter( |
|
216 | 216 | $this->checkerMap[$constraint->getConstraintTypeItemId()]->getSupportedEntityTypes(), |
217 | - static fn ( $status ) => $status !== CheckResult::STATUS_NOT_IN_SCOPE |
|
218 | - ) ); |
|
217 | + static fn ($status) => $status !== CheckResult::STATUS_NOT_IN_SCOPE |
|
218 | + )); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -226,38 +226,38 @@ discard block |
||
226 | 226 | * |
227 | 227 | * @return ConstraintParameterException[] |
228 | 228 | */ |
229 | - private function checkCommonConstraintParameters( Constraint $constraint ): array { |
|
229 | + private function checkCommonConstraintParameters(Constraint $constraint): array { |
|
230 | 230 | $constraintParameters = $constraint->getConstraintParameters(); |
231 | 231 | try { |
232 | - $this->constraintParameterParser->checkError( $constraintParameters ); |
|
233 | - } catch ( ConstraintParameterException $e ) { |
|
234 | - return [ $e ]; |
|
232 | + $this->constraintParameterParser->checkError($constraintParameters); |
|
233 | + } catch (ConstraintParameterException $e) { |
|
234 | + return [$e]; |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | $problems = []; |
238 | 238 | try { |
239 | - $this->constraintParameterParser->parseExceptionParameter( $constraintParameters ); |
|
240 | - } catch ( ConstraintParameterException $e ) { |
|
239 | + $this->constraintParameterParser->parseExceptionParameter($constraintParameters); |
|
240 | + } catch (ConstraintParameterException $e) { |
|
241 | 241 | $problems[] = $e; |
242 | 242 | } |
243 | 243 | try { |
244 | - $this->constraintParameterParser->parseConstraintClarificationParameter( $constraintParameters ); |
|
245 | - } catch ( ConstraintParameterException $e ) { |
|
244 | + $this->constraintParameterParser->parseConstraintClarificationParameter($constraintParameters); |
|
245 | + } catch (ConstraintParameterException $e) { |
|
246 | 246 | $problems[] = $e; |
247 | 247 | } |
248 | 248 | try { |
249 | - $this->constraintParameterParser->parseConstraintStatusParameter( $constraintParameters ); |
|
250 | - } catch ( ConstraintParameterException $e ) { |
|
249 | + $this->constraintParameterParser->parseConstraintStatusParameter($constraintParameters); |
|
250 | + } catch (ConstraintParameterException $e) { |
|
251 | 251 | $problems[] = $e; |
252 | 252 | } |
253 | 253 | try { |
254 | 254 | $this->constraintParameterParser->parseConstraintScopeParameters( |
255 | 255 | $constraintParameters, |
256 | 256 | $constraint->getConstraintTypeItemId(), |
257 | - $this->getValidContextTypes( $constraint ), |
|
258 | - $this->getValidEntityTypes( $constraint ) |
|
257 | + $this->getValidContextTypes($constraint), |
|
258 | + $this->getValidEntityTypes($constraint) |
|
259 | 259 | ); |
260 | - } catch ( ConstraintParameterException $e ) { |
|
260 | + } catch (ConstraintParameterException $e) { |
|
261 | 261 | $problems[] = $e; |
262 | 262 | } |
263 | 263 | return $problems; |
@@ -270,16 +270,16 @@ discard block |
||
270 | 270 | * @return ConstraintParameterException[][] first level indexed by constraint ID, |
271 | 271 | * second level like checkConstraintParametersOnConstraintId (but without possibility of null) |
272 | 272 | */ |
273 | - public function checkConstraintParametersOnPropertyId( NumericPropertyId $propertyId ): array { |
|
274 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
273 | + public function checkConstraintParametersOnPropertyId(NumericPropertyId $propertyId): array { |
|
274 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
275 | 275 | $result = []; |
276 | 276 | |
277 | - foreach ( $constraints as $constraint ) { |
|
278 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
277 | + foreach ($constraints as $constraint) { |
|
278 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
279 | 279 | |
280 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
280 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
281 | 281 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
282 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
282 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | $result[$constraint->getConstraintId()] = $problems; |
@@ -296,18 +296,18 @@ discard block |
||
296 | 296 | * @return ConstraintParameterException[]|null list of constraint parameter exceptions |
297 | 297 | * (empty means all parameters okay), or null if constraint is not found |
298 | 298 | */ |
299 | - public function checkConstraintParametersOnConstraintId( string $constraintId ): ?array { |
|
300 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
299 | + public function checkConstraintParametersOnConstraintId(string $constraintId): ?array { |
|
300 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
301 | 301 | '@phan-var NumericPropertyId $propertyId'; |
302 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
302 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
303 | 303 | |
304 | - foreach ( $constraints as $constraint ) { |
|
305 | - if ( $constraint->getConstraintId() === $constraintId ) { |
|
306 | - $problems = $this->checkCommonConstraintParameters( $constraint ); |
|
304 | + foreach ($constraints as $constraint) { |
|
305 | + if ($constraint->getConstraintId() === $constraintId) { |
|
306 | + $problems = $this->checkCommonConstraintParameters($constraint); |
|
307 | 307 | |
308 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
308 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
309 | 309 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
310 | - $problems = array_merge( $problems, $checker->checkConstraintParameters( $constraint ) ); |
|
310 | + $problems = array_merge($problems, $checker->checkConstraintParameters($constraint)); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | return $problems; |
@@ -332,14 +332,14 @@ discard block |
||
332 | 332 | $result = []; |
333 | 333 | |
334 | 334 | /** @var Statement $statement */ |
335 | - foreach ( $entity->getStatements() as $statement ) { |
|
336 | - $result = array_merge( $result, |
|
335 | + foreach ($entity->getStatements() as $statement) { |
|
336 | + $result = array_merge($result, |
|
337 | 337 | $this->checkStatement( |
338 | 338 | $entity, |
339 | 339 | $statement, |
340 | 340 | $constraintIds, |
341 | 341 | $defaultResultsPerContext |
342 | - ) ); |
|
342 | + )); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | return $result; |
@@ -361,32 +361,32 @@ discard block |
||
361 | 361 | ): array { |
362 | 362 | $result = []; |
363 | 363 | |
364 | - $result = array_merge( $result, |
|
364 | + $result = array_merge($result, |
|
365 | 365 | $this->checkConstraintsForMainSnak( |
366 | 366 | $entity, |
367 | 367 | $statement, |
368 | 368 | $constraintIds, |
369 | 369 | $defaultResultsPerContext |
370 | - ) ); |
|
370 | + )); |
|
371 | 371 | |
372 | - if ( $this->checkQualifiers ) { |
|
373 | - $result = array_merge( $result, |
|
372 | + if ($this->checkQualifiers) { |
|
373 | + $result = array_merge($result, |
|
374 | 374 | $this->checkConstraintsForQualifiers( |
375 | 375 | $entity, |
376 | 376 | $statement, |
377 | 377 | $constraintIds, |
378 | 378 | $defaultResultsPerContext |
379 | - ) ); |
|
379 | + )); |
|
380 | 380 | } |
381 | 381 | |
382 | - if ( $this->checkReferences ) { |
|
383 | - $result = array_merge( $result, |
|
382 | + if ($this->checkReferences) { |
|
383 | + $result = array_merge($result, |
|
384 | 384 | $this->checkConstraintsForReferences( |
385 | 385 | $entity, |
386 | 386 | $statement, |
387 | 387 | $constraintIds, |
388 | 388 | $defaultResultsPerContext |
389 | - ) ); |
|
389 | + )); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | return $result; |
@@ -401,17 +401,17 @@ discard block |
||
401 | 401 | * @param string[]|null $constraintIds |
402 | 402 | * @return Constraint[] |
403 | 403 | */ |
404 | - private function getConstraintsToUse( PropertyId $propertyId, ?array $constraintIds ): array { |
|
405 | - if ( !( $propertyId instanceof NumericPropertyId ) ) { |
|
404 | + private function getConstraintsToUse(PropertyId $propertyId, ?array $constraintIds): array { |
|
405 | + if (!($propertyId instanceof NumericPropertyId)) { |
|
406 | 406 | throw new InvalidArgumentException( |
407 | - 'Non-numeric property ID not supported:' . $propertyId->getSerialization() |
|
407 | + 'Non-numeric property ID not supported:'.$propertyId->getSerialization() |
|
408 | 408 | ); |
409 | 409 | } |
410 | - $constraints = $this->constraintLookup->queryConstraintsForProperty( $propertyId ); |
|
411 | - if ( $constraintIds !== null ) { |
|
410 | + $constraints = $this->constraintLookup->queryConstraintsForProperty($propertyId); |
|
411 | + if ($constraintIds !== null) { |
|
412 | 412 | $constraintsToUse = []; |
413 | - foreach ( $constraints as $constraint ) { |
|
414 | - if ( in_array( $constraint->getConstraintId(), $constraintIds ) ) { |
|
413 | + foreach ($constraints as $constraint) { |
|
414 | + if (in_array($constraint->getConstraintId(), $constraintIds)) { |
|
415 | 415 | $constraintsToUse[] = $constraint; |
416 | 416 | } |
417 | 417 | } |
@@ -435,18 +435,18 @@ discard block |
||
435 | 435 | ?array $constraintIds, |
436 | 436 | ?callable $defaultResults |
437 | 437 | ): array { |
438 | - $context = new MainSnakContext( $entity, $statement ); |
|
438 | + $context = new MainSnakContext($entity, $statement); |
|
439 | 439 | $constraints = $this->getConstraintsToUse( |
440 | 440 | $statement->getPropertyId(), |
441 | 441 | $constraintIds |
442 | 442 | ); |
443 | - $result = $defaultResults !== null ? $defaultResults( $context ) : []; |
|
443 | + $result = $defaultResults !== null ? $defaultResults($context) : []; |
|
444 | 444 | |
445 | - foreach ( $constraints as $constraint ) { |
|
445 | + foreach ($constraints as $constraint) { |
|
446 | 446 | $parameters = $constraint->getConstraintParameters(); |
447 | 447 | try { |
448 | - $exceptions = $this->constraintParameterParser->parseExceptionParameter( $parameters ); |
|
449 | - } catch ( ConstraintParameterException $e ) { |
|
448 | + $exceptions = $this->constraintParameterParser->parseExceptionParameter($parameters); |
|
449 | + } catch (ConstraintParameterException $e) { |
|
450 | 450 | $result[] = new CheckResult( |
451 | 451 | $context, |
452 | 452 | $constraint, |
@@ -456,13 +456,13 @@ discard block |
||
456 | 456 | continue; |
457 | 457 | } |
458 | 458 | |
459 | - if ( in_array( $entity->getId(), $exceptions ) ) { |
|
460 | - $message = new ViolationMessage( 'wbqc-violation-message-exception' ); |
|
461 | - $result[] = new CheckResult( $context, $constraint, CheckResult::STATUS_EXCEPTION, $message ); |
|
459 | + if (in_array($entity->getId(), $exceptions)) { |
|
460 | + $message = new ViolationMessage('wbqc-violation-message-exception'); |
|
461 | + $result[] = new CheckResult($context, $constraint, CheckResult::STATUS_EXCEPTION, $message); |
|
462 | 462 | continue; |
463 | 463 | } |
464 | 464 | |
465 | - $result[] = $this->getCheckResultFor( $context, $constraint ); |
|
465 | + $result[] = $this->getCheckResultFor($context, $constraint); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | return $result; |
@@ -484,24 +484,24 @@ discard block |
||
484 | 484 | ): array { |
485 | 485 | $result = []; |
486 | 486 | |
487 | - if ( in_array( |
|
487 | + if (in_array( |
|
488 | 488 | $statement->getPropertyId()->getSerialization(), |
489 | 489 | $this->propertiesWithViolatingQualifiers |
490 | - ) ) { |
|
490 | + )) { |
|
491 | 491 | return $result; |
492 | 492 | } |
493 | 493 | |
494 | - foreach ( $statement->getQualifiers() as $qualifier ) { |
|
495 | - $qualifierContext = new QualifierContext( $entity, $statement, $qualifier ); |
|
496 | - if ( $defaultResultsPerContext !== null ) { |
|
497 | - $result = array_merge( $result, $defaultResultsPerContext( $qualifierContext ) ); |
|
494 | + foreach ($statement->getQualifiers() as $qualifier) { |
|
495 | + $qualifierContext = new QualifierContext($entity, $statement, $qualifier); |
|
496 | + if ($defaultResultsPerContext !== null) { |
|
497 | + $result = array_merge($result, $defaultResultsPerContext($qualifierContext)); |
|
498 | 498 | } |
499 | 499 | $qualifierConstraints = $this->getConstraintsToUse( |
500 | 500 | $qualifierContext->getSnak()->getPropertyId(), |
501 | 501 | $constraintIds |
502 | 502 | ); |
503 | - foreach ( $qualifierConstraints as $qualifierConstraint ) { |
|
504 | - $result[] = $this->getCheckResultFor( $qualifierContext, $qualifierConstraint ); |
|
503 | + foreach ($qualifierConstraints as $qualifierConstraint) { |
|
504 | + $result[] = $this->getCheckResultFor($qualifierContext, $qualifierConstraint); |
|
505 | 505 | } |
506 | 506 | } |
507 | 507 | |
@@ -525,19 +525,19 @@ discard block |
||
525 | 525 | $result = []; |
526 | 526 | |
527 | 527 | /** @var Reference $reference */ |
528 | - foreach ( $statement->getReferences() as $reference ) { |
|
529 | - foreach ( $reference->getSnaks() as $snak ) { |
|
528 | + foreach ($statement->getReferences() as $reference) { |
|
529 | + foreach ($reference->getSnaks() as $snak) { |
|
530 | 530 | $referenceContext = new ReferenceContext( |
531 | 531 | $entity, $statement, $reference, $snak |
532 | 532 | ); |
533 | - if ( $defaultResultsPerContext !== null ) { |
|
534 | - $result = array_merge( $result, $defaultResultsPerContext( $referenceContext ) ); |
|
533 | + if ($defaultResultsPerContext !== null) { |
|
534 | + $result = array_merge($result, $defaultResultsPerContext($referenceContext)); |
|
535 | 535 | } |
536 | 536 | $referenceConstraints = $this->getConstraintsToUse( |
537 | 537 | $referenceContext->getSnak()->getPropertyId(), |
538 | 538 | $constraintIds |
539 | 539 | ); |
540 | - foreach ( $referenceConstraints as $referenceConstraint ) { |
|
540 | + foreach ($referenceConstraints as $referenceConstraint) { |
|
541 | 541 | $result[] = $this->getCheckResultFor( |
542 | 542 | $referenceContext, |
543 | 543 | $referenceConstraint |
@@ -549,50 +549,50 @@ discard block |
||
549 | 549 | return $result; |
550 | 550 | } |
551 | 551 | |
552 | - private function getCheckResultFor( Context $context, Constraint $constraint ): CheckResult { |
|
553 | - if ( array_key_exists( $constraint->getConstraintTypeItemId(), $this->checkerMap ) ) { |
|
552 | + private function getCheckResultFor(Context $context, Constraint $constraint): CheckResult { |
|
553 | + if (array_key_exists($constraint->getConstraintTypeItemId(), $this->checkerMap)) { |
|
554 | 554 | $checker = $this->checkerMap[$constraint->getConstraintTypeItemId()]; |
555 | - $result = $this->handleScope( $checker, $context, $constraint ); |
|
555 | + $result = $this->handleScope($checker, $context, $constraint); |
|
556 | 556 | |
557 | - if ( $result !== null ) { |
|
558 | - $this->addMetadata( $context, $result ); |
|
557 | + if ($result !== null) { |
|
558 | + $this->addMetadata($context, $result); |
|
559 | 559 | return $result; |
560 | 560 | } |
561 | 561 | |
562 | - $startTime = microtime( true ); |
|
562 | + $startTime = microtime(true); |
|
563 | 563 | try { |
564 | - $result = $checker->checkConstraint( $context, $constraint ); |
|
565 | - } catch ( ConstraintParameterException $e ) { |
|
564 | + $result = $checker->checkConstraint($context, $constraint); |
|
565 | + } catch (ConstraintParameterException $e) { |
|
566 | 566 | $result = new CheckResult( |
567 | 567 | $context, |
568 | 568 | $constraint, |
569 | 569 | CheckResult::STATUS_BAD_PARAMETERS, |
570 | 570 | $e->getViolationMessage() |
571 | 571 | ); |
572 | - } catch ( SparqlHelperException $e ) { |
|
573 | - $message = new ViolationMessage( 'wbqc-violation-message-sparql-error' ); |
|
574 | - $result = new CheckResult( $context, $constraint, CheckResult::STATUS_TODO, $message ); |
|
572 | + } catch (SparqlHelperException $e) { |
|
573 | + $message = new ViolationMessage('wbqc-violation-message-sparql-error'); |
|
574 | + $result = new CheckResult($context, $constraint, CheckResult::STATUS_TODO, $message); |
|
575 | 575 | } |
576 | - $endTime = microtime( true ); |
|
576 | + $endTime = microtime(true); |
|
577 | 577 | |
578 | - $this->addMetadata( $context, $result ); |
|
578 | + $this->addMetadata($context, $result); |
|
579 | 579 | |
580 | - $this->addConstraintClarification( $result ); |
|
580 | + $this->addConstraintClarification($result); |
|
581 | 581 | |
582 | - $this->downgradeResultStatus( $result ); |
|
582 | + $this->downgradeResultStatus($result); |
|
583 | 583 | |
584 | 584 | $this->loggingHelper->logConstraintCheck( |
585 | 585 | $context, |
586 | 586 | $constraint, |
587 | 587 | $result, |
588 | - get_class( $checker ), |
|
588 | + get_class($checker), |
|
589 | 589 | $endTime - $startTime, |
590 | 590 | __METHOD__ |
591 | 591 | ); |
592 | 592 | |
593 | 593 | return $result; |
594 | 594 | } else { |
595 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_TODO, null ); |
|
595 | + return new CheckResult($context, $constraint, CheckResult::STATUS_TODO, null); |
|
596 | 596 | } |
597 | 597 | } |
598 | 598 | |
@@ -601,87 +601,87 @@ discard block |
||
601 | 601 | Context $context, |
602 | 602 | Constraint $constraint |
603 | 603 | ): ?CheckResult { |
604 | - $validContextTypes = $this->getValidContextTypes( $constraint ); |
|
605 | - $validEntityTypes = $this->getValidEntityTypes( $constraint ); |
|
604 | + $validContextTypes = $this->getValidContextTypes($constraint); |
|
605 | + $validEntityTypes = $this->getValidEntityTypes($constraint); |
|
606 | 606 | try { |
607 | - [ $checkedContextTypes, $checkedEntityTypes ] = $this->constraintParameterParser->parseConstraintScopeParameters( |
|
607 | + [$checkedContextTypes, $checkedEntityTypes] = $this->constraintParameterParser->parseConstraintScopeParameters( |
|
608 | 608 | $constraint->getConstraintParameters(), |
609 | 609 | $constraint->getConstraintTypeItemId(), |
610 | 610 | $validContextTypes, |
611 | 611 | $validEntityTypes |
612 | 612 | ); |
613 | - } catch ( ConstraintParameterException $e ) { |
|
614 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage() ); |
|
613 | + } catch (ConstraintParameterException $e) { |
|
614 | + return new CheckResult($context, $constraint, CheckResult::STATUS_BAD_PARAMETERS, $e->getViolationMessage()); |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | $checkedContextTypes ??= $checker->getDefaultContextTypes(); |
618 | 618 | $contextType = $context->getType(); |
619 | - if ( !in_array( $contextType, $checkedContextTypes ) ) { |
|
620 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE, null ); |
|
619 | + if (!in_array($contextType, $checkedContextTypes)) { |
|
620 | + return new CheckResult($context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE, null); |
|
621 | 621 | } |
622 | - if ( $checker->getSupportedContextTypes()[$contextType] === CheckResult::STATUS_TODO ) { |
|
623 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_TODO, null ); |
|
622 | + if ($checker->getSupportedContextTypes()[$contextType] === CheckResult::STATUS_TODO) { |
|
623 | + return new CheckResult($context, $constraint, CheckResult::STATUS_TODO, null); |
|
624 | 624 | } |
625 | 625 | |
626 | 626 | $checkedEntityTypes ??= $validEntityTypes; |
627 | 627 | $entityType = $context->getEntity()->getType(); |
628 | - if ( !in_array( $entityType, $checkedEntityTypes ) ) { |
|
629 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE, null ); |
|
628 | + if (!in_array($entityType, $checkedEntityTypes)) { |
|
629 | + return new CheckResult($context, $constraint, CheckResult::STATUS_NOT_IN_SCOPE, null); |
|
630 | 630 | } |
631 | - if ( $checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO ) { |
|
632 | - return new CheckResult( $context, $constraint, CheckResult::STATUS_TODO, null ); |
|
631 | + if ($checker->getSupportedEntityTypes()[$entityType] === CheckResult::STATUS_TODO) { |
|
632 | + return new CheckResult($context, $constraint, CheckResult::STATUS_TODO, null); |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | return null; |
636 | 636 | } |
637 | 637 | |
638 | - private function addMetadata( Context $context, CheckResult $result ): void { |
|
639 | - $result->withMetadata( Metadata::merge( [ |
|
638 | + private function addMetadata(Context $context, CheckResult $result): void { |
|
639 | + $result->withMetadata(Metadata::merge([ |
|
640 | 640 | $result->getMetadata(), |
641 | - Metadata::ofDependencyMetadata( DependencyMetadata::merge( [ |
|
642 | - DependencyMetadata::ofEntityId( $context->getEntity()->getId() ), |
|
643 | - DependencyMetadata::ofEntityId( $result->getConstraint()->getPropertyId() ), |
|
644 | - ] ) ), |
|
645 | - ] ) ); |
|
641 | + Metadata::ofDependencyMetadata(DependencyMetadata::merge([ |
|
642 | + DependencyMetadata::ofEntityId($context->getEntity()->getId()), |
|
643 | + DependencyMetadata::ofEntityId($result->getConstraint()->getPropertyId()), |
|
644 | + ])), |
|
645 | + ])); |
|
646 | 646 | } |
647 | 647 | |
648 | - private function addConstraintClarification( CheckResult $result ): void { |
|
648 | + private function addConstraintClarification(CheckResult $result): void { |
|
649 | 649 | $constraint = $result->getConstraint(); |
650 | 650 | try { |
651 | 651 | $constraintClarification = $this->constraintParameterParser |
652 | - ->parseConstraintClarificationParameter( $constraint->getConstraintParameters() ); |
|
653 | - $result->setConstraintClarification( $constraintClarification ); |
|
654 | - } catch ( ConstraintParameterException $e ) { |
|
655 | - $result->setStatus( CheckResult::STATUS_BAD_PARAMETERS ); |
|
656 | - $result->setMessage( $e->getViolationMessage() ); |
|
652 | + ->parseConstraintClarificationParameter($constraint->getConstraintParameters()); |
|
653 | + $result->setConstraintClarification($constraintClarification); |
|
654 | + } catch (ConstraintParameterException $e) { |
|
655 | + $result->setStatus(CheckResult::STATUS_BAD_PARAMETERS); |
|
656 | + $result->setMessage($e->getViolationMessage()); |
|
657 | 657 | } |
658 | 658 | } |
659 | 659 | |
660 | - private function downgradeResultStatus( CheckResult $result ): void { |
|
660 | + private function downgradeResultStatus(CheckResult $result): void { |
|
661 | 661 | $constraint = $result->getConstraint(); |
662 | 662 | try { |
663 | 663 | $constraintStatus = $this->constraintParameterParser |
664 | - ->parseConstraintStatusParameter( $constraint->getConstraintParameters() ); |
|
665 | - } catch ( ConstraintParameterException $e ) { |
|
666 | - $result->setStatus( CheckResult::STATUS_BAD_PARAMETERS ); |
|
667 | - $result->setMessage( $e->getViolationMessage() ); |
|
664 | + ->parseConstraintStatusParameter($constraint->getConstraintParameters()); |
|
665 | + } catch (ConstraintParameterException $e) { |
|
666 | + $result->setStatus(CheckResult::STATUS_BAD_PARAMETERS); |
|
667 | + $result->setMessage($e->getViolationMessage()); |
|
668 | 668 | return; |
669 | 669 | } |
670 | - if ( $constraintStatus === null ) { |
|
670 | + if ($constraintStatus === null) { |
|
671 | 671 | // downgrade violation to warning |
672 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
673 | - $result->setStatus( CheckResult::STATUS_WARNING ); |
|
672 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
673 | + $result->setStatus(CheckResult::STATUS_WARNING); |
|
674 | 674 | } |
675 | - } elseif ( $constraintStatus === 'suggestion' ) { |
|
675 | + } elseif ($constraintStatus === 'suggestion') { |
|
676 | 676 | // downgrade violation to suggestion |
677 | - if ( $result->getStatus() === CheckResult::STATUS_VIOLATION ) { |
|
678 | - $result->setStatus( CheckResult::STATUS_SUGGESTION ); |
|
677 | + if ($result->getStatus() === CheckResult::STATUS_VIOLATION) { |
|
678 | + $result->setStatus(CheckResult::STATUS_SUGGESTION); |
|
679 | 679 | } |
680 | 680 | } else { |
681 | - if ( $constraintStatus !== 'mandatory' ) { |
|
681 | + if ($constraintStatus !== 'mandatory') { |
|
682 | 682 | // @codeCoverageIgnoreStart |
683 | 683 | throw new LogicException( |
684 | - "Unknown constraint status '$constraintStatus', " . |
|
684 | + "Unknown constraint status '$constraintStatus', ". |
|
685 | 685 | "only known statuses are 'mandatory' and 'suggestion'" |
686 | 686 | ); |
687 | 687 | // @codeCoverageIgnoreEnd |
@@ -694,12 +694,12 @@ discard block |
||
694 | 694 | * |
695 | 695 | * @return CheckResult[] |
696 | 696 | */ |
697 | - private function sortResult( array $result ): array { |
|
698 | - if ( count( $result ) < 2 ) { |
|
697 | + private function sortResult(array $result): array { |
|
698 | + if (count($result) < 2) { |
|
699 | 699 | return $result; |
700 | 700 | } |
701 | 701 | |
702 | - $sortFunction = static function ( CheckResult $a, CheckResult $b ) { |
|
702 | + $sortFunction = static function(CheckResult $a, CheckResult $b) { |
|
703 | 703 | $orderNum = 0; |
704 | 704 | $order = [ |
705 | 705 | CheckResult::STATUS_BAD_PARAMETERS => $orderNum++, |
@@ -716,55 +716,55 @@ discard block |
||
716 | 716 | $statusA = $a->getStatus(); |
717 | 717 | $statusB = $b->getStatus(); |
718 | 718 | |
719 | - $orderA = array_key_exists( $statusA, $order ) ? $order[ $statusA ] : $order[ 'other' ]; |
|
720 | - $orderB = array_key_exists( $statusB, $order ) ? $order[ $statusB ] : $order[ 'other' ]; |
|
719 | + $orderA = array_key_exists($statusA, $order) ? $order[$statusA] : $order['other']; |
|
720 | + $orderB = array_key_exists($statusB, $order) ? $order[$statusB] : $order['other']; |
|
721 | 721 | |
722 | - if ( $orderA === $orderB ) { |
|
722 | + if ($orderA === $orderB) { |
|
723 | 723 | $cursorA = $a->getContextCursor(); |
724 | 724 | $cursorB = $b->getContextCursor(); |
725 | 725 | |
726 | - if ( $cursorA instanceof EntityContextCursor ) { |
|
726 | + if ($cursorA instanceof EntityContextCursor) { |
|
727 | 727 | return $cursorB instanceof EntityContextCursor ? 0 : -1; |
728 | 728 | } |
729 | - if ( $cursorB instanceof EntityContextCursor ) { |
|
729 | + if ($cursorB instanceof EntityContextCursor) { |
|
730 | 730 | return $cursorA instanceof EntityContextCursor ? 0 : 1; |
731 | 731 | } |
732 | 732 | |
733 | 733 | $pidA = $cursorA->getSnakPropertyId(); |
734 | 734 | $pidB = $cursorB->getSnakPropertyId(); |
735 | 735 | |
736 | - if ( $pidA === $pidB ) { |
|
736 | + if ($pidA === $pidB) { |
|
737 | 737 | $hashA = $cursorA->getSnakHash(); |
738 | 738 | $hashB = $cursorB->getSnakHash(); |
739 | 739 | |
740 | - if ( $hashA === $hashB ) { |
|
741 | - if ( $a instanceof NullResult ) { |
|
740 | + if ($hashA === $hashB) { |
|
741 | + if ($a instanceof NullResult) { |
|
742 | 742 | return $b instanceof NullResult ? 0 : -1; |
743 | 743 | } |
744 | - if ( $b instanceof NullResult ) { |
|
744 | + if ($b instanceof NullResult) { |
|
745 | 745 | return $a instanceof NullResult ? 0 : 1; |
746 | 746 | } |
747 | 747 | |
748 | 748 | $typeA = $a->getConstraint()->getConstraintTypeItemId(); |
749 | 749 | $typeB = $b->getConstraint()->getConstraintTypeItemId(); |
750 | 750 | |
751 | - if ( $typeA == $typeB ) { |
|
751 | + if ($typeA == $typeB) { |
|
752 | 752 | return 0; |
753 | 753 | } else { |
754 | - return ( $typeA > $typeB ) ? 1 : -1; |
|
754 | + return ($typeA > $typeB) ? 1 : -1; |
|
755 | 755 | } |
756 | 756 | } else { |
757 | - return ( $hashA > $hashB ) ? 1 : -1; |
|
757 | + return ($hashA > $hashB) ? 1 : -1; |
|
758 | 758 | } |
759 | 759 | } else { |
760 | - return ( $pidA > $pidB ) ? 1 : -1; |
|
760 | + return ($pidA > $pidB) ? 1 : -1; |
|
761 | 761 | } |
762 | 762 | } else { |
763 | - return ( $orderA > $orderB ) ? 1 : -1; |
|
763 | + return ($orderA > $orderB) ? 1 : -1; |
|
764 | 764 | } |
765 | 765 | }; |
766 | 766 | |
767 | - uasort( $result, $sortFunction ); |
|
767 | + uasort($result, $sortFunction); |
|
768 | 768 | |
769 | 769 | return $result; |
770 | 770 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $this->config = $config; |
54 | 54 | $this->timeParser = new IsoTimestampParser(); |
55 | 55 | $this->timeCalculator = new TimeValueCalculator(); |
56 | - $this->timeValueComparer = new TimeValueComparer( $this->timeCalculator ); |
|
56 | + $this->timeValueComparer = new TimeValueComparer($this->timeCalculator); |
|
57 | 57 | $this->unitConverter = $unitConverter; |
58 | 58 | } |
59 | 59 | |
@@ -61,10 +61,10 @@ discard block |
||
61 | 61 | * @param UnboundedQuantityValue $value |
62 | 62 | * @return UnboundedQuantityValue $value converted to standard units if possible, otherwise unchanged $value. |
63 | 63 | */ |
64 | - private function standardize( UnboundedQuantityValue $value ) { |
|
65 | - if ( $this->unitConverter !== null ) { |
|
66 | - $standard = $this->unitConverter->toStandardUnits( $value ); |
|
67 | - if ( $standard !== null ) { |
|
64 | + private function standardize(UnboundedQuantityValue $value) { |
|
65 | + if ($this->unitConverter !== null) { |
|
66 | + $standard = $this->unitConverter->toStandardUnits($value); |
|
67 | + if ($standard !== null) { |
|
68 | 68 | return $standard; |
69 | 69 | } else { |
70 | 70 | return $value; |
@@ -86,33 +86,33 @@ discard block |
||
86 | 86 | * when $lhs is respectively less than, equal to, or greater than $rhs. |
87 | 87 | * (In other words, just like the “spaceship” operator <=>.) |
88 | 88 | */ |
89 | - public function getComparison( ?DataValue $lhs = null, ?DataValue $rhs = null ) { |
|
90 | - if ( $lhs === null || $rhs === null ) { |
|
89 | + public function getComparison(?DataValue $lhs = null, ?DataValue $rhs = null) { |
|
90 | + if ($lhs === null || $rhs === null) { |
|
91 | 91 | return 0; |
92 | 92 | } |
93 | 93 | |
94 | - if ( $lhs->getType() !== $rhs->getType() ) { |
|
95 | - throw new InvalidArgumentException( 'Different data value types' ); |
|
94 | + if ($lhs->getType() !== $rhs->getType()) { |
|
95 | + throw new InvalidArgumentException('Different data value types'); |
|
96 | 96 | } |
97 | 97 | |
98 | - switch ( $lhs->getType() ) { |
|
98 | + switch ($lhs->getType()) { |
|
99 | 99 | case 'time': |
100 | 100 | /** @var TimeValue $lhs */ |
101 | 101 | /** @var TimeValue $rhs */ |
102 | 102 | '@phan-var TimeValue $lhs'; |
103 | 103 | '@phan-var TimeValue $rhs'; |
104 | - return $this->timeValueComparer->getComparison( $lhs, $rhs ); |
|
104 | + return $this->timeValueComparer->getComparison($lhs, $rhs); |
|
105 | 105 | case 'quantity': |
106 | 106 | /** @var QuantityValue|UnboundedQuantityValue $lhs */ |
107 | 107 | /** @var QuantityValue|UnboundedQuantityValue $rhs */ |
108 | 108 | '@phan-var QuantityValue|UnboundedQuantityValue $lhs'; |
109 | 109 | '@phan-var QuantityValue|UnboundedQuantityValue $rhs'; |
110 | - $lhsStandard = $this->standardize( $lhs ); |
|
111 | - $rhsStandard = $this->standardize( $rhs ); |
|
112 | - return $lhsStandard->getAmount()->compare( $rhsStandard->getAmount() ); |
|
110 | + $lhsStandard = $this->standardize($lhs); |
|
111 | + $rhsStandard = $this->standardize($rhs); |
|
112 | + return $lhsStandard->getAmount()->compare($rhsStandard->getAmount()); |
|
113 | 113 | } |
114 | 114 | |
115 | - throw new InvalidArgumentException( 'Unsupported data value type' ); |
|
115 | + throw new InvalidArgumentException('Unsupported data value type'); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -127,71 +127,71 @@ discard block |
||
127 | 127 | * @throws InvalidArgumentException if the values do not both have the same, supported data value type |
128 | 128 | * @return UnboundedQuantityValue |
129 | 129 | */ |
130 | - public function getDifference( DataValue $minuend, DataValue $subtrahend ) { |
|
131 | - if ( $minuend->getType() === 'time' && $subtrahend->getType() === 'time' ) { |
|
132 | - $minuendSeconds = $this->timeCalculator->getTimestamp( $minuend ); |
|
133 | - $subtrahendSeconds = $this->timeCalculator->getTimestamp( $subtrahend ); |
|
130 | + public function getDifference(DataValue $minuend, DataValue $subtrahend) { |
|
131 | + if ($minuend->getType() === 'time' && $subtrahend->getType() === 'time') { |
|
132 | + $minuendSeconds = $this->timeCalculator->getTimestamp($minuend); |
|
133 | + $subtrahendSeconds = $this->timeCalculator->getTimestamp($subtrahend); |
|
134 | 134 | return UnboundedQuantityValue::newFromNumber( |
135 | 135 | $minuendSeconds - $subtrahendSeconds, |
136 | - $this->config->get( 'WBQualityConstraintsSecondUnit' ) |
|
136 | + $this->config->get('WBQualityConstraintsSecondUnit') |
|
137 | 137 | ); |
138 | 138 | } |
139 | - if ( $minuend->getType() === 'quantity' && $subtrahend->getType() === 'quantity' ) { |
|
140 | - $minuendStandard = $this->standardize( $minuend ); |
|
141 | - $subtrahendStandard = $this->standardize( $subtrahend ); |
|
139 | + if ($minuend->getType() === 'quantity' && $subtrahend->getType() === 'quantity') { |
|
140 | + $minuendStandard = $this->standardize($minuend); |
|
141 | + $subtrahendStandard = $this->standardize($subtrahend); |
|
142 | 142 | $minuendValue = $minuendStandard->getAmount()->getValueFloat(); |
143 | 143 | $subtrahendValue = $subtrahendStandard->getAmount()->getValueFloat(); |
144 | 144 | $diff = $minuendValue - $subtrahendValue; |
145 | 145 | // we don’t check whether both quantities have the same standard unit – |
146 | 146 | // that’s the job of a different constraint type, Units (T164372) |
147 | - return UnboundedQuantityValue::newFromNumber( $diff, $minuendStandard->getUnit() ); |
|
147 | + return UnboundedQuantityValue::newFromNumber($diff, $minuendStandard->getUnit()); |
|
148 | 148 | } |
149 | 149 | |
150 | - throw new InvalidArgumentException( 'Unsupported or different data value types' ); |
|
150 | + throw new InvalidArgumentException('Unsupported or different data value types'); |
|
151 | 151 | } |
152 | 152 | |
153 | - public function getDifferenceInYears( TimeValue $minuend, TimeValue $subtrahend ) { |
|
154 | - if ( !preg_match( '/^([-+]\d{1,16})-(.*)$/', $minuend->getTime(), $minuendMatches ) || |
|
155 | - !preg_match( '/^([-+]\d{1,16})-(.*)$/', $subtrahend->getTime(), $subtrahendMatches ) |
|
153 | + public function getDifferenceInYears(TimeValue $minuend, TimeValue $subtrahend) { |
|
154 | + if (!preg_match('/^([-+]\d{1,16})-(.*)$/', $minuend->getTime(), $minuendMatches) || |
|
155 | + !preg_match('/^([-+]\d{1,16})-(.*)$/', $subtrahend->getTime(), $subtrahendMatches) |
|
156 | 156 | ) { |
157 | - throw new InvalidArgumentException( 'TimeValue::getTime() did not match expected format' ); |
|
157 | + throw new InvalidArgumentException('TimeValue::getTime() did not match expected format'); |
|
158 | 158 | } |
159 | - $minuendYear = (float)$minuendMatches[1]; |
|
160 | - $subtrahendYear = (float)$subtrahendMatches[1]; |
|
159 | + $minuendYear = (float) $minuendMatches[1]; |
|
160 | + $subtrahendYear = (float) $subtrahendMatches[1]; |
|
161 | 161 | $minuendRest = $minuendMatches[2]; |
162 | 162 | $subtrahendRest = $subtrahendMatches[2]; |
163 | 163 | |
164 | 164 | // calculate difference of years |
165 | 165 | $diff = $minuendYear - $subtrahendYear; |
166 | - if ( $minuendYear > 0.0 && $subtrahendYear < 0.0 ) { |
|
166 | + if ($minuendYear > 0.0 && $subtrahendYear < 0.0) { |
|
167 | 167 | $diff -= 1.0; // there is no year 0, remove it from difference |
168 | - } elseif ( $minuendYear < 0.0 && $subtrahendYear > 0.0 ) { |
|
168 | + } elseif ($minuendYear < 0.0 && $subtrahendYear > 0.0) { |
|
169 | 169 | $diff -= -1.0; // there is no year 0, remove it from negative difference |
170 | 170 | } |
171 | 171 | |
172 | 172 | // adjust for date within year by parsing the month-day part within the same year |
173 | - $minuendDateValue = $this->timeParser->parse( '+0000000000001970-' . $minuendRest ); |
|
174 | - $subtrahendDateValue = $this->timeParser->parse( '+0000000000001970-' . $subtrahendRest ); |
|
175 | - $minuendDateSeconds = $this->timeCalculator->getTimestamp( $minuendDateValue ); |
|
176 | - $subtrahendDateSeconds = $this->timeCalculator->getTimestamp( $subtrahendDateValue ); |
|
177 | - if ( $minuendDateSeconds < $subtrahendDateSeconds ) { |
|
173 | + $minuendDateValue = $this->timeParser->parse('+0000000000001970-'.$minuendRest); |
|
174 | + $subtrahendDateValue = $this->timeParser->parse('+0000000000001970-'.$subtrahendRest); |
|
175 | + $minuendDateSeconds = $this->timeCalculator->getTimestamp($minuendDateValue); |
|
176 | + $subtrahendDateSeconds = $this->timeCalculator->getTimestamp($subtrahendDateValue); |
|
177 | + if ($minuendDateSeconds < $subtrahendDateSeconds) { |
|
178 | 178 | // difference in the last year is actually less than one full year |
179 | 179 | // e. g. 1975-03-01 - 1974-09-01 is just six months |
180 | 180 | // (we don’t need sub-year precision in the difference, adjusting by 0.5 is enough) |
181 | 181 | $diff -= 0.5; |
182 | - } elseif ( $minuendDateSeconds > $subtrahendDateSeconds ) { |
|
182 | + } elseif ($minuendDateSeconds > $subtrahendDateSeconds) { |
|
183 | 183 | // difference in the last year is actually more than one full year |
184 | 184 | // e. g. 1975-09-01 - 1974-03-01 is 18 months |
185 | 185 | // (we don’t need sub-year precision in the difference, adjusting by 0.5 is enough) |
186 | 186 | $diff += 0.5; |
187 | 187 | } |
188 | 188 | |
189 | - $unit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
190 | - return UnboundedQuantityValue::newFromNumber( $diff, $unit ); |
|
189 | + $unit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
190 | + return UnboundedQuantityValue::newFromNumber($diff, $unit); |
|
191 | 191 | } |
192 | 192 | |
193 | - public function isFutureTime( TimeValue $timeValue ) { |
|
194 | - return $this->timeValueComparer->isFutureTime( $timeValue ); |
|
193 | + public function isFutureTime(TimeValue $timeValue) { |
|
194 | + return $this->timeValueComparer->isFutureTime($timeValue); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Helper; |
6 | 6 | |
@@ -68,15 +68,15 @@ discard block |
||
68 | 68 | * Check if any errors are recorded in the constraint parameters. |
69 | 69 | * @throws ConstraintParameterException |
70 | 70 | */ |
71 | - public function checkError( array $parameters ): void { |
|
72 | - if ( array_key_exists( '@error', $parameters ) ) { |
|
71 | + public function checkError(array $parameters): void { |
|
72 | + if (array_key_exists('@error', $parameters)) { |
|
73 | 73 | $error = $parameters['@error']; |
74 | - if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) { |
|
74 | + if (array_key_exists('toolong', $error) && $error['toolong']) { |
|
75 | 75 | $msg = 'wbqc-violation-message-parameters-error-toolong'; |
76 | 76 | } else { |
77 | 77 | $msg = 'wbqc-violation-message-parameters-error-unknown'; |
78 | 78 | } |
79 | - throw new ConstraintParameterException( new ViolationMessage( $msg ) ); |
|
79 | + throw new ConstraintParameterException(new ViolationMessage($msg)); |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | |
@@ -84,11 +84,11 @@ discard block |
||
84 | 84 | * Require that $parameters contains exactly one $parameterId parameter. |
85 | 85 | * @throws ConstraintParameterException |
86 | 86 | */ |
87 | - private function requireSingleParameter( array $parameters, string $parameterId ): void { |
|
88 | - if ( count( $parameters[$parameterId] ) !== 1 ) { |
|
87 | + private function requireSingleParameter(array $parameters, string $parameterId): void { |
|
88 | + if (count($parameters[$parameterId]) !== 1) { |
|
89 | 89 | throw new ConstraintParameterException( |
90 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single' ) ) |
|
91 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
90 | + (new ViolationMessage('wbqc-violation-message-parameter-single')) |
|
91 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
92 | 92 | ); |
93 | 93 | } |
94 | 94 | } |
@@ -97,11 +97,11 @@ discard block |
||
97 | 97 | * Require that $snak is a {@link PropertyValueSnak}. |
98 | 98 | * @throws ConstraintParameterException |
99 | 99 | */ |
100 | - private function requireValueParameter( Snak $snak, string $parameterId ): void { |
|
101 | - if ( !( $snak instanceof PropertyValueSnak ) ) { |
|
100 | + private function requireValueParameter(Snak $snak, string $parameterId): void { |
|
101 | + if (!($snak instanceof PropertyValueSnak)) { |
|
102 | 102 | throw new ConstraintParameterException( |
103 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
104 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
103 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
104 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
105 | 105 | ); |
106 | 106 | } |
107 | 107 | } |
@@ -110,17 +110,17 @@ discard block |
||
110 | 110 | * Parse a single entity ID parameter. |
111 | 111 | * @throws ConstraintParameterException |
112 | 112 | */ |
113 | - private function parseEntityIdParameter( array $snakSerialization, string $parameterId ): EntityId { |
|
114 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
115 | - $this->requireValueParameter( $snak, $parameterId ); |
|
113 | + private function parseEntityIdParameter(array $snakSerialization, string $parameterId): EntityId { |
|
114 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
115 | + $this->requireValueParameter($snak, $parameterId); |
|
116 | 116 | $value = $snak->getDataValue(); |
117 | - if ( $value instanceof EntityIdValue ) { |
|
117 | + if ($value instanceof EntityIdValue) { |
|
118 | 118 | return $value->getEntityId(); |
119 | 119 | } else { |
120 | 120 | throw new ConstraintParameterException( |
121 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-entity' ) ) |
|
122 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
123 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
121 | + (new ViolationMessage('wbqc-violation-message-parameter-entity')) |
|
122 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
123 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
124 | 124 | ); |
125 | 125 | } |
126 | 126 | } |
@@ -131,20 +131,20 @@ discard block |
||
131 | 131 | * @throws ConstraintParameterException if the parameter is invalid or missing |
132 | 132 | * @return string[] class entity ID serializations |
133 | 133 | */ |
134 | - public function parseClassParameter( array $constraintParameters, string $constraintTypeItemId ): array { |
|
135 | - $this->checkError( $constraintParameters ); |
|
136 | - $classId = $this->config->get( 'WBQualityConstraintsClassId' ); |
|
137 | - if ( !array_key_exists( $classId, $constraintParameters ) ) { |
|
134 | + public function parseClassParameter(array $constraintParameters, string $constraintTypeItemId): array { |
|
135 | + $this->checkError($constraintParameters); |
|
136 | + $classId = $this->config->get('WBQualityConstraintsClassId'); |
|
137 | + if (!array_key_exists($classId, $constraintParameters)) { |
|
138 | 138 | throw new ConstraintParameterException( |
139 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
140 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
141 | - ->withEntityId( new NumericPropertyId( $classId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
139 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
140 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
141 | + ->withEntityId(new NumericPropertyId($classId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
142 | 142 | ); |
143 | 143 | } |
144 | 144 | |
145 | 145 | $classes = []; |
146 | - foreach ( $constraintParameters[$classId] as $class ) { |
|
147 | - $classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization(); |
|
146 | + foreach ($constraintParameters[$classId] as $class) { |
|
147 | + $classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization(); |
|
148 | 148 | } |
149 | 149 | return $classes; |
150 | 150 | } |
@@ -155,31 +155,31 @@ discard block |
||
155 | 155 | * @throws ConstraintParameterException if the parameter is invalid or missing |
156 | 156 | * @return string 'instance', 'subclass', or 'instanceOrSubclass' |
157 | 157 | */ |
158 | - public function parseRelationParameter( array $constraintParameters, string $constraintTypeItemId ): string { |
|
159 | - $this->checkError( $constraintParameters ); |
|
160 | - $relationId = $this->config->get( 'WBQualityConstraintsRelationId' ); |
|
161 | - if ( !array_key_exists( $relationId, $constraintParameters ) ) { |
|
158 | + public function parseRelationParameter(array $constraintParameters, string $constraintTypeItemId): string { |
|
159 | + $this->checkError($constraintParameters); |
|
160 | + $relationId = $this->config->get('WBQualityConstraintsRelationId'); |
|
161 | + if (!array_key_exists($relationId, $constraintParameters)) { |
|
162 | 162 | throw new ConstraintParameterException( |
163 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
164 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
165 | - ->withEntityId( new NumericPropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
163 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
164 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
165 | + ->withEntityId(new NumericPropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
166 | 166 | ); |
167 | 167 | } |
168 | 168 | |
169 | - $this->requireSingleParameter( $constraintParameters, $relationId ); |
|
170 | - $relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId ); |
|
171 | - if ( !( $relationEntityId instanceof ItemId ) ) { |
|
169 | + $this->requireSingleParameter($constraintParameters, $relationId); |
|
170 | + $relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId); |
|
171 | + if (!($relationEntityId instanceof ItemId)) { |
|
172 | 172 | throw new ConstraintParameterException( |
173 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) ) |
|
174 | - ->withEntityId( new NumericPropertyId( $relationId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
175 | - ->withDataValue( new EntityIdValue( $relationEntityId ), Role::CONSTRAINT_PARAMETER_VALUE ) |
|
173 | + (new ViolationMessage('wbqc-violation-message-parameter-item')) |
|
174 | + ->withEntityId(new NumericPropertyId($relationId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
175 | + ->withDataValue(new EntityIdValue($relationEntityId), Role::CONSTRAINT_PARAMETER_VALUE) |
|
176 | 176 | ); |
177 | 177 | } |
178 | - return $this->mapItemId( $relationEntityId, [ |
|
179 | - $this->config->get( 'WBQualityConstraintsInstanceOfRelationId' ) => 'instance', |
|
180 | - $this->config->get( 'WBQualityConstraintsSubclassOfRelationId' ) => 'subclass', |
|
181 | - $this->config->get( 'WBQualityConstraintsInstanceOrSubclassOfRelationId' ) => 'instanceOrSubclass', |
|
182 | - ], $relationId ); |
|
178 | + return $this->mapItemId($relationEntityId, [ |
|
179 | + $this->config->get('WBQualityConstraintsInstanceOfRelationId') => 'instance', |
|
180 | + $this->config->get('WBQualityConstraintsSubclassOfRelationId') => 'subclass', |
|
181 | + $this->config->get('WBQualityConstraintsInstanceOrSubclassOfRelationId') => 'instanceOrSubclass', |
|
182 | + ], $relationId); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -189,20 +189,20 @@ discard block |
||
189 | 189 | * @throws ConstraintParameterException |
190 | 190 | * @return PropertyId |
191 | 191 | */ |
192 | - private function parsePropertyIdParameter( array $snakSerialization, string $parameterId ): PropertyId { |
|
193 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
194 | - $this->requireValueParameter( $snak, $parameterId ); |
|
192 | + private function parsePropertyIdParameter(array $snakSerialization, string $parameterId): PropertyId { |
|
193 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
194 | + $this->requireValueParameter($snak, $parameterId); |
|
195 | 195 | $value = $snak->getDataValue(); |
196 | - if ( $value instanceof EntityIdValue ) { |
|
196 | + if ($value instanceof EntityIdValue) { |
|
197 | 197 | $id = $value->getEntityId(); |
198 | - if ( $id instanceof PropertyId ) { |
|
198 | + if ($id instanceof PropertyId) { |
|
199 | 199 | return $id; |
200 | 200 | } |
201 | 201 | } |
202 | 202 | throw new ConstraintParameterException( |
203 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-property' ) ) |
|
204 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
205 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
203 | + (new ViolationMessage('wbqc-violation-message-parameter-property')) |
|
204 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
205 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
206 | 206 | ); |
207 | 207 | } |
208 | 208 | |
@@ -213,33 +213,33 @@ discard block |
||
213 | 213 | * @throws ConstraintParameterException if the parameter is invalid or missing |
214 | 214 | * @return PropertyId |
215 | 215 | */ |
216 | - public function parsePropertyParameter( array $constraintParameters, string $constraintTypeItemId ): PropertyId { |
|
217 | - $this->checkError( $constraintParameters ); |
|
218 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
219 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
216 | + public function parsePropertyParameter(array $constraintParameters, string $constraintTypeItemId): PropertyId { |
|
217 | + $this->checkError($constraintParameters); |
|
218 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
219 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
220 | 220 | throw new ConstraintParameterException( |
221 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
222 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
223 | - ->withEntityId( new NumericPropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
221 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
222 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
223 | + ->withEntityId(new NumericPropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
224 | 224 | ); |
225 | 225 | } |
226 | 226 | |
227 | - $this->requireSingleParameter( $constraintParameters, $propertyId ); |
|
228 | - return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId ); |
|
227 | + $this->requireSingleParameter($constraintParameters, $propertyId); |
|
228 | + return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId); |
|
229 | 229 | } |
230 | 230 | |
231 | - private function parseItemIdParameter( PropertyValueSnak $snak, string $parameterId ): ItemIdSnakValue { |
|
231 | + private function parseItemIdParameter(PropertyValueSnak $snak, string $parameterId): ItemIdSnakValue { |
|
232 | 232 | $dataValue = $snak->getDataValue(); |
233 | - if ( $dataValue instanceof EntityIdValue ) { |
|
233 | + if ($dataValue instanceof EntityIdValue) { |
|
234 | 234 | $entityId = $dataValue->getEntityId(); |
235 | - if ( $entityId instanceof ItemId ) { |
|
236 | - return ItemIdSnakValue::fromItemId( $entityId ); |
|
235 | + if ($entityId instanceof ItemId) { |
|
236 | + return ItemIdSnakValue::fromItemId($entityId); |
|
237 | 237 | } |
238 | 238 | } |
239 | 239 | throw new ConstraintParameterException( |
240 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-item' ) ) |
|
241 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
242 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
240 | + (new ViolationMessage('wbqc-violation-message-parameter-item')) |
|
241 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
242 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
243 | 243 | ); |
244 | 244 | } |
245 | 245 | |
@@ -257,14 +257,14 @@ discard block |
||
257 | 257 | bool $required, |
258 | 258 | ?string $parameterId = null |
259 | 259 | ): array { |
260 | - $this->checkError( $constraintParameters ); |
|
261 | - $parameterId ??= $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
262 | - if ( !array_key_exists( $parameterId, $constraintParameters ) ) { |
|
263 | - if ( $required ) { |
|
260 | + $this->checkError($constraintParameters); |
|
261 | + $parameterId ??= $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
262 | + if (!array_key_exists($parameterId, $constraintParameters)) { |
|
263 | + if ($required) { |
|
264 | 264 | throw new ConstraintParameterException( |
265 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
266 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
267 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
265 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
266 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
267 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
268 | 268 | ); |
269 | 269 | } else { |
270 | 270 | return []; |
@@ -272,11 +272,11 @@ discard block |
||
272 | 272 | } |
273 | 273 | |
274 | 274 | $values = []; |
275 | - foreach ( $constraintParameters[$parameterId] as $parameter ) { |
|
276 | - $snak = $this->snakDeserializer->deserialize( $parameter ); |
|
277 | - switch ( true ) { |
|
275 | + foreach ($constraintParameters[$parameterId] as $parameter) { |
|
276 | + $snak = $this->snakDeserializer->deserialize($parameter); |
|
277 | + switch (true) { |
|
278 | 278 | case $snak instanceof PropertyValueSnak: |
279 | - $values[] = $this->parseItemIdParameter( $snak, $parameterId ); |
|
279 | + $values[] = $this->parseItemIdParameter($snak, $parameterId); |
|
280 | 280 | break; |
281 | 281 | case $snak instanceof PropertySomeValueSnak: |
282 | 282 | $values[] = ItemIdSnakValue::someValue(); |
@@ -304,13 +304,13 @@ discard block |
||
304 | 304 | bool $required, |
305 | 305 | string $parameterId |
306 | 306 | ): array { |
307 | - return array_map( static function ( ItemIdSnakValue $value ) use ( $parameterId ): ItemId { |
|
308 | - if ( $value->isValue() ) { |
|
307 | + return array_map(static function(ItemIdSnakValue $value) use ($parameterId): ItemId { |
|
308 | + if ($value->isValue()) { |
|
309 | 309 | return $value->getItemId(); |
310 | 310 | } else { |
311 | 311 | throw new ConstraintParameterException( |
312 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value' ) ) |
|
313 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
312 | + (new ViolationMessage('wbqc-violation-message-parameter-value')) |
|
313 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
314 | 314 | ); |
315 | 315 | } |
316 | 316 | }, $this->parseItemsParameter( |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | $constraintTypeItemId, |
319 | 319 | $required, |
320 | 320 | $parameterId |
321 | - ) ); |
|
321 | + )); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
@@ -326,18 +326,18 @@ discard block |
||
326 | 326 | * @throws ConstraintParameterException |
327 | 327 | * @return mixed elements of $mapping |
328 | 328 | */ |
329 | - private function mapItemId( ItemId $itemId, array $mapping, string $parameterId ) { |
|
329 | + private function mapItemId(ItemId $itemId, array $mapping, string $parameterId) { |
|
330 | 330 | $serialization = $itemId->getSerialization(); |
331 | - if ( array_key_exists( $serialization, $mapping ) ) { |
|
331 | + if (array_key_exists($serialization, $mapping)) { |
|
332 | 332 | return $mapping[$serialization]; |
333 | 333 | } else { |
334 | - $allowed = array_map( static function ( $id ) { |
|
335 | - return new ItemId( $id ); |
|
336 | - }, array_keys( $mapping ) ); |
|
334 | + $allowed = array_map(static function($id) { |
|
335 | + return new ItemId($id); |
|
336 | + }, array_keys($mapping)); |
|
337 | 337 | throw new ConstraintParameterException( |
338 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
339 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
340 | - ->withEntityIdList( $allowed, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
338 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
339 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
340 | + ->withEntityIdList($allowed, Role::CONSTRAINT_PARAMETER_VALUE) |
|
341 | 341 | ); |
342 | 342 | } |
343 | 343 | } |
@@ -348,27 +348,27 @@ discard block |
||
348 | 348 | * @throws ConstraintParameterException if the parameter is invalid or missing |
349 | 349 | * @return PropertyId[] |
350 | 350 | */ |
351 | - public function parsePropertiesParameter( array $constraintParameters, string $constraintTypeItemId ): array { |
|
352 | - $this->checkError( $constraintParameters ); |
|
353 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
354 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
351 | + public function parsePropertiesParameter(array $constraintParameters, string $constraintTypeItemId): array { |
|
352 | + $this->checkError($constraintParameters); |
|
353 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
354 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
355 | 355 | throw new ConstraintParameterException( |
356 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
357 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
358 | - ->withEntityId( new NumericPropertyId( $propertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
356 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
357 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
358 | + ->withEntityId(new NumericPropertyId($propertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
359 | 359 | ); |
360 | 360 | } |
361 | 361 | |
362 | 362 | $parameters = $constraintParameters[$propertyId]; |
363 | - if ( count( $parameters ) === 1 && |
|
364 | - $this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak |
|
363 | + if (count($parameters) === 1 && |
|
364 | + $this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak |
|
365 | 365 | ) { |
366 | 366 | return []; |
367 | 367 | } |
368 | 368 | |
369 | 369 | $properties = []; |
370 | - foreach ( $parameters as $parameter ) { |
|
371 | - $properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId ); |
|
370 | + foreach ($parameters as $parameter) { |
|
371 | + $properties[] = $this->parsePropertyIdParameter($parameter, $propertyId); |
|
372 | 372 | } |
373 | 373 | return $properties; |
374 | 374 | } |
@@ -376,24 +376,24 @@ discard block |
||
376 | 376 | /** |
377 | 377 | * @throws ConstraintParameterException |
378 | 378 | */ |
379 | - private function parseValueOrNoValueParameter( array $snakSerialization, string $parameterId ): ?DataValue { |
|
380 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
381 | - if ( $snak instanceof PropertyValueSnak ) { |
|
379 | + private function parseValueOrNoValueParameter(array $snakSerialization, string $parameterId): ?DataValue { |
|
380 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
381 | + if ($snak instanceof PropertyValueSnak) { |
|
382 | 382 | return $snak->getDataValue(); |
383 | - } elseif ( $snak instanceof PropertyNoValueSnak ) { |
|
383 | + } elseif ($snak instanceof PropertyNoValueSnak) { |
|
384 | 384 | return null; |
385 | 385 | } else { |
386 | 386 | throw new ConstraintParameterException( |
387 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
388 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
387 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
388 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
389 | 389 | ); |
390 | 390 | } |
391 | 391 | } |
392 | 392 | |
393 | - private function parseValueOrNoValueOrNowParameter( array $snakSerialization, string $parameterId ): ?DataValue { |
|
393 | + private function parseValueOrNoValueOrNowParameter(array $snakSerialization, string $parameterId): ?DataValue { |
|
394 | 394 | try { |
395 | - return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId ); |
|
396 | - } catch ( ConstraintParameterException $e ) { |
|
395 | + return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId); |
|
396 | + } catch (ConstraintParameterException $e) { |
|
397 | 397 | // unknown value means “now” |
398 | 398 | return new NowValue(); |
399 | 399 | } |
@@ -402,14 +402,14 @@ discard block |
||
402 | 402 | /** |
403 | 403 | * Checks whether there is exactly one non-null quantity with the given unit. |
404 | 404 | */ |
405 | - private function exactlyOneQuantityWithUnit( ?DataValue $min, ?DataValue $max, string $unit ): bool { |
|
406 | - if ( !( $min instanceof UnboundedQuantityValue ) || |
|
407 | - !( $max instanceof UnboundedQuantityValue ) |
|
405 | + private function exactlyOneQuantityWithUnit(?DataValue $min, ?DataValue $max, string $unit): bool { |
|
406 | + if (!($min instanceof UnboundedQuantityValue) || |
|
407 | + !($max instanceof UnboundedQuantityValue) |
|
408 | 408 | ) { |
409 | 409 | return false; |
410 | 410 | } |
411 | 411 | |
412 | - return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit ); |
|
412 | + return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit); |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | /** |
@@ -429,42 +429,42 @@ discard block |
||
429 | 429 | string $constraintTypeItemId, |
430 | 430 | string $type |
431 | 431 | ): array { |
432 | - $this->checkError( $constraintParameters ); |
|
433 | - if ( !array_key_exists( $minimumId, $constraintParameters ) || |
|
434 | - !array_key_exists( $maximumId, $constraintParameters ) |
|
432 | + $this->checkError($constraintParameters); |
|
433 | + if (!array_key_exists($minimumId, $constraintParameters) || |
|
434 | + !array_key_exists($maximumId, $constraintParameters) |
|
435 | 435 | ) { |
436 | 436 | throw new ConstraintParameterException( |
437 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-needed' ) ) |
|
438 | - ->withDataValueType( $type ) |
|
439 | - ->withEntityId( new NumericPropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
440 | - ->withEntityId( new NumericPropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
441 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
437 | + (new ViolationMessage('wbqc-violation-message-range-parameters-needed')) |
|
438 | + ->withDataValueType($type) |
|
439 | + ->withEntityId(new NumericPropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
440 | + ->withEntityId(new NumericPropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
441 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
442 | 442 | ); |
443 | 443 | } |
444 | 444 | |
445 | - $this->requireSingleParameter( $constraintParameters, $minimumId ); |
|
446 | - $this->requireSingleParameter( $constraintParameters, $maximumId ); |
|
445 | + $this->requireSingleParameter($constraintParameters, $minimumId); |
|
446 | + $this->requireSingleParameter($constraintParameters, $maximumId); |
|
447 | 447 | $parseFunction = $type === 'time' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter'; |
448 | - $min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId ); |
|
449 | - $max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId ); |
|
448 | + $min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId); |
|
449 | + $max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId); |
|
450 | 450 | |
451 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
452 | - if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) { |
|
451 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
452 | + if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) { |
|
453 | 453 | throw new ConstraintParameterException( |
454 | - new ViolationMessage( 'wbqc-violation-message-range-parameters-one-year' ) |
|
454 | + new ViolationMessage('wbqc-violation-message-range-parameters-one-year') |
|
455 | 455 | ); |
456 | 456 | } |
457 | - if ( ( $min === null && $max === null ) || |
|
458 | - ( $min !== null && $max !== null && $min->equals( $max ) ) |
|
457 | + if (($min === null && $max === null) || |
|
458 | + ($min !== null && $max !== null && $min->equals($max)) |
|
459 | 459 | ) { |
460 | 460 | throw new ConstraintParameterException( |
461 | - ( new ViolationMessage( 'wbqc-violation-message-range-parameters-same' ) ) |
|
462 | - ->withEntityId( new NumericPropertyId( $minimumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
463 | - ->withEntityId( new NumericPropertyId( $maximumId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
461 | + (new ViolationMessage('wbqc-violation-message-range-parameters-same')) |
|
462 | + ->withEntityId(new NumericPropertyId($minimumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
463 | + ->withEntityId(new NumericPropertyId($maximumId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
464 | 464 | ); |
465 | 465 | } |
466 | 466 | |
467 | - return [ $min, $max ]; |
|
467 | + return [$min, $max]; |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | /** |
@@ -474,11 +474,11 @@ discard block |
||
474 | 474 | * @throws ConstraintParameterException if the parameter is invalid or missing |
475 | 475 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
476 | 476 | */ |
477 | - public function parseQuantityRangeParameter( array $constraintParameters, string $constraintTypeItemId ): array { |
|
477 | + public function parseQuantityRangeParameter(array $constraintParameters, string $constraintTypeItemId): array { |
|
478 | 478 | return $this->parseRangeParameter( |
479 | 479 | $constraintParameters, |
480 | - $this->config->get( 'WBQualityConstraintsMinimumQuantityId' ), |
|
481 | - $this->config->get( 'WBQualityConstraintsMaximumQuantityId' ), |
|
480 | + $this->config->get('WBQualityConstraintsMinimumQuantityId'), |
|
481 | + $this->config->get('WBQualityConstraintsMaximumQuantityId'), |
|
482 | 482 | $constraintTypeItemId, |
483 | 483 | 'quantity' |
484 | 484 | ); |
@@ -491,11 +491,11 @@ discard block |
||
491 | 491 | * @throws ConstraintParameterException if the parameter is invalid or missing |
492 | 492 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
493 | 493 | */ |
494 | - public function parseTimeRangeParameter( array $constraintParameters, string $constraintTypeItemId ): array { |
|
494 | + public function parseTimeRangeParameter(array $constraintParameters, string $constraintTypeItemId): array { |
|
495 | 495 | return $this->parseRangeParameter( |
496 | 496 | $constraintParameters, |
497 | - $this->config->get( 'WBQualityConstraintsMinimumDateId' ), |
|
498 | - $this->config->get( 'WBQualityConstraintsMaximumDateId' ), |
|
497 | + $this->config->get('WBQualityConstraintsMinimumDateId'), |
|
498 | + $this->config->get('WBQualityConstraintsMaximumDateId'), |
|
499 | 499 | $constraintTypeItemId, |
500 | 500 | 'time' |
501 | 501 | ); |
@@ -508,20 +508,20 @@ discard block |
||
508 | 508 | * @throws ConstraintParameterException |
509 | 509 | * @return string[] |
510 | 510 | */ |
511 | - public function parseLanguageParameter( array $constraintParameters, string $constraintTypeItemId ): array { |
|
512 | - $this->checkError( $constraintParameters ); |
|
513 | - $languagePropertyId = $this->config->get( 'WBQualityConstraintsLanguagePropertyId' ); |
|
514 | - if ( !array_key_exists( $languagePropertyId, $constraintParameters ) ) { |
|
511 | + public function parseLanguageParameter(array $constraintParameters, string $constraintTypeItemId): array { |
|
512 | + $this->checkError($constraintParameters); |
|
513 | + $languagePropertyId = $this->config->get('WBQualityConstraintsLanguagePropertyId'); |
|
514 | + if (!array_key_exists($languagePropertyId, $constraintParameters)) { |
|
515 | 515 | throw new ConstraintParameterException( |
516 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
517 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
518 | - ->withEntityId( new NumericPropertyId( $languagePropertyId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
516 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
517 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
518 | + ->withEntityId(new NumericPropertyId($languagePropertyId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
519 | 519 | ); |
520 | 520 | } |
521 | 521 | |
522 | 522 | $languages = []; |
523 | - foreach ( $constraintParameters[$languagePropertyId] as $snak ) { |
|
524 | - $languages[] = $this->parseStringParameter( $snak, $languagePropertyId ); |
|
523 | + foreach ($constraintParameters[$languagePropertyId] as $snak) { |
|
524 | + $languages[] = $this->parseStringParameter($snak, $languagePropertyId); |
|
525 | 525 | } |
526 | 526 | return $languages; |
527 | 527 | } |
@@ -530,17 +530,17 @@ discard block |
||
530 | 530 | * Parse a single string parameter. |
531 | 531 | * @throws ConstraintParameterException |
532 | 532 | */ |
533 | - private function parseStringParameter( array $snakSerialization, string $parameterId ): string { |
|
534 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
535 | - $this->requireValueParameter( $snak, $parameterId ); |
|
533 | + private function parseStringParameter(array $snakSerialization, string $parameterId): string { |
|
534 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
535 | + $this->requireValueParameter($snak, $parameterId); |
|
536 | 536 | $value = $snak->getDataValue(); |
537 | - if ( $value instanceof StringValue ) { |
|
537 | + if ($value instanceof StringValue) { |
|
538 | 538 | return $value->getValue(); |
539 | 539 | } else { |
540 | 540 | throw new ConstraintParameterException( |
541 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-string' ) ) |
|
542 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
543 | - ->withDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
541 | + (new ViolationMessage('wbqc-violation-message-parameter-string')) |
|
542 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
543 | + ->withDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
544 | 544 | ); |
545 | 545 | } |
546 | 546 | } |
@@ -551,15 +551,15 @@ discard block |
||
551 | 551 | * @throws ConstraintParameterException if the parameter is invalid or missing |
552 | 552 | * @return string |
553 | 553 | */ |
554 | - public function parseNamespaceParameter( array $constraintParameters, string $constraintTypeItemId ): string { |
|
555 | - $this->checkError( $constraintParameters ); |
|
556 | - $namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' ); |
|
557 | - if ( !array_key_exists( $namespaceId, $constraintParameters ) ) { |
|
554 | + public function parseNamespaceParameter(array $constraintParameters, string $constraintTypeItemId): string { |
|
555 | + $this->checkError($constraintParameters); |
|
556 | + $namespaceId = $this->config->get('WBQualityConstraintsNamespaceId'); |
|
557 | + if (!array_key_exists($namespaceId, $constraintParameters)) { |
|
558 | 558 | return ''; |
559 | 559 | } |
560 | 560 | |
561 | - $this->requireSingleParameter( $constraintParameters, $namespaceId ); |
|
562 | - return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId ); |
|
561 | + $this->requireSingleParameter($constraintParameters, $namespaceId); |
|
562 | + return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId); |
|
563 | 563 | } |
564 | 564 | |
565 | 565 | /** |
@@ -568,19 +568,19 @@ discard block |
||
568 | 568 | * @throws ConstraintParameterException if the parameter is invalid or missing |
569 | 569 | * @return string |
570 | 570 | */ |
571 | - public function parseFormatParameter( array $constraintParameters, string $constraintTypeItemId ): string { |
|
572 | - $this->checkError( $constraintParameters ); |
|
573 | - $formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' ); |
|
574 | - if ( !array_key_exists( $formatId, $constraintParameters ) ) { |
|
571 | + public function parseFormatParameter(array $constraintParameters, string $constraintTypeItemId): string { |
|
572 | + $this->checkError($constraintParameters); |
|
573 | + $formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId'); |
|
574 | + if (!array_key_exists($formatId, $constraintParameters)) { |
|
575 | 575 | throw new ConstraintParameterException( |
576 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-needed' ) ) |
|
577 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
578 | - ->withEntityId( new NumericPropertyId( $formatId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
576 | + (new ViolationMessage('wbqc-violation-message-parameter-needed')) |
|
577 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
578 | + ->withEntityId(new NumericPropertyId($formatId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
579 | 579 | ); |
580 | 580 | } |
581 | 581 | |
582 | - $this->requireSingleParameter( $constraintParameters, $formatId ); |
|
583 | - return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId ); |
|
582 | + $this->requireSingleParameter($constraintParameters, $formatId); |
|
583 | + return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | /** |
@@ -588,16 +588,16 @@ discard block |
||
588 | 588 | * @throws ConstraintParameterException if the parameter is invalid |
589 | 589 | * @return EntityId[] |
590 | 590 | */ |
591 | - public function parseExceptionParameter( array $constraintParameters ): array { |
|
592 | - $this->checkError( $constraintParameters ); |
|
593 | - $exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' ); |
|
594 | - if ( !array_key_exists( $exceptionId, $constraintParameters ) ) { |
|
591 | + public function parseExceptionParameter(array $constraintParameters): array { |
|
592 | + $this->checkError($constraintParameters); |
|
593 | + $exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId'); |
|
594 | + if (!array_key_exists($exceptionId, $constraintParameters)) { |
|
595 | 595 | return []; |
596 | 596 | } |
597 | 597 | |
598 | 598 | return array_map( |
599 | - function ( $snakSerialization ) use ( $exceptionId ) { |
|
600 | - return $this->parseEntityIdParameter( $snakSerialization, $exceptionId ); |
|
599 | + function($snakSerialization) use ($exceptionId) { |
|
600 | + return $this->parseEntityIdParameter($snakSerialization, $exceptionId); |
|
601 | 601 | }, |
602 | 602 | $constraintParameters[$exceptionId] |
603 | 603 | ); |
@@ -608,39 +608,39 @@ discard block |
||
608 | 608 | * @throws ConstraintParameterException if the parameter is invalid |
609 | 609 | * @return string|null 'mandatory', 'suggestion' or null |
610 | 610 | */ |
611 | - public function parseConstraintStatusParameter( array $constraintParameters ): ?string { |
|
612 | - $this->checkError( $constraintParameters ); |
|
613 | - $constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' ); |
|
614 | - if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) { |
|
611 | + public function parseConstraintStatusParameter(array $constraintParameters): ?string { |
|
612 | + $this->checkError($constraintParameters); |
|
613 | + $constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId'); |
|
614 | + if (!array_key_exists($constraintStatusId, $constraintParameters)) { |
|
615 | 615 | return null; |
616 | 616 | } |
617 | 617 | |
618 | - $mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' ); |
|
619 | - $supportedStatuses = [ new ItemId( $mandatoryId ) ]; |
|
620 | - if ( $this->config->get( 'WBQualityConstraintsEnableSuggestionConstraintStatus' ) ) { |
|
621 | - $suggestionId = $this->config->get( 'WBQualityConstraintsSuggestionConstraintId' ); |
|
622 | - $supportedStatuses[] = new ItemId( $suggestionId ); |
|
618 | + $mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId'); |
|
619 | + $supportedStatuses = [new ItemId($mandatoryId)]; |
|
620 | + if ($this->config->get('WBQualityConstraintsEnableSuggestionConstraintStatus')) { |
|
621 | + $suggestionId = $this->config->get('WBQualityConstraintsSuggestionConstraintId'); |
|
622 | + $supportedStatuses[] = new ItemId($suggestionId); |
|
623 | 623 | } else { |
624 | 624 | $suggestionId = null; |
625 | 625 | } |
626 | 626 | |
627 | - $this->requireSingleParameter( $constraintParameters, $constraintStatusId ); |
|
628 | - $snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] ); |
|
629 | - $this->requireValueParameter( $snak, $constraintStatusId ); |
|
627 | + $this->requireSingleParameter($constraintParameters, $constraintStatusId); |
|
628 | + $snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]); |
|
629 | + $this->requireValueParameter($snak, $constraintStatusId); |
|
630 | 630 | '@phan-var \Wikibase\DataModel\Snak\PropertyValueSnak $snak'; |
631 | 631 | $dataValue = $snak->getDataValue(); |
632 | 632 | '@phan-var EntityIdValue $dataValue'; |
633 | 633 | $entityId = $dataValue->getEntityId(); |
634 | 634 | $statusId = $entityId->getSerialization(); |
635 | 635 | |
636 | - if ( $statusId === $mandatoryId ) { |
|
636 | + if ($statusId === $mandatoryId) { |
|
637 | 637 | return 'mandatory'; |
638 | - } elseif ( $statusId === $suggestionId ) { |
|
638 | + } elseif ($statusId === $suggestionId) { |
|
639 | 639 | return 'suggestion'; |
640 | 640 | } else { |
641 | 641 | throw new ConstraintParameterException( |
642 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-oneof' ) ) |
|
643 | - ->withEntityId( new NumericPropertyId( $constraintStatusId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
642 | + (new ViolationMessage('wbqc-violation-message-parameter-oneof')) |
|
643 | + ->withEntityId(new NumericPropertyId($constraintStatusId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
644 | 644 | ->withEntityIdList( |
645 | 645 | $supportedStatuses, |
646 | 646 | Role::CONSTRAINT_PARAMETER_VALUE |
@@ -653,12 +653,12 @@ discard block |
||
653 | 653 | * Require that $dataValue is a {@link MonolingualTextValue}. |
654 | 654 | * @throws ConstraintParameterException |
655 | 655 | */ |
656 | - private function requireMonolingualTextParameter( DataValue $dataValue, string $parameterId ): void { |
|
657 | - if ( !( $dataValue instanceof MonolingualTextValue ) ) { |
|
656 | + private function requireMonolingualTextParameter(DataValue $dataValue, string $parameterId): void { |
|
657 | + if (!($dataValue instanceof MonolingualTextValue)) { |
|
658 | 658 | throw new ConstraintParameterException( |
659 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-monolingualtext' ) ) |
|
660 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
661 | - ->withDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
659 | + (new ViolationMessage('wbqc-violation-message-parameter-monolingualtext')) |
|
660 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
661 | + ->withDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
662 | 662 | ); |
663 | 663 | } |
664 | 664 | } |
@@ -668,31 +668,31 @@ discard block |
||
668 | 668 | * |
669 | 669 | * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts |
670 | 670 | */ |
671 | - private function parseMultilingualTextParameter( array $snakSerializations, string $parameterId ): MultilingualTextValue { |
|
671 | + private function parseMultilingualTextParameter(array $snakSerializations, string $parameterId): MultilingualTextValue { |
|
672 | 672 | $result = []; |
673 | 673 | |
674 | - foreach ( $snakSerializations as $snakSerialization ) { |
|
675 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
676 | - $this->requireValueParameter( $snak, $parameterId ); |
|
674 | + foreach ($snakSerializations as $snakSerialization) { |
|
675 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
676 | + $this->requireValueParameter($snak, $parameterId); |
|
677 | 677 | |
678 | 678 | $value = $snak->getDataValue(); |
679 | - $this->requireMonolingualTextParameter( $value, $parameterId ); |
|
679 | + $this->requireMonolingualTextParameter($value, $parameterId); |
|
680 | 680 | /** @var MonolingualTextValue $value */ |
681 | 681 | '@phan-var MonolingualTextValue $value'; |
682 | 682 | |
683 | 683 | $code = $value->getLanguageCode(); |
684 | - if ( array_key_exists( $code, $result ) ) { |
|
684 | + if (array_key_exists($code, $result)) { |
|
685 | 685 | throw new ConstraintParameterException( |
686 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-single-per-language' ) ) |
|
687 | - ->withEntityId( new NumericPropertyId( $parameterId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
688 | - ->withLanguage( $code ) |
|
686 | + (new ViolationMessage('wbqc-violation-message-parameter-single-per-language')) |
|
687 | + ->withEntityId(new NumericPropertyId($parameterId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
688 | + ->withLanguage($code) |
|
689 | 689 | ); |
690 | 690 | } |
691 | 691 | |
692 | 692 | $result[$code] = $value; |
693 | 693 | } |
694 | 694 | |
695 | - return new MultilingualTextValue( $result ); |
|
695 | + return new MultilingualTextValue($result); |
|
696 | 696 | } |
697 | 697 | |
698 | 698 | /** |
@@ -700,11 +700,11 @@ discard block |
||
700 | 700 | * @throws ConstraintParameterException if the parameter is invalid |
701 | 701 | * @return MultilingualTextValue |
702 | 702 | */ |
703 | - public function parseSyntaxClarificationParameter( array $constraintParameters ): MultilingualTextValue { |
|
704 | - $syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' ); |
|
703 | + public function parseSyntaxClarificationParameter(array $constraintParameters): MultilingualTextValue { |
|
704 | + $syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId'); |
|
705 | 705 | |
706 | - if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) { |
|
707 | - return new MultilingualTextValue( [] ); |
|
706 | + if (!array_key_exists($syntaxClarificationId, $constraintParameters)) { |
|
707 | + return new MultilingualTextValue([]); |
|
708 | 708 | } |
709 | 709 | |
710 | 710 | $syntaxClarifications = $this->parseMultilingualTextParameter( |
@@ -720,11 +720,11 @@ discard block |
||
720 | 720 | * @throws ConstraintParameterException if the parameter is invalid |
721 | 721 | * @return MultilingualTextValue |
722 | 722 | */ |
723 | - public function parseConstraintClarificationParameter( array $constraintParameters ): MultilingualTextValue { |
|
724 | - $constraintClarificationId = $this->config->get( 'WBQualityConstraintsConstraintClarificationId' ); |
|
723 | + public function parseConstraintClarificationParameter(array $constraintParameters): MultilingualTextValue { |
|
724 | + $constraintClarificationId = $this->config->get('WBQualityConstraintsConstraintClarificationId'); |
|
725 | 725 | |
726 | - if ( !array_key_exists( $constraintClarificationId, $constraintParameters ) ) { |
|
727 | - return new MultilingualTextValue( [] ); |
|
726 | + if (!array_key_exists($constraintClarificationId, $constraintParameters)) { |
|
727 | + return new MultilingualTextValue([]); |
|
728 | 728 | } |
729 | 729 | |
730 | 730 | $constraintClarifications = $this->parseMultilingualTextParameter( |
@@ -757,14 +757,14 @@ discard block |
||
757 | 757 | array $validContextTypes, |
758 | 758 | array $validEntityTypes |
759 | 759 | ): array { |
760 | - $contextTypeParameterId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' ); |
|
760 | + $contextTypeParameterId = $this->config->get('WBQualityConstraintsConstraintScopeId'); |
|
761 | 761 | $contextTypeItemIds = $this->parseItemIdsParameter( |
762 | 762 | $constraintParameters, |
763 | 763 | $constraintTypeItemId, |
764 | 764 | false, |
765 | 765 | $contextTypeParameterId |
766 | 766 | ); |
767 | - $entityTypeParameterId = $this->config->get( 'WBQualityConstraintsConstraintEntityTypesId' ); |
|
767 | + $entityTypeParameterId = $this->config->get('WBQualityConstraintsConstraintEntityTypesId'); |
|
768 | 768 | $entityTypeItemIds = $this->parseItemIdsParameter( |
769 | 769 | $constraintParameters, |
770 | 770 | $constraintTypeItemId, |
@@ -780,26 +780,26 @@ discard block |
||
780 | 780 | $contextTypes = null; |
781 | 781 | $entityTypes = null; |
782 | 782 | |
783 | - if ( $contextTypeParameterId === $entityTypeParameterId ) { |
|
783 | + if ($contextTypeParameterId === $entityTypeParameterId) { |
|
784 | 784 | $itemIds = $contextTypeItemIds; |
785 | 785 | $mapping = $contextTypeMapping + $entityTypeMapping; |
786 | - foreach ( $itemIds as $itemId ) { |
|
787 | - $mapped = $this->mapItemId( $itemId, $mapping, $contextTypeParameterId ); |
|
788 | - if ( in_array( $mapped, $contextTypeMapping, true ) ) { |
|
786 | + foreach ($itemIds as $itemId) { |
|
787 | + $mapped = $this->mapItemId($itemId, $mapping, $contextTypeParameterId); |
|
788 | + if (in_array($mapped, $contextTypeMapping, true)) { |
|
789 | 789 | $contextTypes[] = $mapped; |
790 | 790 | } else { |
791 | 791 | $entityTypes[] = $mapped; |
792 | 792 | } |
793 | 793 | } |
794 | 794 | } else { |
795 | - foreach ( $contextTypeItemIds as $contextTypeItemId ) { |
|
795 | + foreach ($contextTypeItemIds as $contextTypeItemId) { |
|
796 | 796 | $contextTypes[] = $this->mapItemId( |
797 | 797 | $contextTypeItemId, |
798 | 798 | $contextTypeMapping, |
799 | 799 | $contextTypeParameterId |
800 | 800 | ); |
801 | 801 | } |
802 | - foreach ( $entityTypeItemIds as $entityTypeItemId ) { |
|
802 | + foreach ($entityTypeItemIds as $entityTypeItemId) { |
|
803 | 803 | $entityTypes[] = $this->mapItemId( |
804 | 804 | $entityTypeItemId, |
805 | 805 | $entityTypeMapping, |
@@ -808,21 +808,21 @@ discard block |
||
808 | 808 | } |
809 | 809 | } |
810 | 810 | |
811 | - $this->checkValidScope( $constraintTypeItemId, $contextTypes, $validContextTypes ); |
|
812 | - $this->checkValidScope( $constraintTypeItemId, $entityTypes, $validEntityTypes ); |
|
811 | + $this->checkValidScope($constraintTypeItemId, $contextTypes, $validContextTypes); |
|
812 | + $this->checkValidScope($constraintTypeItemId, $entityTypes, $validEntityTypes); |
|
813 | 813 | |
814 | - return [ $contextTypes, $entityTypes ]; |
|
814 | + return [$contextTypes, $entityTypes]; |
|
815 | 815 | } |
816 | 816 | |
817 | - private function checkValidScope( string $constraintTypeItemId, ?array $types, array $validTypes ): void { |
|
818 | - $invalidTypes = array_diff( $types ?: [], $validTypes ); |
|
819 | - if ( $invalidTypes !== [] ) { |
|
820 | - $invalidType = array_pop( $invalidTypes ); |
|
817 | + private function checkValidScope(string $constraintTypeItemId, ?array $types, array $validTypes): void { |
|
818 | + $invalidTypes = array_diff($types ?: [], $validTypes); |
|
819 | + if ($invalidTypes !== []) { |
|
820 | + $invalidType = array_pop($invalidTypes); |
|
821 | 821 | throw new ConstraintParameterException( |
822 | - ( new ViolationMessage( 'wbqc-violation-message-invalid-scope' ) ) |
|
823 | - ->withConstraintScope( $invalidType, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
824 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
825 | - ->withConstraintScopeList( $validTypes, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
822 | + (new ViolationMessage('wbqc-violation-message-invalid-scope')) |
|
823 | + ->withConstraintScope($invalidType, Role::CONSTRAINT_PARAMETER_VALUE) |
|
824 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
825 | + ->withConstraintScopeList($validTypes, Role::CONSTRAINT_PARAMETER_VALUE) |
|
826 | 826 | ); |
827 | 827 | } |
828 | 828 | } |
@@ -830,8 +830,8 @@ discard block |
||
830 | 830 | /** |
831 | 831 | * Turn an item ID into a full unit string (using the concept URI). |
832 | 832 | */ |
833 | - private function parseUnitParameter( ItemId $unitId ): string { |
|
834 | - return $this->unitItemConceptBaseUri . $unitId->getSerialization(); |
|
833 | + private function parseUnitParameter(ItemId $unitId): string { |
|
834 | + return $this->unitItemConceptBaseUri.$unitId->getSerialization(); |
|
835 | 835 | } |
836 | 836 | |
837 | 837 | /** |
@@ -839,23 +839,23 @@ discard block |
||
839 | 839 | * |
840 | 840 | * @throws ConstraintParameterException |
841 | 841 | */ |
842 | - private function parseUnitItem( ItemIdSnakValue $item ): UnitsParameter { |
|
843 | - switch ( true ) { |
|
842 | + private function parseUnitItem(ItemIdSnakValue $item): UnitsParameter { |
|
843 | + switch (true) { |
|
844 | 844 | case $item->isValue(): |
845 | - $unit = $this->parseUnitParameter( $item->getItemId() ); |
|
845 | + $unit = $this->parseUnitParameter($item->getItemId()); |
|
846 | 846 | return new UnitsParameter( |
847 | - [ $item->getItemId() ], |
|
848 | - [ UnboundedQuantityValue::newFromNumber( 1, $unit ) ], |
|
847 | + [$item->getItemId()], |
|
848 | + [UnboundedQuantityValue::newFromNumber(1, $unit)], |
|
849 | 849 | false |
850 | 850 | ); |
851 | 851 | case $item->isSomeValue(): |
852 | - $qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
852 | + $qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
853 | 853 | throw new ConstraintParameterException( |
854 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) ) |
|
855 | - ->withEntityId( new NumericPropertyId( $qualifierId ), Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
854 | + (new ViolationMessage('wbqc-violation-message-parameter-value-or-novalue')) |
|
855 | + ->withEntityId(new NumericPropertyId($qualifierId), Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
856 | 856 | ); |
857 | 857 | case $item->isNoValue(): |
858 | - return new UnitsParameter( [], [], true ); |
|
858 | + return new UnitsParameter([], [], true); |
|
859 | 859 | } |
860 | 860 | } |
861 | 861 | |
@@ -865,36 +865,36 @@ discard block |
||
865 | 865 | * @throws ConstraintParameterException if the parameter is invalid or missing |
866 | 866 | * @return UnitsParameter |
867 | 867 | */ |
868 | - public function parseUnitsParameter( array $constraintParameters, string $constraintTypeItemId ): UnitsParameter { |
|
869 | - $items = $this->parseItemsParameter( $constraintParameters, $constraintTypeItemId, true ); |
|
868 | + public function parseUnitsParameter(array $constraintParameters, string $constraintTypeItemId): UnitsParameter { |
|
869 | + $items = $this->parseItemsParameter($constraintParameters, $constraintTypeItemId, true); |
|
870 | 870 | $unitItems = []; |
871 | 871 | $unitQuantities = []; |
872 | 872 | $unitlessAllowed = false; |
873 | 873 | |
874 | - foreach ( $items as $item ) { |
|
875 | - $unit = $this->parseUnitItem( $item ); |
|
876 | - $unitItems = array_merge( $unitItems, $unit->getUnitItemIds() ); |
|
877 | - $unitQuantities = array_merge( $unitQuantities, $unit->getUnitQuantities() ); |
|
874 | + foreach ($items as $item) { |
|
875 | + $unit = $this->parseUnitItem($item); |
|
876 | + $unitItems = array_merge($unitItems, $unit->getUnitItemIds()); |
|
877 | + $unitQuantities = array_merge($unitQuantities, $unit->getUnitQuantities()); |
|
878 | 878 | $unitlessAllowed = $unitlessAllowed || $unit->getUnitlessAllowed(); |
879 | 879 | } |
880 | 880 | |
881 | - if ( $unitQuantities === [] && !$unitlessAllowed ) { |
|
881 | + if ($unitQuantities === [] && !$unitlessAllowed) { |
|
882 | 882 | throw new LogicException( |
883 | 883 | 'The "units" parameter is required, and yet we seem to be missing any allowed unit' |
884 | 884 | ); |
885 | 885 | } |
886 | 886 | |
887 | - return new UnitsParameter( $unitItems, $unitQuantities, $unitlessAllowed ); |
|
887 | + return new UnitsParameter($unitItems, $unitQuantities, $unitlessAllowed); |
|
888 | 888 | } |
889 | 889 | |
890 | 890 | private function getEntityTypeMapping(): array { |
891 | 891 | return [ |
892 | - $this->config->get( 'WBQualityConstraintsWikibaseItemId' ) => 'item', |
|
893 | - $this->config->get( 'WBQualityConstraintsWikibasePropertyId' ) => 'property', |
|
894 | - $this->config->get( 'WBQualityConstraintsWikibaseLexemeId' ) => 'lexeme', |
|
895 | - $this->config->get( 'WBQualityConstraintsWikibaseFormId' ) => 'form', |
|
896 | - $this->config->get( 'WBQualityConstraintsWikibaseSenseId' ) => 'sense', |
|
897 | - $this->config->get( 'WBQualityConstraintsWikibaseMediaInfoId' ) => 'mediainfo', |
|
892 | + $this->config->get('WBQualityConstraintsWikibaseItemId') => 'item', |
|
893 | + $this->config->get('WBQualityConstraintsWikibasePropertyId') => 'property', |
|
894 | + $this->config->get('WBQualityConstraintsWikibaseLexemeId') => 'lexeme', |
|
895 | + $this->config->get('WBQualityConstraintsWikibaseFormId') => 'form', |
|
896 | + $this->config->get('WBQualityConstraintsWikibaseSenseId') => 'sense', |
|
897 | + $this->config->get('WBQualityConstraintsWikibaseMediaInfoId') => 'mediainfo', |
|
898 | 898 | ]; |
899 | 899 | } |
900 | 900 | |
@@ -904,10 +904,10 @@ discard block |
||
904 | 904 | * @throws ConstraintParameterException if the parameter is invalid or missing |
905 | 905 | * @return EntityTypesParameter |
906 | 906 | */ |
907 | - public function parseEntityTypesParameter( array $constraintParameters, string $constraintTypeItemId ): EntityTypesParameter { |
|
907 | + public function parseEntityTypesParameter(array $constraintParameters, string $constraintTypeItemId): EntityTypesParameter { |
|
908 | 908 | $entityTypes = []; |
909 | 909 | $entityTypeItemIds = []; |
910 | - $parameterId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
910 | + $parameterId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
911 | 911 | $itemIds = $this->parseItemIdsParameter( |
912 | 912 | $constraintParameters, |
913 | 913 | $constraintTypeItemId, |
@@ -916,22 +916,22 @@ discard block |
||
916 | 916 | ); |
917 | 917 | |
918 | 918 | $mapping = $this->getEntityTypeMapping(); |
919 | - foreach ( $itemIds as $itemId ) { |
|
920 | - $entityType = $this->mapItemId( $itemId, $mapping, $parameterId ); |
|
919 | + foreach ($itemIds as $itemId) { |
|
920 | + $entityType = $this->mapItemId($itemId, $mapping, $parameterId); |
|
921 | 921 | $entityTypes[] = $entityType; |
922 | 922 | $entityTypeItemIds[] = $itemId; |
923 | 923 | } |
924 | 924 | |
925 | - if ( $entityTypes === [] ) { |
|
925 | + if ($entityTypes === []) { |
|
926 | 926 | // @codeCoverageIgnoreStart |
927 | 927 | throw new LogicException( |
928 | - 'The "entity types" parameter is required, ' . |
|
928 | + 'The "entity types" parameter is required, '. |
|
929 | 929 | 'and yet we seem to be missing any allowed entity type' |
930 | 930 | ); |
931 | 931 | // @codeCoverageIgnoreEnd |
932 | 932 | } |
933 | 933 | |
934 | - return new EntityTypesParameter( $entityTypes, $entityTypeItemIds ); |
|
934 | + return new EntityTypesParameter($entityTypes, $entityTypeItemIds); |
|
935 | 935 | } |
936 | 936 | |
937 | 937 | /** |
@@ -939,18 +939,18 @@ discard block |
||
939 | 939 | * @throws ConstraintParameterException if the parameter is invalid |
940 | 940 | * @return PropertyId[] |
941 | 941 | */ |
942 | - public function parseSeparatorsParameter( array $constraintParameters ): array { |
|
943 | - $separatorId = $this->config->get( 'WBQualityConstraintsSeparatorId' ); |
|
942 | + public function parseSeparatorsParameter(array $constraintParameters): array { |
|
943 | + $separatorId = $this->config->get('WBQualityConstraintsSeparatorId'); |
|
944 | 944 | |
945 | - if ( !array_key_exists( $separatorId, $constraintParameters ) ) { |
|
945 | + if (!array_key_exists($separatorId, $constraintParameters)) { |
|
946 | 946 | return []; |
947 | 947 | } |
948 | 948 | |
949 | 949 | $parameters = $constraintParameters[$separatorId]; |
950 | 950 | $separators = []; |
951 | 951 | |
952 | - foreach ( $parameters as $parameter ) { |
|
953 | - $separators[] = $this->parsePropertyIdParameter( $parameter, $separatorId ); |
|
952 | + foreach ($parameters as $parameter) { |
|
953 | + $separators[] = $this->parsePropertyIdParameter($parameter, $separatorId); |
|
954 | 954 | } |
955 | 955 | |
956 | 956 | return $separators; |
@@ -958,17 +958,17 @@ discard block |
||
958 | 958 | |
959 | 959 | private function getConstraintScopeContextTypeMapping(): array { |
960 | 960 | return [ |
961 | - $this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' ) => Context::TYPE_STATEMENT, |
|
962 | - $this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' ) => Context::TYPE_QUALIFIER, |
|
963 | - $this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' ) => Context::TYPE_REFERENCE, |
|
961 | + $this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId') => Context::TYPE_STATEMENT, |
|
962 | + $this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId') => Context::TYPE_QUALIFIER, |
|
963 | + $this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId') => Context::TYPE_REFERENCE, |
|
964 | 964 | ]; |
965 | 965 | } |
966 | 966 | |
967 | 967 | private function getPropertyScopeContextTypeMapping(): array { |
968 | 968 | return [ |
969 | - $this->config->get( 'WBQualityConstraintsAsMainValueId' ) => Context::TYPE_STATEMENT, |
|
970 | - $this->config->get( 'WBQualityConstraintsAsQualifiersId' ) => Context::TYPE_QUALIFIER, |
|
971 | - $this->config->get( 'WBQualityConstraintsAsReferencesId' ) => Context::TYPE_REFERENCE, |
|
969 | + $this->config->get('WBQualityConstraintsAsMainValueId') => Context::TYPE_STATEMENT, |
|
970 | + $this->config->get('WBQualityConstraintsAsQualifiersId') => Context::TYPE_QUALIFIER, |
|
971 | + $this->config->get('WBQualityConstraintsAsReferencesId') => Context::TYPE_REFERENCE, |
|
972 | 972 | ]; |
973 | 973 | } |
974 | 974 | |
@@ -978,9 +978,9 @@ discard block |
||
978 | 978 | * @throws ConstraintParameterException if the parameter is invalid or missing |
979 | 979 | * @return string[] list of Context::TYPE_* constants |
980 | 980 | */ |
981 | - public function parsePropertyScopeParameter( array $constraintParameters, string $constraintTypeItemId ): array { |
|
981 | + public function parsePropertyScopeParameter(array $constraintParameters, string $constraintTypeItemId): array { |
|
982 | 982 | $contextTypes = []; |
983 | - $parameterId = $this->config->get( 'WBQualityConstraintsPropertyScopeId' ); |
|
983 | + $parameterId = $this->config->get('WBQualityConstraintsPropertyScopeId'); |
|
984 | 984 | $itemIds = $this->parseItemIdsParameter( |
985 | 985 | $constraintParameters, |
986 | 986 | $constraintTypeItemId, |
@@ -989,14 +989,14 @@ discard block |
||
989 | 989 | ); |
990 | 990 | |
991 | 991 | $mapping = $this->getPropertyScopeContextTypeMapping(); |
992 | - foreach ( $itemIds as $itemId ) { |
|
993 | - $contextTypes[] = $this->mapItemId( $itemId, $mapping, $parameterId ); |
|
992 | + foreach ($itemIds as $itemId) { |
|
993 | + $contextTypes[] = $this->mapItemId($itemId, $mapping, $parameterId); |
|
994 | 994 | } |
995 | 995 | |
996 | - if ( $contextTypes === [] ) { |
|
996 | + if ($contextTypes === []) { |
|
997 | 997 | // @codeCoverageIgnoreStart |
998 | 998 | throw new LogicException( |
999 | - 'The "property scope" parameter is required, ' . |
|
999 | + 'The "property scope" parameter is required, '. |
|
1000 | 1000 | 'and yet we seem to be missing any allowed scope' |
1001 | 1001 | ); |
1002 | 1002 | // @codeCoverageIgnoreEnd |
@@ -16,27 +16,27 @@ |
||
16 | 16 | */ |
17 | 17 | private $timeValueCalculator; |
18 | 18 | |
19 | - public function __construct( ?TimeValueCalculator $timeValueCalculator = null ) { |
|
19 | + public function __construct(?TimeValueCalculator $timeValueCalculator = null) { |
|
20 | 20 | $this->timeValueCalculator = $timeValueCalculator ?: new TimeValueCalculator(); |
21 | 21 | } |
22 | 22 | |
23 | - public function getComparison( TimeValue $lhs, TimeValue $rhs ) { |
|
24 | - $lhsTimestamp = $this->timeValueCalculator->getTimestamp( $lhs ); |
|
25 | - $rhsTimestamp = $this->timeValueCalculator->getTimestamp( $rhs ); |
|
23 | + public function getComparison(TimeValue $lhs, TimeValue $rhs) { |
|
24 | + $lhsTimestamp = $this->timeValueCalculator->getTimestamp($lhs); |
|
25 | + $rhsTimestamp = $this->timeValueCalculator->getTimestamp($rhs); |
|
26 | 26 | |
27 | - if ( $lhsTimestamp === $rhsTimestamp ) { |
|
27 | + if ($lhsTimestamp === $rhsTimestamp) { |
|
28 | 28 | return 0; |
29 | 29 | } |
30 | 30 | |
31 | 31 | return $lhsTimestamp < $rhsTimestamp ? -1 : 1; |
32 | 32 | } |
33 | 33 | |
34 | - public function getMinimum( TimeValue $timeValue1, TimeValue $timeValue2 ) { |
|
35 | - return $this->getComparison( $timeValue1, $timeValue2 ) <= 0 ? $timeValue1 : $timeValue2; |
|
34 | + public function getMinimum(TimeValue $timeValue1, TimeValue $timeValue2) { |
|
35 | + return $this->getComparison($timeValue1, $timeValue2) <= 0 ? $timeValue1 : $timeValue2; |
|
36 | 36 | } |
37 | 37 | |
38 | - public function isFutureTime( TimeValue $timeValue ) { |
|
39 | - return $this->getComparison( $timeValue, new NowValue() ) >= 0; |
|
38 | + public function isFutureTime(TimeValue $timeValue) { |
|
39 | + return $this->getComparison($timeValue, new NowValue()) >= 0; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Cache; |
6 | 6 | |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | * @param int $maxAge The maximum age of the cached value (in seconds). |
32 | 32 | * @return self Indication that a value is possibly outdated by up to this many seconds. |
33 | 33 | */ |
34 | - public static function ofMaximumAgeInSeconds( int $maxAge ): self { |
|
35 | - Assert::parameter( $maxAge > 0, '$maxAge', '$maxage > 0' ); |
|
34 | + public static function ofMaximumAgeInSeconds(int $maxAge): self { |
|
35 | + Assert::parameter($maxAge > 0, '$maxAge', '$maxage > 0'); |
|
36 | 36 | $ret = new self; |
37 | 37 | $ret->maxAge = $maxAge; |
38 | 38 | return $ret; |
@@ -43,9 +43,9 @@ discard block |
||
43 | 43 | * @param array|null $array As returned by toArray. |
44 | 44 | * @return self |
45 | 45 | */ |
46 | - public static function ofArray( ?array $array = null ): self { |
|
46 | + public static function ofArray(?array $array = null): self { |
|
47 | 47 | $ret = new self; |
48 | - if ( $array !== null ) { |
|
48 | + if ($array !== null) { |
|
49 | 49 | $ret->maxAge = $array['maximumAgeInSeconds']; |
50 | 50 | } |
51 | 51 | return $ret; |
@@ -55,11 +55,11 @@ discard block |
||
55 | 55 | * @param self[] $metadatas |
56 | 56 | * @return self |
57 | 57 | */ |
58 | - public static function merge( array $metadatas ): self { |
|
59 | - Assert::parameterElementType( self::class, $metadatas, '$metadatas' ); |
|
58 | + public static function merge(array $metadatas): self { |
|
59 | + Assert::parameterElementType(self::class, $metadatas, '$metadatas'); |
|
60 | 60 | $ret = new self; |
61 | - foreach ( $metadatas as $metadata ) { |
|
62 | - $ret->maxAge = max( $ret->maxAge, $metadata->maxAge ); |
|
61 | + foreach ($metadatas as $metadata) { |
|
62 | + $ret->maxAge = max($ret->maxAge, $metadata->maxAge); |
|
63 | 63 | } |
64 | 64 | return $ret; |
65 | 65 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * For a fresh value, returns 0. |
78 | 78 | */ |
79 | 79 | public function getMaximumAgeInSeconds(): int { |
80 | - if ( is_int( $this->maxAge ) ) { |
|
80 | + if (is_int($this->maxAge)) { |
|
81 | 81 | return $this->maxAge; |
82 | 82 | } else { |
83 | 83 | return 0; |
@@ -92,8 +92,7 @@ discard block |
||
92 | 92 | return $this->isCached() ? |
93 | 93 | [ |
94 | 94 | 'maximumAgeInSeconds' => $this->maxAge, |
95 | - ] : |
|
96 | - null; |
|
95 | + ] : null; |
|
97 | 96 | } |
98 | 97 | |
99 | 98 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @param EntityId $entityId An entity ID from which the value was derived. |
38 | 38 | * @return self Indication that a value was derived from the entity with the given ID. |
39 | 39 | */ |
40 | - public static function ofEntityId( EntityId $entityId ) { |
|
40 | + public static function ofEntityId(EntityId $entityId) { |
|
41 | 41 | $ret = new self; |
42 | 42 | $ret->entityIds[] = $entityId; |
43 | 43 | return $ret; |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @return self Indication that a value will only remain valid |
50 | 50 | * as long as the given time value is in the future, not in the past. |
51 | 51 | */ |
52 | - public static function ofFutureTime( TimeValue $timeValue ) { |
|
52 | + public static function ofFutureTime(TimeValue $timeValue) { |
|
53 | 53 | $ret = new self; |
54 | 54 | $ret->timeValue = $timeValue; |
55 | 55 | return $ret; |
@@ -59,17 +59,17 @@ discard block |
||
59 | 59 | * @param self[] $metadatas |
60 | 60 | * @return self |
61 | 61 | */ |
62 | - public static function merge( array $metadatas ) { |
|
63 | - Assert::parameterElementType( self::class, $metadatas, '$metadatas' ); |
|
62 | + public static function merge(array $metadatas) { |
|
63 | + Assert::parameterElementType(self::class, $metadatas, '$metadatas'); |
|
64 | 64 | $ret = new self; |
65 | 65 | $entityIds = []; |
66 | - foreach ( $metadatas as $metadata ) { |
|
67 | - foreach ( $metadata->entityIds as $entityId ) { |
|
66 | + foreach ($metadatas as $metadata) { |
|
67 | + foreach ($metadata->entityIds as $entityId) { |
|
68 | 68 | $entityIds[$entityId->getSerialization()] = $entityId; |
69 | 69 | } |
70 | - $ret->timeValue = self::minTimeValue( $ret->timeValue, $metadata->timeValue ); |
|
70 | + $ret->timeValue = self::minTimeValue($ret->timeValue, $metadata->timeValue); |
|
71 | 71 | } |
72 | - $ret->entityIds = array_values( $entityIds ); |
|
72 | + $ret->entityIds = array_values($entityIds); |
|
73 | 73 | return $ret; |
74 | 74 | } |
75 | 75 | |
@@ -78,14 +78,14 @@ discard block |
||
78 | 78 | * @param TimeValue|null $t2 |
79 | 79 | * @return TimeValue|null |
80 | 80 | */ |
81 | - private static function minTimeValue( ?TimeValue $t1 = null, ?TimeValue $t2 = null ) { |
|
82 | - if ( $t1 === null ) { |
|
81 | + private static function minTimeValue(?TimeValue $t1 = null, ?TimeValue $t2 = null) { |
|
82 | + if ($t1 === null) { |
|
83 | 83 | return $t2; |
84 | 84 | } |
85 | - if ( $t2 === null ) { |
|
85 | + if ($t2 === null) { |
|
86 | 86 | return $t1; |
87 | 87 | } |
88 | - return ( new TimeValueComparer() )->getMinimum( $t1, $t2 ); |
|
88 | + return (new TimeValueComparer())->getMinimum($t1, $t2); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Result; |
6 | 6 | |
@@ -108,12 +108,12 @@ discard block |
||
108 | 108 | string $status = self::STATUS_TODO, |
109 | 109 | ?ViolationMessage $message = null |
110 | 110 | ) { |
111 | - if ( $contextCursor instanceof Context ) { |
|
111 | + if ($contextCursor instanceof Context) { |
|
112 | 112 | $context = $contextCursor; |
113 | 113 | $this->contextCursor = $context->getCursor(); |
114 | 114 | $this->snakType = $context->getSnak()->getType(); |
115 | 115 | $mainSnak = $context->getSnak(); |
116 | - if ( $mainSnak instanceof PropertyValueSnak ) { |
|
116 | + if ($mainSnak instanceof PropertyValueSnak) { |
|
117 | 117 | $this->dataValue = $mainSnak->getDataValue(); |
118 | 118 | } else { |
119 | 119 | $this->dataValue = null; |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | $this->status = $status; |
128 | 128 | $this->message = $message; |
129 | 129 | $this->metadata = Metadata::blank(); |
130 | - $this->constraintClarification = new MultilingualTextValue( [] ); |
|
130 | + $this->constraintClarification = new MultilingualTextValue([]); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | public function getContextCursor(): ContextCursor { |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | return $this->status; |
164 | 164 | } |
165 | 165 | |
166 | - public function setStatus( string $status ): void { |
|
166 | + public function setStatus(string $status): void { |
|
167 | 167 | $this->status = $status; |
168 | 168 | } |
169 | 169 | |
@@ -171,11 +171,11 @@ discard block |
||
171 | 171 | return $this->message; |
172 | 172 | } |
173 | 173 | |
174 | - public function setMessage( ?ViolationMessage $message ) { |
|
174 | + public function setMessage(?ViolationMessage $message) { |
|
175 | 175 | $this->message = $message; |
176 | 176 | } |
177 | 177 | |
178 | - public function withMetadata( Metadata $metadata ): self { |
|
178 | + public function withMetadata(Metadata $metadata): self { |
|
179 | 179 | $this->metadata = $metadata; |
180 | 180 | return $this; |
181 | 181 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | return $this->constraintClarification; |
189 | 189 | } |
190 | 190 | |
191 | - public function setConstraintClarification( MultilingualTextValue $constraintClarification ) { |
|
191 | + public function setConstraintClarification(MultilingualTextValue $constraintClarification) { |
|
192 | 192 | $this->constraintClarification = $constraintClarification; |
193 | 193 | } |
194 | 194 |