@@ -77,21 +77,21 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @return self |
79 | 79 | */ |
80 | - public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) { |
|
80 | + public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') { |
|
81 | 81 | $repo = WikibaseRepo::getDefaultInstance(); |
82 | 82 | |
83 | 83 | $language = $repo->getUserLanguage(); |
84 | 84 | $formatterOptions = new FormatterOptions(); |
85 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
85 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
86 | 86 | $valueFormatterFactory = $repo->getValueFormatterFactory(); |
87 | - $valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
87 | + $valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions); |
|
88 | 88 | |
89 | 89 | $languageFallbackLabelDescriptionLookupFactory = $repo->getLanguageFallbackLabelDescriptionLookupFactory(); |
90 | - $labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup( $language ); |
|
90 | + $labelDescriptionLookup = $languageFallbackLabelDescriptionLookupFactory->newLabelDescriptionLookup($language); |
|
91 | 91 | $entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory(); |
92 | - $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup ); |
|
92 | + $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($labelDescriptionLookup); |
|
93 | 93 | $entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory(); |
94 | - $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup ); |
|
94 | + $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($labelDescriptionLookup); |
|
95 | 95 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
96 | 96 | $titleParser = MediaWikiServices::getInstance()->getTitleParser(); |
97 | 97 | $unitConverter = $repo->getUnitConverter(); |
@@ -124,10 +124,10 @@ discard block |
||
124 | 124 | $repo->getEntityTitleLookup(), |
125 | 125 | $entityIdLabelFormatter, |
126 | 126 | $constraintParameterRenderer, |
127 | - new MultilingualTextViolationMessageRenderer( $entityIdHtmlLinkFormatter, $valueFormatter, $config ), |
|
127 | + new MultilingualTextViolationMessageRenderer($entityIdHtmlLinkFormatter, $valueFormatter, $config), |
|
128 | 128 | $config |
129 | 129 | ); |
130 | - if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) { |
|
130 | + if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) { |
|
131 | 131 | $wikiPageEntityMetaDataAccessor = new WikiPageEntityMetaDataLookup( |
132 | 132 | $repo->getEntityNamespaceLookup() |
133 | 133 | ); |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | ResultsCache::getDefaultInstance(), |
139 | 139 | $wikiPageEntityMetaDataAccessor, |
140 | 140 | $entityIdParser, |
141 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ), |
|
141 | + $config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'), |
|
142 | 142 | [ |
143 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ), |
|
144 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ), |
|
145 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ), |
|
146 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ), |
|
143 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId'), |
|
144 | + $config->get('WBQualityConstraintsTypeConstraintId'), |
|
145 | + $config->get('WBQualityConstraintsValueTypeConstraintId'), |
|
146 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId'), |
|
147 | 147 | ], |
148 | 148 | $dataFactory |
149 | 149 | ); |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $prefix, |
156 | 156 | $repo->getEntityIdParser(), |
157 | 157 | $repo->getStatementGuidValidator(), |
158 | - $repo->getApiHelperFactory( RequestContext::getMain() ), |
|
158 | + $repo->getApiHelperFactory(RequestContext::getMain()), |
|
159 | 159 | $resultsBuilder, |
160 | 160 | $dataFactory |
161 | 161 | ); |
@@ -181,11 +181,11 @@ discard block |
||
181 | 181 | ResultsBuilder $resultsBuilder, |
182 | 182 | IBufferingStatsdDataFactory $dataFactory |
183 | 183 | ) { |
184 | - parent::__construct( $main, $name, $prefix ); |
|
184 | + parent::__construct($main, $name, $prefix); |
|
185 | 185 | $this->entityIdParser = $entityIdParser; |
186 | 186 | $this->statementGuidValidator = $statementGuidValidator; |
187 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
188 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
187 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
188 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
189 | 189 | $this->resultsBuilder = $resultsBuilder; |
190 | 190 | $this->dataFactory = $dataFactory; |
191 | 191 | } |
@@ -200,9 +200,9 @@ discard block |
||
200 | 200 | |
201 | 201 | $params = $this->extractRequestParams(); |
202 | 202 | |
203 | - $this->validateParameters( $params ); |
|
204 | - $entityIds = $this->parseEntityIds( $params ); |
|
205 | - $claimIds = $this->parseClaimIds( $params ); |
|
203 | + $this->validateParameters($params); |
|
204 | + $entityIds = $this->parseEntityIds($params); |
|
205 | + $claimIds = $this->parseClaimIds($params); |
|
206 | 206 | $constraintIDs = $params[self::PARAM_CONSTRAINT_ID]; |
207 | 207 | $statuses = $params[self::PARAM_STATUS]; |
208 | 208 | |
@@ -217,13 +217,13 @@ discard block |
||
217 | 217 | )->getArray() |
218 | 218 | ); |
219 | 219 | // ensure that result contains the given entity IDs even if they have no statements |
220 | - foreach ( $entityIds as $entityId ) { |
|
220 | + foreach ($entityIds as $entityId) { |
|
221 | 221 | $this->getResult()->addArrayType( |
222 | - [ $this->getModuleName(), $entityId->getSerialization() ], |
|
222 | + [$this->getModuleName(), $entityId->getSerialization()], |
|
223 | 223 | 'assoc' |
224 | 224 | ); |
225 | 225 | } |
226 | - $this->resultBuilder->markSuccess( 1 ); |
|
226 | + $this->resultBuilder->markSuccess(1); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -231,24 +231,24 @@ discard block |
||
231 | 231 | * |
232 | 232 | * @return EntityId[] |
233 | 233 | */ |
234 | - private function parseEntityIds( array $params ) { |
|
234 | + private function parseEntityIds(array $params) { |
|
235 | 235 | $ids = $params[self::PARAM_ID]; |
236 | 236 | |
237 | - if ( $ids === null ) { |
|
237 | + if ($ids === null) { |
|
238 | 238 | return []; |
239 | - } elseif ( $ids === [] ) { |
|
239 | + } elseif ($ids === []) { |
|
240 | 240 | $this->errorReporter->dieError( |
241 | - 'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
241 | + 'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
242 | 242 | } |
243 | 243 | |
244 | - return array_map( function ( $id ) { |
|
244 | + return array_map(function($id) { |
|
245 | 245 | try { |
246 | - return $this->entityIdParser->parse( $id ); |
|
247 | - } catch ( EntityIdParsingException $e ) { |
|
246 | + return $this->entityIdParser->parse($id); |
|
247 | + } catch (EntityIdParsingException $e) { |
|
248 | 248 | $this->errorReporter->dieError( |
249 | - "Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] ); |
|
249 | + "Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] ); |
|
250 | 250 | } |
251 | - }, $ids ); |
|
251 | + }, $ids); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
@@ -256,35 +256,35 @@ discard block |
||
256 | 256 | * |
257 | 257 | * @return string[] |
258 | 258 | */ |
259 | - private function parseClaimIds( array $params ) { |
|
259 | + private function parseClaimIds(array $params) { |
|
260 | 260 | $ids = $params[self::PARAM_CLAIM_ID]; |
261 | 261 | |
262 | - if ( $ids === null ) { |
|
262 | + if ($ids === null) { |
|
263 | 263 | return []; |
264 | - } elseif ( $ids === [] ) { |
|
264 | + } elseif ($ids === []) { |
|
265 | 265 | $this->errorReporter->dieError( |
266 | - 'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
266 | + 'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
267 | 267 | } |
268 | 268 | |
269 | - foreach ( $ids as $id ) { |
|
270 | - if ( !$this->statementGuidValidator->validate( $id ) ) { |
|
269 | + foreach ($ids as $id) { |
|
270 | + if (!$this->statementGuidValidator->validate($id)) { |
|
271 | 271 | $this->errorReporter->dieError( |
272 | - "Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] ); |
|
272 | + "Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] ); |
|
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
276 | 276 | return $ids; |
277 | 277 | } |
278 | 278 | |
279 | - private function validateParameters( array $params ) { |
|
280 | - if ( $params[self::PARAM_CONSTRAINT_ID] !== null |
|
281 | - && empty( $params[self::PARAM_CONSTRAINT_ID] ) |
|
279 | + private function validateParameters(array $params) { |
|
280 | + if ($params[self::PARAM_CONSTRAINT_ID] !== null |
|
281 | + && empty($params[self::PARAM_CONSTRAINT_ID]) |
|
282 | 282 | ) { |
283 | 283 | $paramConstraintId = self::PARAM_CONSTRAINT_ID; |
284 | 284 | $this->errorReporter->dieError( |
285 | 285 | "If $paramConstraintId is specified, it must be nonempty.", 'no-data' ); |
286 | 286 | } |
287 | - if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) { |
|
287 | + if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) { |
|
288 | 288 | $paramId = self::PARAM_ID; |
289 | 289 | $paramClaimId = self::PARAM_CLAIM_ID; |
290 | 290 | $this->errorReporter->dieError( |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | * @throws ConstraintParameterException |
94 | 94 | * @return CheckResult |
95 | 95 | */ |
96 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
96 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
97 | 97 | $parameters = []; |
98 | 98 | $constraintParameters = $constraint->getConstraintParameters(); |
99 | 99 | |
100 | - $format = $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
101 | - $parameters['pattern'] = [ $format ]; |
|
100 | + $format = $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
101 | + $parameters['pattern'] = [$format]; |
|
102 | 102 | |
103 | 103 | $syntaxClarifications = $this->constraintParameterParser->parseSyntaxClarificationParameter( |
104 | 104 | $constraintParameters |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | |
107 | 107 | $snak = $context->getSnak(); |
108 | 108 | |
109 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
109 | + if (!$snak instanceof PropertyValueSnak) { |
|
110 | 110 | // nothing to check |
111 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
111 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | $dataValue = $snak->getDataValue(); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * error handling: |
118 | 118 | * type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext' |
119 | 119 | */ |
120 | - switch ( $dataValue->getType() ) { |
|
120 | + switch ($dataValue->getType()) { |
|
121 | 121 | case 'string': |
122 | 122 | $text = $dataValue->getValue(); |
123 | 123 | break; |
@@ -126,46 +126,46 @@ discard block |
||
126 | 126 | $text = $dataValue->getText(); |
127 | 127 | break; |
128 | 128 | default: |
129 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-types-2' ) ) |
|
130 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ) |
|
131 | - ->withDataValueType( 'string' ) |
|
132 | - ->withDataValueType( 'monolingualtext' ); |
|
133 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
129 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-types-2')) |
|
130 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM) |
|
131 | + ->withDataValueType('string') |
|
132 | + ->withDataValueType('monolingualtext'); |
|
133 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
134 | 134 | } |
135 | 135 | |
136 | - if ( $this->sparqlHelper !== null && $this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) ) { |
|
137 | - if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) { |
|
136 | + if ($this->sparqlHelper !== null && $this->config->get('WBQualityConstraintsCheckFormatConstraint')) { |
|
137 | + if ($this->sparqlHelper->matchesRegularExpression($text, $format)) { |
|
138 | 138 | $message = null; |
139 | 139 | $status = CheckResult::STATUS_COMPLIANCE; |
140 | 140 | } else { |
141 | - $message = ( new ViolationMessage( 'wbqc-violation-message-format-clarification' ) ) |
|
142 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY ) |
|
143 | - ->withDataValue( new StringValue( $text ), Role::OBJECT ) |
|
144 | - ->withInlineCode( $format, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
145 | - ->withMultilingualText( $syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE ); |
|
141 | + $message = (new ViolationMessage('wbqc-violation-message-format-clarification')) |
|
142 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::CONSTRAINT_PROPERTY) |
|
143 | + ->withDataValue(new StringValue($text), Role::OBJECT) |
|
144 | + ->withInlineCode($format, Role::CONSTRAINT_PARAMETER_VALUE) |
|
145 | + ->withMultilingualText($syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE); |
|
146 | 146 | $status = CheckResult::STATUS_VIOLATION; |
147 | 147 | } |
148 | 148 | } else { |
149 | - $message = ( new ViolationMessage( 'wbqc-violation-message-security-reason' ) ) |
|
150 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ); |
|
149 | + $message = (new ViolationMessage('wbqc-violation-message-security-reason')) |
|
150 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM); |
|
151 | 151 | $status = CheckResult::STATUS_TODO; |
152 | 152 | } |
153 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
153 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
154 | 154 | } |
155 | 155 | |
156 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
156 | + public function checkConstraintParameters(Constraint $constraint) { |
|
157 | 157 | $constraintParameters = $constraint->getConstraintParameters(); |
158 | 158 | $exceptions = []; |
159 | 159 | try { |
160 | - $this->constraintParameterParser->parseFormatParameter( $constraintParameters, $constraint->getConstraintTypeItemId() ); |
|
161 | - } catch ( ConstraintParameterException $e ) { |
|
160 | + $this->constraintParameterParser->parseFormatParameter($constraintParameters, $constraint->getConstraintTypeItemId()); |
|
161 | + } catch (ConstraintParameterException $e) { |
|
162 | 162 | $exceptions[] = $e; |
163 | 163 | } |
164 | 164 | try { |
165 | 165 | $this->constraintParameterParser->parseSyntaxClarificationParameter( |
166 | 166 | $constraintParameters |
167 | 167 | ); |
168 | - } catch ( ConstraintParameterException $e ) { |
|
168 | + } catch (ConstraintParameterException $e) { |
|
169 | 169 | $exceptions[] = $e; |
170 | 170 | } |
171 | 171 | return $exceptions; |
@@ -16,6 +16,9 @@ |
||
16 | 16 | */ |
17 | 17 | class ViolationMessageSerializer implements Serializer { |
18 | 18 | |
19 | + /** |
|
20 | + * @param string $fullMessageKey |
|
21 | + */ |
|
19 | 22 | private function abbreviateViolationMessageKey( $fullMessageKey ) { |
20 | 23 | return substr( $fullMessageKey, strlen( ViolationMessage::MESSAGE_KEY_PREFIX ) ); |
21 | 24 | } |
@@ -19,26 +19,26 @@ discard block |
||
19 | 19 | */ |
20 | 20 | class ViolationMessageSerializer implements Serializer { |
21 | 21 | |
22 | - private function abbreviateViolationMessageKey( $fullMessageKey ) { |
|
23 | - return substr( $fullMessageKey, strlen( ViolationMessage::MESSAGE_KEY_PREFIX ) ); |
|
22 | + private function abbreviateViolationMessageKey($fullMessageKey) { |
|
23 | + return substr($fullMessageKey, strlen(ViolationMessage::MESSAGE_KEY_PREFIX)); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @param ViolationMessage $object |
28 | 28 | * @return array |
29 | 29 | */ |
30 | - public function serialize( $object ) { |
|
30 | + public function serialize($object) { |
|
31 | 31 | /** @var ViolationMessage $object */ |
32 | - Assert::parameterType( ViolationMessage::class, $object, '$object' ); |
|
32 | + Assert::parameterType(ViolationMessage::class, $object, '$object'); |
|
33 | 33 | |
34 | 34 | $arguments = $object->getArguments(); |
35 | 35 | $serializedArguments = []; |
36 | - foreach ( $arguments as $argument ) { |
|
37 | - $serializedArguments[] = $this->serializeArgument( $argument ); |
|
36 | + foreach ($arguments as $argument) { |
|
37 | + $serializedArguments[] = $this->serializeArgument($argument); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | return [ |
41 | - 'k' => $this->abbreviateViolationMessageKey( $object->getMessageKey() ), |
|
41 | + 'k' => $this->abbreviateViolationMessageKey($object->getMessageKey()), |
|
42 | 42 | 'a' => $serializedArguments, |
43 | 43 | ]; |
44 | 44 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @param array $argument element of ViolationMessage::getArguments() |
48 | 48 | * @return array [ 't' => ViolationMessage::TYPE_*, 'v' => serialized value, 'r' => $role ] |
49 | 49 | */ |
50 | - private function serializeArgument( array $argument ) { |
|
50 | + private function serializeArgument(array $argument) { |
|
51 | 51 | $methods = [ |
52 | 52 | ViolationMessage::TYPE_ENTITY_ID => 'serializeEntityId', |
53 | 53 | ViolationMessage::TYPE_ENTITY_ID_LIST => 'serializeEntityIdList', |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | $value = $argument['value']; |
67 | 67 | $role = $argument['role']; |
68 | 68 | |
69 | - if ( array_key_exists( $type, $methods ) ) { |
|
69 | + if (array_key_exists($type, $methods)) { |
|
70 | 70 | $method = $methods[$type]; |
71 | - $serializedValue = $this->$method( $value ); |
|
71 | + $serializedValue = $this->$method($value); |
|
72 | 72 | } else { |
73 | 73 | throw new InvalidArgumentException( |
74 | - 'Unknown ViolationMessage argument type ' . $type . '!' |
|
74 | + 'Unknown ViolationMessage argument type '.$type.'!' |
|
75 | 75 | ); |
76 | 76 | } |
77 | 77 | |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | * @param string $string any value that shall simply be serialized to itself |
89 | 89 | * @return string that same value, unchanged |
90 | 90 | */ |
91 | - private function serializeStringByIdentity( $string ) { |
|
92 | - Assert::parameterType( 'string', $string, '$string' ); |
|
91 | + private function serializeStringByIdentity($string) { |
|
92 | + Assert::parameterType('string', $string, '$string'); |
|
93 | 93 | return $string; |
94 | 94 | } |
95 | 95 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * @param EntityId $entityId |
98 | 98 | * @return string entity ID serialization |
99 | 99 | */ |
100 | - private function serializeEntityId( EntityId $entityId ) { |
|
100 | + private function serializeEntityId(EntityId $entityId) { |
|
101 | 101 | return $entityId->getSerialization(); |
102 | 102 | } |
103 | 103 | |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | * @param EntityId[] $entityIdList |
106 | 106 | * @return string[] entity ID serializations |
107 | 107 | */ |
108 | - private function serializeEntityIdList( array $entityIdList ) { |
|
109 | - return array_map( [ $this, 'serializeEntityId' ], $entityIdList ); |
|
108 | + private function serializeEntityIdList(array $entityIdList) { |
|
109 | + return array_map([$this, 'serializeEntityId'], $entityIdList); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -114,10 +114,10 @@ discard block |
||
114 | 114 | * @return string entity ID serialization, '::somevalue', or '::novalue' |
115 | 115 | * (according to EntityId::PATTERN, entity ID serializations can never begin with two colons) |
116 | 116 | */ |
117 | - private function serializeItemIdSnakValue( ItemIdSnakValue $value ) { |
|
118 | - switch ( true ) { |
|
117 | + private function serializeItemIdSnakValue(ItemIdSnakValue $value) { |
|
118 | + switch (true) { |
|
119 | 119 | case $value->isValue(): |
120 | - return $this->serializeEntityId( $value->getItemId() ); |
|
120 | + return $this->serializeEntityId($value->getItemId()); |
|
121 | 121 | case $value->isSomeValue(): |
122 | 122 | return '::somevalue'; |
123 | 123 | case $value->isNoValue(): |
@@ -135,15 +135,15 @@ discard block |
||
135 | 135 | * @param ItemIdSnakValue[] $valueList |
136 | 136 | * @return string[] array of entity ID serializations, '::somevalue's or '::novalue's |
137 | 137 | */ |
138 | - private function serializeItemIdSnakValueList( array $valueList ) { |
|
139 | - return array_map( [ $this, 'serializeItemIdSnakValue' ], $valueList ); |
|
138 | + private function serializeItemIdSnakValueList(array $valueList) { |
|
139 | + return array_map([$this, 'serializeItemIdSnakValue'], $valueList); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
143 | 143 | * @param DataValue $dataValue |
144 | 144 | * @return array the data value in array form |
145 | 145 | */ |
146 | - private function serializeDataValue( DataValue $dataValue ) { |
|
146 | + private function serializeDataValue(DataValue $dataValue) { |
|
147 | 147 | return $dataValue->toArray(); |
148 | 148 | } |
149 | 149 | |
@@ -151,8 +151,8 @@ discard block |
||
151 | 151 | * @param string $scope one of the Context::TYPE_* constants |
152 | 152 | * @return string the abbreviated scope |
153 | 153 | */ |
154 | - private function serializeConstraintScope( $scope ) { |
|
155 | - switch ( $scope ) { |
|
154 | + private function serializeConstraintScope($scope) { |
|
155 | + switch ($scope) { |
|
156 | 156 | case Context::TYPE_STATEMENT: |
157 | 157 | return 's'; |
158 | 158 | case Context::TYPE_QUALIFIER: |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | default: |
163 | 163 | // @codeCoverageIgnoreStart |
164 | 164 | throw new LogicException( |
165 | - 'Unknown constraint scope ' . $scope |
|
165 | + 'Unknown constraint scope '.$scope |
|
166 | 166 | ); |
167 | 167 | // @codeCoverageIgnoreEnd |
168 | 168 | } |
@@ -172,15 +172,15 @@ discard block |
||
172 | 172 | * @param string[] $scopeList Context::TYPE_* constants |
173 | 173 | * @return string[] abbreviated scopes |
174 | 174 | */ |
175 | - private function serializeConstraintScopeList( array $scopeList ) { |
|
176 | - return array_map( [ $this, 'serializeConstraintScope' ], $scopeList ); |
|
175 | + private function serializeConstraintScopeList(array $scopeList) { |
|
176 | + return array_map([$this, 'serializeConstraintScope'], $scopeList); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
180 | 180 | * @param MultilingualTextValue $text |
181 | 181 | * @return mixed {@see MultilingualTextValue::getArrayValue} |
182 | 182 | */ |
183 | - private function serializeMultilingualText( MultilingualTextValue $text ) { |
|
183 | + private function serializeMultilingualText(MultilingualTextValue $text) { |
|
184 | 184 | return $text->getArrayValue(); |
185 | 185 | } |
186 | 186 |
@@ -39,23 +39,23 @@ discard block |
||
39 | 39 | $this->dataValueFactory = $dataValueFactory; |
40 | 40 | } |
41 | 41 | |
42 | - public function unabbreviateViolationMessageKey( $messageKeySuffix ) { |
|
43 | - return ViolationMessage::MESSAGE_KEY_PREFIX . $messageKeySuffix; |
|
42 | + public function unabbreviateViolationMessageKey($messageKeySuffix) { |
|
43 | + return ViolationMessage::MESSAGE_KEY_PREFIX.$messageKeySuffix; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @param array $serialization |
48 | 48 | * @return ViolationMessage |
49 | 49 | */ |
50 | - public function deserialize( $serialization ) { |
|
51 | - Assert::parameterType( 'array', $serialization, '$serialization' ); |
|
50 | + public function deserialize($serialization) { |
|
51 | + Assert::parameterType('array', $serialization, '$serialization'); |
|
52 | 52 | |
53 | 53 | $message = new ViolationMessage( |
54 | - $this->unabbreviateViolationMessageKey( $serialization['k'] ) |
|
54 | + $this->unabbreviateViolationMessageKey($serialization['k']) |
|
55 | 55 | ); |
56 | 56 | |
57 | - foreach ( $serialization['a'] as $serializedArgument ) { |
|
58 | - $message = $this->deserializeArgument( $message, $serializedArgument ); |
|
57 | + foreach ($serialization['a'] as $serializedArgument) { |
|
58 | + $message = $this->deserializeArgument($message, $serializedArgument); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | return $message; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @param array $serializedArgument [ 't' => ViolationMessage::TYPE_*, 'v' => serialized value, 'r' => $role ] |
67 | 67 | * @return ViolationMessage $message with the deserialized argument appended |
68 | 68 | */ |
69 | - private function deserializeArgument( ViolationMessage $message, array $serializedArgument ) { |
|
69 | + private function deserializeArgument(ViolationMessage $message, array $serializedArgument) { |
|
70 | 70 | $methods = [ |
71 | 71 | ViolationMessage::TYPE_ENTITY_ID => 'deserializeEntityId', |
72 | 72 | ViolationMessage::TYPE_ENTITY_ID_LIST => 'deserializeEntityIdList', |
@@ -85,23 +85,23 @@ discard block |
||
85 | 85 | $serializedValue = $serializedArgument['v']; |
86 | 86 | $role = $serializedArgument['r']; |
87 | 87 | |
88 | - if ( array_key_exists( $type, $methods ) ) { |
|
88 | + if (array_key_exists($type, $methods)) { |
|
89 | 89 | $method = $methods[$type]; |
90 | - $value = $this->$method( $serializedValue ); |
|
90 | + $value = $this->$method($serializedValue); |
|
91 | 91 | } else { |
92 | 92 | throw new InvalidArgumentException( |
93 | - 'Unknown ViolationMessage argument type ' . $type . '!' |
|
93 | + 'Unknown ViolationMessage argument type '.$type.'!' |
|
94 | 94 | ); |
95 | 95 | } |
96 | 96 | |
97 | - return $message->withArgument( $type, $role, $value ); |
|
97 | + return $message->withArgument($type, $role, $value); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * @param string $string any value that shall simply be deserialized into itself |
102 | 102 | * @return string that same value, unchanged |
103 | 103 | */ |
104 | - private function deserializeStringByIdentity( $string ) { |
|
104 | + private function deserializeStringByIdentity($string) { |
|
105 | 105 | return $string; |
106 | 106 | } |
107 | 107 | |
@@ -109,30 +109,30 @@ discard block |
||
109 | 109 | * @param string $entityIdSerialization entity ID serialization |
110 | 110 | * @return EntityId |
111 | 111 | */ |
112 | - private function deserializeEntityId( $entityIdSerialization ) { |
|
113 | - return $this->entityIdParser->parse( $entityIdSerialization ); |
|
112 | + private function deserializeEntityId($entityIdSerialization) { |
|
113 | + return $this->entityIdParser->parse($entityIdSerialization); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
117 | 117 | * @param string[] $entityIdSerializations entity ID serializations |
118 | 118 | * @return EntityId[] |
119 | 119 | */ |
120 | - private function deserializeEntityIdList( array $entityIdSerializations ) { |
|
121 | - return array_map( [ $this, 'deserializeEntityId' ], $entityIdSerializations ); |
|
120 | + private function deserializeEntityIdList(array $entityIdSerializations) { |
|
121 | + return array_map([$this, 'deserializeEntityId'], $entityIdSerializations); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
125 | 125 | * @param string $valueSerialization entity ID serialization, '::somevalue' or '::novalue' |
126 | 126 | * @return ItemIdSnakValue |
127 | 127 | */ |
128 | - private function deserializeItemIdSnakValue( $valueSerialization ) { |
|
129 | - switch ( $valueSerialization ) { |
|
128 | + private function deserializeItemIdSnakValue($valueSerialization) { |
|
129 | + switch ($valueSerialization) { |
|
130 | 130 | case '::somevalue': |
131 | 131 | return ItemIdSnakValue::someValue(); |
132 | 132 | case '::novalue': |
133 | 133 | return ItemIdSnakValue::noValue(); |
134 | 134 | default: |
135 | - return ItemIdSnakValue::fromItemId( $this->deserializeEntityId( $valueSerialization ) ); |
|
135 | + return ItemIdSnakValue::fromItemId($this->deserializeEntityId($valueSerialization)); |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
@@ -140,24 +140,24 @@ discard block |
||
140 | 140 | * @param string[] $valueSerializations entity ID serializations, '::somevalue's or '::novalue's |
141 | 141 | * @return ItemIdSnakValue[] |
142 | 142 | */ |
143 | - private function deserializeItemIdSnakValueList( $valueSerializations ) { |
|
144 | - return array_map( [ $this, 'deserializeItemIdSnakValue' ], $valueSerializations ); |
|
143 | + private function deserializeItemIdSnakValueList($valueSerializations) { |
|
144 | + return array_map([$this, 'deserializeItemIdSnakValue'], $valueSerializations); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
148 | 148 | * @param array $dataValueSerialization the data value in array form |
149 | 149 | * @return DataValue |
150 | 150 | */ |
151 | - private function deserializeDataValue( array $dataValueSerialization ) { |
|
152 | - return $this->dataValueFactory->newFromArray( $dataValueSerialization ); |
|
151 | + private function deserializeDataValue(array $dataValueSerialization) { |
|
152 | + return $this->dataValueFactory->newFromArray($dataValueSerialization); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
156 | 156 | * @param string $scopeAbbreviation |
157 | 157 | * @return string one of the Context::TYPE_* constants |
158 | 158 | */ |
159 | - private function deserializeConstraintScope( $scopeAbbreviation ) { |
|
160 | - switch ( $scopeAbbreviation ) { |
|
159 | + private function deserializeConstraintScope($scopeAbbreviation) { |
|
160 | + switch ($scopeAbbreviation) { |
|
161 | 161 | case 's': |
162 | 162 | return Context::TYPE_STATEMENT; |
163 | 163 | case 'q': |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | default: |
168 | 168 | // @codeCoverageIgnoreStart |
169 | 169 | throw new LogicException( |
170 | - 'Unknown constraint scope abbreviation ' . $scopeAbbreviation |
|
170 | + 'Unknown constraint scope abbreviation '.$scopeAbbreviation |
|
171 | 171 | ); |
172 | 172 | // @codeCoverageIgnoreEnd |
173 | 173 | } |
@@ -177,16 +177,16 @@ discard block |
||
177 | 177 | * @param string[] $scopeAbbreviations |
178 | 178 | * @return string[] Context::TYPE_* constants |
179 | 179 | */ |
180 | - private function deserializeConstraintScopeList( array $scopeAbbreviations ) { |
|
181 | - return array_map( [ $this, 'deserializeConstraintScope' ], $scopeAbbreviations ); |
|
180 | + private function deserializeConstraintScopeList(array $scopeAbbreviations) { |
|
181 | + return array_map([$this, 'deserializeConstraintScope'], $scopeAbbreviations); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | 185 | * @param mixed $textSerialization {@see MultilingualTextValue::getArrayValue} |
186 | 186 | * @return MultilingualTextValue |
187 | 187 | */ |
188 | - private function deserializeMultilingualText( $textSerialization ) { |
|
189 | - return MultilingualTextValue::newFromArray( $textSerialization ); |
|
188 | + private function deserializeMultilingualText($textSerialization) { |
|
189 | + return MultilingualTextValue::newFromArray($textSerialization); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | } |
@@ -107,18 +107,18 @@ discard block |
||
107 | 107 | $this->violationMessageDeserializer = $violationMessageDeserializer; |
108 | 108 | $this->dataFactory = $dataFactory; |
109 | 109 | |
110 | - $this->entityPrefix = $rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY ); |
|
110 | + $this->entityPrefix = $rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY); |
|
111 | 111 | $this->prefixes = <<<EOT |
112 | -PREFIX wd: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY )}> |
|
113 | -PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}> |
|
114 | -PREFIX wdt: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_DIRECT_CLAIM )}> |
|
115 | -PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}> |
|
116 | -PREFIX p: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM )}> |
|
117 | -PREFIX ps: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM_STATEMENT )}> |
|
118 | -PREFIX pq: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER )}> |
|
119 | -PREFIX pqv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER_VALUE )}> |
|
120 | -PREFIX pr: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE )}> |
|
121 | -PREFIX prv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE_VALUE )}> |
|
112 | +PREFIX wd: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY)}> |
|
113 | +PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}> |
|
114 | +PREFIX wdt: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_DIRECT_CLAIM)}> |
|
115 | +PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}> |
|
116 | +PREFIX p: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM)}> |
|
117 | +PREFIX ps: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM_STATEMENT)}> |
|
118 | +PREFIX pq: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER)}> |
|
119 | +PREFIX pqv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER_VALUE)}> |
|
120 | +PREFIX pr: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE)}> |
|
121 | +PREFIX prv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE_VALUE)}> |
|
122 | 122 | PREFIX wikibase: <http://wikiba.se/ontology#> |
123 | 123 | PREFIX wikibase-beta: <http://wikiba.se/ontology-beta#> |
124 | 124 | EOT; |
@@ -133,21 +133,21 @@ discard block |
||
133 | 133 | * @return CachedBool |
134 | 134 | * @throws SparqlHelperException if the query times out or some other error occurs |
135 | 135 | */ |
136 | - public function hasType( $id, array $classes, $withInstance ) { |
|
137 | - $instanceOfId = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
138 | - $subclassOfId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
136 | + public function hasType($id, array $classes, $withInstance) { |
|
137 | + $instanceOfId = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
138 | + $subclassOfId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
139 | 139 | |
140 | - $path = ( $withInstance ? "wdt:$instanceOfId/" : "" ) . "wdt:$subclassOfId*"; |
|
140 | + $path = ($withInstance ? "wdt:$instanceOfId/" : "")."wdt:$subclassOfId*"; |
|
141 | 141 | |
142 | 142 | $metadatas = []; |
143 | 143 | |
144 | - foreach ( array_chunk( $classes, 20 ) as $classesChunk ) { |
|
145 | - $classesValues = implode( ' ', array_map( |
|
146 | - function( $class ) { |
|
147 | - return 'wd:' . $class; |
|
144 | + foreach (array_chunk($classes, 20) as $classesChunk) { |
|
145 | + $classesValues = implode(' ', array_map( |
|
146 | + function($class) { |
|
147 | + return 'wd:'.$class; |
|
148 | 148 | }, |
149 | 149 | $classesChunk |
150 | - ) ); |
|
150 | + )); |
|
151 | 151 | |
152 | 152 | $query = <<<EOF |
153 | 153 | ASK { |
@@ -158,19 +158,19 @@ discard block |
||
158 | 158 | EOF; |
159 | 159 | // TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually |
160 | 160 | |
161 | - $result = $this->runQuery( $query ); |
|
161 | + $result = $this->runQuery($query); |
|
162 | 162 | $metadatas[] = $result->getMetadata(); |
163 | - if ( $result->getArray()['boolean'] ) { |
|
163 | + if ($result->getArray()['boolean']) { |
|
164 | 164 | return new CachedBool( |
165 | 165 | true, |
166 | - Metadata::merge( $metadatas ) |
|
166 | + Metadata::merge($metadatas) |
|
167 | 167 | ); |
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
171 | 171 | return new CachedBool( |
172 | 172 | false, |
173 | - Metadata::merge( $metadatas ) |
|
173 | + Metadata::merge($metadatas) |
|
174 | 174 | ); |
175 | 175 | } |
176 | 176 | |
@@ -186,10 +186,10 @@ discard block |
||
186 | 186 | $ignoreDeprecatedStatements |
187 | 187 | ) { |
188 | 188 | $pid = $statement->getPropertyId()->serialize(); |
189 | - $guid = str_replace( '$', '-', $statement->getGuid() ); |
|
189 | + $guid = str_replace('$', '-', $statement->getGuid()); |
|
190 | 190 | |
191 | 191 | $deprecatedFilter = ''; |
192 | - if ( $ignoreDeprecatedStatements ) { |
|
192 | + if ($ignoreDeprecatedStatements) { |
|
193 | 193 | $deprecatedFilter .= 'MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }'; |
194 | 194 | $deprecatedFilter .= 'MINUS { ?otherStatement wikibase-beta:rank wikibase-beta:DeprecatedRank. }'; |
195 | 195 | } |
@@ -209,9 +209,9 @@ discard block |
||
209 | 209 | LIMIT 10 |
210 | 210 | EOF; |
211 | 211 | |
212 | - $result = $this->runQuery( $query ); |
|
212 | + $result = $this->runQuery($query); |
|
213 | 213 | |
214 | - return $this->getOtherEntities( $result ); |
|
214 | + return $this->getOtherEntities($result); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
@@ -236,16 +236,15 @@ discard block |
||
236 | 236 | $dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty( |
237 | 237 | $snak->getPropertyId() |
238 | 238 | ); |
239 | - list( $value, $isFullValue ) = $this->getRdfLiteral( $dataType, $dataValue ); |
|
240 | - if ( $isFullValue ) { |
|
239 | + list($value, $isFullValue) = $this->getRdfLiteral($dataType, $dataValue); |
|
240 | + if ($isFullValue) { |
|
241 | 241 | $prefix .= 'v'; |
242 | 242 | } |
243 | 243 | $path = $type === Context::TYPE_QUALIFIER ? |
244 | - "$prefix:$pid" : |
|
245 | - "prov:wasDerivedFrom/$prefix:$pid"; |
|
244 | + "$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid"; |
|
246 | 245 | |
247 | 246 | $deprecatedFilter = ''; |
248 | - if ( $ignoreDeprecatedStatements ) { |
|
247 | + if ($ignoreDeprecatedStatements) { |
|
249 | 248 | $deprecatedFilter = <<< EOF |
250 | 249 | MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. } |
251 | 250 | MINUS { ?otherStatement wikibase-beta:rank wikibase-beta:DeprecatedRank. } |
@@ -266,9 +265,9 @@ discard block |
||
266 | 265 | LIMIT 10 |
267 | 266 | EOF; |
268 | 267 | |
269 | - $result = $this->runQuery( $query ); |
|
268 | + $result = $this->runQuery($query); |
|
270 | 269 | |
271 | - return $this->getOtherEntities( $result ); |
|
270 | + return $this->getOtherEntities($result); |
|
272 | 271 | } |
273 | 272 | |
274 | 273 | /** |
@@ -278,8 +277,8 @@ discard block |
||
278 | 277 | * |
279 | 278 | * @return string |
280 | 279 | */ |
281 | - private function stringLiteral( $text ) { |
|
282 | - return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"'; |
|
280 | + private function stringLiteral($text) { |
|
281 | + return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"'; |
|
283 | 282 | } |
284 | 283 | |
285 | 284 | /** |
@@ -289,17 +288,17 @@ discard block |
||
289 | 288 | * |
290 | 289 | * @return CachedEntityIds |
291 | 290 | */ |
292 | - private function getOtherEntities( CachedQueryResults $results ) { |
|
293 | - return new CachedEntityIds( array_map( |
|
294 | - function ( $resultBindings ) { |
|
291 | + private function getOtherEntities(CachedQueryResults $results) { |
|
292 | + return new CachedEntityIds(array_map( |
|
293 | + function($resultBindings) { |
|
295 | 294 | $entityIRI = $resultBindings['otherEntity']['value']; |
296 | - $entityPrefixLength = strlen( $this->entityPrefix ); |
|
297 | - if ( substr( $entityIRI, 0, $entityPrefixLength ) === $this->entityPrefix ) { |
|
295 | + $entityPrefixLength = strlen($this->entityPrefix); |
|
296 | + if (substr($entityIRI, 0, $entityPrefixLength) === $this->entityPrefix) { |
|
298 | 297 | try { |
299 | 298 | return $this->entityIdParser->parse( |
300 | - substr( $entityIRI, $entityPrefixLength ) |
|
299 | + substr($entityIRI, $entityPrefixLength) |
|
301 | 300 | ); |
302 | - } catch ( EntityIdParsingException $e ) { |
|
301 | + } catch (EntityIdParsingException $e) { |
|
303 | 302 | // fall through |
304 | 303 | } |
305 | 304 | } |
@@ -307,7 +306,7 @@ discard block |
||
307 | 306 | return null; |
308 | 307 | }, |
309 | 308 | $results->getArray()['results']['bindings'] |
310 | - ), $results->getMetadata() ); |
|
309 | + ), $results->getMetadata()); |
|
311 | 310 | } |
312 | 311 | |
313 | 312 | // @codingStandardsIgnoreStart cyclomatic complexity of this function is too high |
@@ -320,47 +319,47 @@ discard block |
||
320 | 319 | * @return array the literal or IRI as a string in SPARQL syntax, |
321 | 320 | * and a boolean indicating whether it refers to a full value node or not |
322 | 321 | */ |
323 | - private function getRdfLiteral( $dataType, DataValue $dataValue ) { |
|
324 | - switch ( $dataType ) { |
|
322 | + private function getRdfLiteral($dataType, DataValue $dataValue) { |
|
323 | + switch ($dataType) { |
|
325 | 324 | case 'string': |
326 | 325 | case 'external-id': |
327 | - return [ $this->stringLiteral( $dataValue->getValue() ), false ]; |
|
326 | + return [$this->stringLiteral($dataValue->getValue()), false]; |
|
328 | 327 | case 'commonsMedia': |
329 | - $url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() ); |
|
330 | - return [ '<' . $url . '>', false ]; |
|
328 | + $url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue()); |
|
329 | + return ['<'.$url.'>', false]; |
|
331 | 330 | case 'geo-shape': |
332 | - $url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() ); |
|
333 | - return [ '<' . $url . '>', false ]; |
|
331 | + $url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue()); |
|
332 | + return ['<'.$url.'>', false]; |
|
334 | 333 | case 'tabular-data': |
335 | - $url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() ); |
|
336 | - return [ '<' . $url . '>', false ]; |
|
334 | + $url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue()); |
|
335 | + return ['<'.$url.'>', false]; |
|
337 | 336 | case 'url': |
338 | 337 | $url = $dataValue->getValue(); |
339 | - if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) { |
|
338 | + if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) { |
|
340 | 339 | // not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF) |
341 | 340 | // such an URL should never reach us, so just throw |
342 | - throw new InvalidArgumentException( 'invalid URL: ' . $url ); |
|
341 | + throw new InvalidArgumentException('invalid URL: '.$url); |
|
343 | 342 | } |
344 | - return [ '<' . $url . '>', false ]; |
|
343 | + return ['<'.$url.'>', false]; |
|
345 | 344 | case 'wikibase-item': |
346 | 345 | case 'wikibase-property': |
347 | 346 | /** @var EntityIdValue $dataValue */ |
348 | - return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ]; |
|
347 | + return ['wd:'.$dataValue->getEntityId()->getSerialization(), false]; |
|
349 | 348 | case 'monolingualtext': |
350 | 349 | /** @var MonolingualTextValue $dataValue */ |
351 | 350 | $lang = $dataValue->getLanguageCode(); |
352 | - if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) { |
|
351 | + if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) { |
|
353 | 352 | // not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG) |
354 | 353 | // such a language tag should never reach us, so just throw |
355 | - throw new InvalidArgumentException( 'invalid language tag: ' . $lang ); |
|
354 | + throw new InvalidArgumentException('invalid language tag: '.$lang); |
|
356 | 355 | } |
357 | - return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ]; |
|
356 | + return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false]; |
|
358 | 357 | case 'globe-coordinate': |
359 | 358 | case 'quantity': |
360 | 359 | case 'time': |
361 | - return [ 'wdv:' . $dataValue->getHash(), true ]; |
|
360 | + return ['wdv:'.$dataValue->getHash(), true]; |
|
362 | 361 | default: |
363 | - throw new InvalidArgumentException( 'unknown data type: ' . $dataType ); |
|
362 | + throw new InvalidArgumentException('unknown data type: '.$dataType); |
|
364 | 363 | } |
365 | 364 | } |
366 | 365 | // @codingStandardsIgnoreEnd |
@@ -373,47 +372,47 @@ discard block |
||
373 | 372 | * @throws SparqlHelperException if the query times out or some other error occurs |
374 | 373 | * @throws ConstraintParameterException if the $regex is invalid |
375 | 374 | */ |
376 | - public function matchesRegularExpression( $text, $regex ) { |
|
375 | + public function matchesRegularExpression($text, $regex) { |
|
377 | 376 | // caching wrapper around matchesRegularExpressionWithSparql |
378 | 377 | |
379 | - $textHash = hash( 'sha256', $text ); |
|
378 | + $textHash = hash('sha256', $text); |
|
380 | 379 | $cacheKey = $this->cache->makeKey( |
381 | 380 | 'WikibaseQualityConstraints', // extension |
382 | 381 | 'regex', // action |
383 | 382 | 'WDQS-Java', // regex flavor |
384 | - hash( 'sha256', $regex ) |
|
383 | + hash('sha256', $regex) |
|
385 | 384 | ); |
386 | - $cacheMapSize = $this->config->get( 'WBQualityConstraintsFormatCacheMapSize' ); |
|
385 | + $cacheMapSize = $this->config->get('WBQualityConstraintsFormatCacheMapSize'); |
|
387 | 386 | |
388 | 387 | $cacheMapArray = $this->cache->getWithSetCallback( |
389 | 388 | $cacheKey, |
390 | 389 | WANObjectCache::TTL_DAY, |
391 | - function( $cacheMapArray ) use ( $text, $regex, $textHash, $cacheMapSize ) { |
|
390 | + function($cacheMapArray) use ($text, $regex, $textHash, $cacheMapSize) { |
|
392 | 391 | // Initialize the cache map if not set |
393 | - if ( $cacheMapArray === false ) { |
|
392 | + if ($cacheMapArray === false) { |
|
394 | 393 | $key = 'wikibase.quality.constraints.regex.cache.refresh.init'; |
395 | - $this->dataFactory->increment( $key ); |
|
394 | + $this->dataFactory->increment($key); |
|
396 | 395 | return []; |
397 | 396 | } |
398 | 397 | |
399 | 398 | $key = 'wikibase.quality.constraints.regex.cache.refresh'; |
400 | - $this->dataFactory->increment( $key ); |
|
401 | - $cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $cacheMapSize ); |
|
402 | - if ( $cacheMap->has( $textHash ) ) { |
|
399 | + $this->dataFactory->increment($key); |
|
400 | + $cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $cacheMapSize); |
|
401 | + if ($cacheMap->has($textHash)) { |
|
403 | 402 | $key = 'wikibase.quality.constraints.regex.cache.refresh.hit'; |
404 | - $this->dataFactory->increment( $key ); |
|
405 | - $cacheMap->get( $textHash ); // ping cache |
|
403 | + $this->dataFactory->increment($key); |
|
404 | + $cacheMap->get($textHash); // ping cache |
|
406 | 405 | } else { |
407 | 406 | $key = 'wikibase.quality.constraints.regex.cache.refresh.miss'; |
408 | - $this->dataFactory->increment( $key ); |
|
407 | + $this->dataFactory->increment($key); |
|
409 | 408 | try { |
410 | - $matches = $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
411 | - } catch ( ConstraintParameterException $e ) { |
|
409 | + $matches = $this->matchesRegularExpressionWithSparql($text, $regex); |
|
410 | + } catch (ConstraintParameterException $e) { |
|
412 | 411 | $matches = [ |
413 | 412 | 'type' => ConstraintParameterException::class, |
414 | 413 | 'message' => $e->getMessage(), |
415 | 414 | ]; |
416 | - } catch ( SparqlHelperException $e ) { |
|
415 | + } catch (SparqlHelperException $e) { |
|
417 | 416 | // don’t cache this |
418 | 417 | return $cacheMap->toArray(); |
419 | 418 | } |
@@ -437,27 +436,27 @@ discard block |
||
437 | 436 | ] |
438 | 437 | ); |
439 | 438 | |
440 | - if ( isset( $cacheMapArray[$textHash] ) ) { |
|
439 | + if (isset($cacheMapArray[$textHash])) { |
|
441 | 440 | $key = 'wikibase.quality.constraints.regex.cache.hit'; |
442 | - $this->dataFactory->increment( $key ); |
|
441 | + $this->dataFactory->increment($key); |
|
443 | 442 | $matches = $cacheMapArray[$textHash]; |
444 | - if ( is_bool( $matches ) ) { |
|
443 | + if (is_bool($matches)) { |
|
445 | 444 | return $matches; |
446 | - } elseif ( is_array( $matches ) && |
|
447 | - $matches['type'] == ConstraintParameterException::class ) { |
|
448 | - throw new ConstraintParameterException( $matches['message'] ); |
|
445 | + } elseif (is_array($matches) && |
|
446 | + $matches['type'] == ConstraintParameterException::class) { |
|
447 | + throw new ConstraintParameterException($matches['message']); |
|
449 | 448 | } else { |
450 | 449 | throw new MWException( |
451 | - 'Value of unknown type in object cache (' . |
|
452 | - 'cache key: ' . $cacheKey . ', ' . |
|
453 | - 'cache map key: ' . $textHash . ', ' . |
|
454 | - 'value type: ' . gettype( $matches ) . ')' |
|
450 | + 'Value of unknown type in object cache ('. |
|
451 | + 'cache key: '.$cacheKey.', '. |
|
452 | + 'cache map key: '.$textHash.', '. |
|
453 | + 'value type: '.gettype($matches).')' |
|
455 | 454 | ); |
456 | 455 | } |
457 | 456 | } else { |
458 | 457 | $key = 'wikibase.quality.constraints.regex.cache.miss'; |
459 | - $this->dataFactory->increment( $key ); |
|
460 | - return $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
458 | + $this->dataFactory->increment($key); |
|
459 | + return $this->matchesRegularExpressionWithSparql($text, $regex); |
|
461 | 460 | } |
462 | 461 | } |
463 | 462 | |
@@ -472,26 +471,26 @@ discard block |
||
472 | 471 | * @throws SparqlHelperException if the query times out or some other error occurs |
473 | 472 | * @throws ConstraintParameterException if the $regex is invalid |
474 | 473 | */ |
475 | - public function matchesRegularExpressionWithSparql( $text, $regex ) { |
|
476 | - $textStringLiteral = $this->stringLiteral( $text ); |
|
477 | - $regexStringLiteral = $this->stringLiteral( '^' . $regex . '$' ); |
|
474 | + public function matchesRegularExpressionWithSparql($text, $regex) { |
|
475 | + $textStringLiteral = $this->stringLiteral($text); |
|
476 | + $regexStringLiteral = $this->stringLiteral('^'.$regex.'$'); |
|
478 | 477 | |
479 | 478 | $query = <<<EOF |
480 | 479 | SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {} |
481 | 480 | EOF; |
482 | 481 | |
483 | - $result = $this->runQuery( $query ); |
|
482 | + $result = $this->runQuery($query); |
|
484 | 483 | |
485 | 484 | $vars = $result->getArray()['results']['bindings'][0]; |
486 | - if ( array_key_exists( 'matches', $vars ) ) { |
|
485 | + if (array_key_exists('matches', $vars)) { |
|
487 | 486 | // true or false ⇒ regex okay, text matches or not |
488 | 487 | return $vars['matches']['value'] === 'true'; |
489 | 488 | } else { |
490 | 489 | // empty result: regex broken |
491 | 490 | throw new ConstraintParameterException( |
492 | - wfMessage( 'wbqc-violation-message-parameter-regex' ) |
|
493 | - ->rawParams( ConstraintParameterRenderer::formatByRole( Role::CONSTRAINT_PARAMETER_VALUE, |
|
494 | - '<code><nowiki>' . htmlspecialchars( $regex ) . '</nowiki></code>' ) ) |
|
491 | + wfMessage('wbqc-violation-message-parameter-regex') |
|
492 | + ->rawParams(ConstraintParameterRenderer::formatByRole(Role::CONSTRAINT_PARAMETER_VALUE, |
|
493 | + '<code><nowiki>'.htmlspecialchars($regex).'</nowiki></code>')) |
|
495 | 494 | ->escaped() |
496 | 495 | ); |
497 | 496 | } |
@@ -504,14 +503,14 @@ discard block |
||
504 | 503 | * |
505 | 504 | * @return boolean |
506 | 505 | */ |
507 | - public function isTimeout( $responseContent ) { |
|
508 | - $timeoutRegex = implode( '|', array_map( |
|
509 | - function ( $fqn ) { |
|
510 | - return preg_quote( $fqn, '/' ); |
|
506 | + public function isTimeout($responseContent) { |
|
507 | + $timeoutRegex = implode('|', array_map( |
|
508 | + function($fqn) { |
|
509 | + return preg_quote($fqn, '/'); |
|
511 | 510 | }, |
512 | - $this->config->get( 'WBQualityConstraintsSparqlTimeoutExceptionClasses' ) |
|
513 | - ) ); |
|
514 | - return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent ); |
|
511 | + $this->config->get('WBQualityConstraintsSparqlTimeoutExceptionClasses') |
|
512 | + )); |
|
513 | + return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent); |
|
515 | 514 | } |
516 | 515 | |
517 | 516 | /** |
@@ -523,17 +522,17 @@ discard block |
||
523 | 522 | * @return integer|boolean the max-age (in seconds) |
524 | 523 | * or a plain boolean if no max-age can be determined |
525 | 524 | */ |
526 | - public function getCacheMaxAge( $responseHeaders ) { |
|
525 | + public function getCacheMaxAge($responseHeaders) { |
|
527 | 526 | if ( |
528 | - array_key_exists( 'x-cache-status', $responseHeaders ) && |
|
529 | - preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] ) |
|
527 | + array_key_exists('x-cache-status', $responseHeaders) && |
|
528 | + preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0]) |
|
530 | 529 | ) { |
531 | 530 | $maxage = []; |
532 | 531 | if ( |
533 | - array_key_exists( 'cache-control', $responseHeaders ) && |
|
534 | - preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage ) |
|
532 | + array_key_exists('cache-control', $responseHeaders) && |
|
533 | + preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage) |
|
535 | 534 | ) { |
536 | - return intval( $maxage[1] ); |
|
535 | + return intval($maxage[1]); |
|
537 | 536 | } else { |
538 | 537 | return true; |
539 | 538 | } |
@@ -551,59 +550,58 @@ discard block |
||
551 | 550 | * |
552 | 551 | * @throws SparqlHelperException if the query times out or some other error occurs |
553 | 552 | */ |
554 | - public function runQuery( $query ) { |
|
553 | + public function runQuery($query) { |
|
555 | 554 | |
556 | - $endpoint = $this->config->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
557 | - $maxQueryTimeMillis = $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' ); |
|
558 | - $url = $endpoint . '?' . http_build_query( |
|
555 | + $endpoint = $this->config->get('WBQualityConstraintsSparqlEndpoint'); |
|
556 | + $maxQueryTimeMillis = $this->config->get('WBQualityConstraintsSparqlMaxMillis'); |
|
557 | + $url = $endpoint.'?'.http_build_query( |
|
559 | 558 | [ |
560 | - 'query' => "#wbqc\n" . $this->prefixes . $query, |
|
559 | + 'query' => "#wbqc\n".$this->prefixes.$query, |
|
561 | 560 | 'format' => 'json', |
562 | 561 | 'maxQueryTimeMillis' => $maxQueryTimeMillis, |
563 | 562 | ], |
564 | - null, ini_get( 'arg_separator.output' ), |
|
563 | + null, ini_get('arg_separator.output'), |
|
565 | 564 | // encode spaces with %20, not + |
566 | 565 | PHP_QUERY_RFC3986 |
567 | 566 | ); |
568 | 567 | |
569 | 568 | $options = [ |
570 | 569 | 'method' => 'GET', |
571 | - 'timeout' => (int)round( ( $maxQueryTimeMillis + 1000 ) / 1000 ), |
|
570 | + 'timeout' => (int) round(($maxQueryTimeMillis + 1000) / 1000), |
|
572 | 571 | 'connectTimeout' => 'default', |
573 | 572 | ]; |
574 | - $request = MWHttpRequest::factory( $url, $options ); |
|
575 | - $startTime = microtime( true ); |
|
573 | + $request = MWHttpRequest::factory($url, $options); |
|
574 | + $startTime = microtime(true); |
|
576 | 575 | $status = $request->execute(); |
577 | - $endTime = microtime( true ); |
|
576 | + $endTime = microtime(true); |
|
578 | 577 | $this->dataFactory->timing( |
579 | 578 | 'wikibase.quality.constraints.sparql.timing', |
580 | - ( $endTime - $startTime ) * 1000 |
|
579 | + ($endTime - $startTime) * 1000 |
|
581 | 580 | ); |
582 | 581 | |
583 | - $maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() ); |
|
584 | - if ( $maxAge ) { |
|
585 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' ); |
|
582 | + $maxAge = $this->getCacheMaxAge($request->getResponseHeaders()); |
|
583 | + if ($maxAge) { |
|
584 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.cached'); |
|
586 | 585 | } |
587 | 586 | |
588 | - if ( $status->isOK() ) { |
|
587 | + if ($status->isOK()) { |
|
589 | 588 | $json = $request->getContent(); |
590 | - $arr = json_decode( $json, true ); |
|
589 | + $arr = json_decode($json, true); |
|
591 | 590 | return new CachedQueryResults( |
592 | 591 | $arr, |
593 | 592 | Metadata::ofCachingMetadata( |
594 | 593 | $maxAge ? |
595 | - CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) : |
|
596 | - CachingMetadata::fresh() |
|
594 | + CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh() |
|
597 | 595 | ) |
598 | 596 | ); |
599 | 597 | } else { |
600 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' ); |
|
598 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.error'); |
|
601 | 599 | |
602 | 600 | $this->dataFactory->increment( |
603 | 601 | "wikibase.quality.constraints.sparql.error.http.{$request->getStatus()}" |
604 | 602 | ); |
605 | 603 | |
606 | - if ( $this->isTimeout( $request->getContent() ) ) { |
|
604 | + if ($this->isTimeout($request->getContent())) { |
|
607 | 605 | $this->dataFactory->increment( |
608 | 606 | 'wikibase.quality.constraints.sparql.error.timeout' |
609 | 607 | ); |
@@ -77,15 +77,15 @@ discard block |
||
77 | 77 | * @param array $parameters |
78 | 78 | * @throws ConstraintParameterException |
79 | 79 | */ |
80 | - public function checkError( array $parameters ) { |
|
81 | - if ( array_key_exists( '@error', $parameters ) ) { |
|
80 | + public function checkError(array $parameters) { |
|
81 | + if (array_key_exists('@error', $parameters)) { |
|
82 | 82 | $error = $parameters['@error']; |
83 | - if ( array_key_exists( 'toolong', $error ) && $error['toolong'] ) { |
|
83 | + if (array_key_exists('toolong', $error) && $error['toolong']) { |
|
84 | 84 | $msg = 'wbqc-violation-message-parameters-error-toolong'; |
85 | 85 | } else { |
86 | 86 | $msg = 'wbqc-violation-message-parameters-error-unknown'; |
87 | 87 | } |
88 | - throw new ConstraintParameterException( wfMessage( $msg )->escaped() ); |
|
88 | + throw new ConstraintParameterException(wfMessage($msg)->escaped()); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
@@ -95,11 +95,11 @@ discard block |
||
95 | 95 | * @param string $parameterId |
96 | 96 | * @throws ConstraintParameterException |
97 | 97 | */ |
98 | - private function requireSingleParameter( array $parameters, $parameterId ) { |
|
99 | - if ( count( $parameters[$parameterId] ) !== 1 ) { |
|
98 | + private function requireSingleParameter(array $parameters, $parameterId) { |
|
99 | + if (count($parameters[$parameterId]) !== 1) { |
|
100 | 100 | throw new ConstraintParameterException( |
101 | - wfMessage( 'wbqc-violation-message-parameter-single' ) |
|
102 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
101 | + wfMessage('wbqc-violation-message-parameter-single') |
|
102 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
103 | 103 | ->escaped() |
104 | 104 | ); |
105 | 105 | } |
@@ -112,11 +112,11 @@ discard block |
||
112 | 112 | * @return void |
113 | 113 | * @throws ConstraintParameterException |
114 | 114 | */ |
115 | - private function requireValueParameter( Snak $snak, $parameterId ) { |
|
116 | - if ( !( $snak instanceof PropertyValueSnak ) ) { |
|
115 | + private function requireValueParameter(Snak $snak, $parameterId) { |
|
116 | + if (!($snak instanceof PropertyValueSnak)) { |
|
117 | 117 | throw new ConstraintParameterException( |
118 | - wfMessage( 'wbqc-violation-message-parameter-value' ) |
|
119 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
118 | + wfMessage('wbqc-violation-message-parameter-value') |
|
119 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
120 | 120 | ->escaped() |
121 | 121 | ); |
122 | 122 | } |
@@ -129,18 +129,18 @@ discard block |
||
129 | 129 | * @throws ConstraintParameterException |
130 | 130 | * @return EntityId |
131 | 131 | */ |
132 | - private function parseEntityIdParameter( array $snakSerialization, $parameterId ) { |
|
133 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
134 | - $this->requireValueParameter( $snak, $parameterId ); |
|
132 | + private function parseEntityIdParameter(array $snakSerialization, $parameterId) { |
|
133 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
134 | + $this->requireValueParameter($snak, $parameterId); |
|
135 | 135 | $value = $snak->getDataValue(); |
136 | - if ( $value instanceof EntityIdValue ) { |
|
136 | + if ($value instanceof EntityIdValue) { |
|
137 | 137 | return $value->getEntityId(); |
138 | 138 | } else { |
139 | 139 | throw new ConstraintParameterException( |
140 | - wfMessage( 'wbqc-violation-message-parameter-entity' ) |
|
140 | + wfMessage('wbqc-violation-message-parameter-entity') |
|
141 | 141 | ->rawParams( |
142 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
143 | - $this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
142 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
143 | + $this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
144 | 144 | ) |
145 | 145 | ->escaped() |
146 | 146 | ); |
@@ -153,21 +153,21 @@ discard block |
||
153 | 153 | * @throws ConstraintParameterException if the parameter is invalid or missing |
154 | 154 | * @return string[] class entity ID serializations |
155 | 155 | */ |
156 | - public function parseClassParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
157 | - $this->checkError( $constraintParameters ); |
|
158 | - $classId = $this->config->get( 'WBQualityConstraintsClassId' ); |
|
159 | - if ( !array_key_exists( $classId, $constraintParameters ) ) { |
|
156 | + public function parseClassParameter(array $constraintParameters, $constraintTypeItemId) { |
|
157 | + $this->checkError($constraintParameters); |
|
158 | + $classId = $this->config->get('WBQualityConstraintsClassId'); |
|
159 | + if (!array_key_exists($classId, $constraintParameters)) { |
|
160 | 160 | throw new ConstraintParameterException( |
161 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
162 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
163 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $classId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
161 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
162 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
163 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($classId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
164 | 164 | ->escaped() |
165 | 165 | ); |
166 | 166 | } |
167 | 167 | |
168 | 168 | $classes = []; |
169 | - foreach ( $constraintParameters[$classId] as $class ) { |
|
170 | - $classes[] = $this->parseEntityIdParameter( $class, $classId )->getSerialization(); |
|
169 | + foreach ($constraintParameters[$classId] as $class) { |
|
170 | + $classes[] = $this->parseEntityIdParameter($class, $classId)->getSerialization(); |
|
171 | 171 | } |
172 | 172 | return $classes; |
173 | 173 | } |
@@ -178,24 +178,24 @@ discard block |
||
178 | 178 | * @throws ConstraintParameterException if the parameter is invalid or missing |
179 | 179 | * @return string 'instance', 'subclass', or 'instanceOrSubclass' |
180 | 180 | */ |
181 | - public function parseRelationParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
182 | - $this->checkError( $constraintParameters ); |
|
183 | - $relationId = $this->config->get( 'WBQualityConstraintsRelationId' ); |
|
184 | - if ( !array_key_exists( $relationId, $constraintParameters ) ) { |
|
181 | + public function parseRelationParameter(array $constraintParameters, $constraintTypeItemId) { |
|
182 | + $this->checkError($constraintParameters); |
|
183 | + $relationId = $this->config->get('WBQualityConstraintsRelationId'); |
|
184 | + if (!array_key_exists($relationId, $constraintParameters)) { |
|
185 | 185 | throw new ConstraintParameterException( |
186 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
187 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
188 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $relationId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
186 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
187 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
188 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($relationId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
189 | 189 | ->escaped() |
190 | 190 | ); |
191 | 191 | } |
192 | 192 | |
193 | - $this->requireSingleParameter( $constraintParameters, $relationId ); |
|
194 | - $relationEntityId = $this->parseEntityIdParameter( $constraintParameters[$relationId][0], $relationId ); |
|
195 | - $instanceId = $this->config->get( 'WBQualityConstraintsInstanceOfRelationId' ); |
|
196 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfRelationId' ); |
|
197 | - $instanceOrSubclassId = $this->config->get( 'WBQualityConstraintsInstanceOrSubclassOfRelationId' ); |
|
198 | - switch ( $relationEntityId ) { |
|
193 | + $this->requireSingleParameter($constraintParameters, $relationId); |
|
194 | + $relationEntityId = $this->parseEntityIdParameter($constraintParameters[$relationId][0], $relationId); |
|
195 | + $instanceId = $this->config->get('WBQualityConstraintsInstanceOfRelationId'); |
|
196 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfRelationId'); |
|
197 | + $instanceOrSubclassId = $this->config->get('WBQualityConstraintsInstanceOrSubclassOfRelationId'); |
|
198 | + switch ($relationEntityId) { |
|
199 | 199 | case $instanceId: |
200 | 200 | return 'instance'; |
201 | 201 | case $subclassId: |
@@ -204,13 +204,13 @@ discard block |
||
204 | 204 | return 'instanceOrSubclass'; |
205 | 205 | default: |
206 | 206 | throw new ConstraintParameterException( |
207 | - wfMessage( 'wbqc-violation-message-parameter-oneof' ) |
|
208 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $relationId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
209 | - ->numParams( 3 ) |
|
210 | - ->rawParams( $this->constraintParameterRenderer->formatItemIdList( |
|
211 | - [ $instanceId, $subclassId, $instanceOrSubclassId ], |
|
207 | + wfMessage('wbqc-violation-message-parameter-oneof') |
|
208 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($relationId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
209 | + ->numParams(3) |
|
210 | + ->rawParams($this->constraintParameterRenderer->formatItemIdList( |
|
211 | + [$instanceId, $subclassId, $instanceOrSubclassId], |
|
212 | 212 | Role::CONSTRAINT_PARAMETER_VALUE |
213 | - ) ) |
|
213 | + )) |
|
214 | 214 | ->escaped() |
215 | 215 | ); |
216 | 216 | } |
@@ -223,21 +223,21 @@ discard block |
||
223 | 223 | * @throws ConstraintParameterException |
224 | 224 | * @return PropertyId |
225 | 225 | */ |
226 | - private function parsePropertyIdParameter( array $snakSerialization, $parameterId ) { |
|
227 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
228 | - $this->requireValueParameter( $snak, $parameterId ); |
|
226 | + private function parsePropertyIdParameter(array $snakSerialization, $parameterId) { |
|
227 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
228 | + $this->requireValueParameter($snak, $parameterId); |
|
229 | 229 | $value = $snak->getDataValue(); |
230 | - if ( $value instanceof EntityIdValue ) { |
|
230 | + if ($value instanceof EntityIdValue) { |
|
231 | 231 | $id = $value->getEntityId(); |
232 | - if ( $id instanceof PropertyId ) { |
|
232 | + if ($id instanceof PropertyId) { |
|
233 | 233 | return $id; |
234 | 234 | } |
235 | 235 | } |
236 | 236 | throw new ConstraintParameterException( |
237 | - wfMessage( 'wbqc-violation-message-parameter-property' ) |
|
237 | + wfMessage('wbqc-violation-message-parameter-property') |
|
238 | 238 | ->rawParams( |
239 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
240 | - $this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
239 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
240 | + $this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
241 | 241 | ) |
242 | 242 | ->escaped() |
243 | 243 | ); |
@@ -250,34 +250,34 @@ discard block |
||
250 | 250 | * @throws ConstraintParameterException if the parameter is invalid or missing |
251 | 251 | * @return PropertyId |
252 | 252 | */ |
253 | - public function parsePropertyParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
254 | - $this->checkError( $constraintParameters ); |
|
255 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
256 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
253 | + public function parsePropertyParameter(array $constraintParameters, $constraintTypeItemId) { |
|
254 | + $this->checkError($constraintParameters); |
|
255 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
256 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
257 | 257 | throw new ConstraintParameterException( |
258 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
259 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
260 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
258 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
259 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
260 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
261 | 261 | ->escaped() |
262 | 262 | ); |
263 | 263 | } |
264 | 264 | |
265 | - $this->requireSingleParameter( $constraintParameters, $propertyId ); |
|
266 | - return $this->parsePropertyIdParameter( $constraintParameters[$propertyId][0], $propertyId ); |
|
265 | + $this->requireSingleParameter($constraintParameters, $propertyId); |
|
266 | + return $this->parsePropertyIdParameter($constraintParameters[$propertyId][0], $propertyId); |
|
267 | 267 | } |
268 | 268 | |
269 | - private function parseItemIdParameter( PropertyValueSnak $snak, $parameterId ) { |
|
269 | + private function parseItemIdParameter(PropertyValueSnak $snak, $parameterId) { |
|
270 | 270 | $dataValue = $snak->getDataValue(); |
271 | - if ( $dataValue instanceof EntityIdValue && |
|
271 | + if ($dataValue instanceof EntityIdValue && |
|
272 | 272 | $dataValue->getEntityId() instanceof ItemId |
273 | 273 | ) { |
274 | - return ItemIdSnakValue::fromItemId( $dataValue->getEntityId() ); |
|
274 | + return ItemIdSnakValue::fromItemId($dataValue->getEntityId()); |
|
275 | 275 | } else { |
276 | 276 | throw new ConstraintParameterException( |
277 | - wfMessage( 'wbqc-violation-message-parameter-item' ) |
|
277 | + wfMessage('wbqc-violation-message-parameter-item') |
|
278 | 278 | ->rawParams( |
279 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
280 | - $this->constraintParameterRenderer->formatDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
279 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
280 | + $this->constraintParameterRenderer->formatDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
281 | 281 | ) |
282 | 282 | ->escaped() |
283 | 283 | ); |
@@ -291,15 +291,15 @@ discard block |
||
291 | 291 | * @throws ConstraintParameterException if the parameter is invalid or missing |
292 | 292 | * @return ItemIdSnakValue[] array of values |
293 | 293 | */ |
294 | - public function parseItemsParameter( array $constraintParameters, $constraintTypeItemId, $required ) { |
|
295 | - $this->checkError( $constraintParameters ); |
|
296 | - $qualifierId = $this->config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
297 | - if ( !array_key_exists( $qualifierId, $constraintParameters ) ) { |
|
298 | - if ( $required ) { |
|
294 | + public function parseItemsParameter(array $constraintParameters, $constraintTypeItemId, $required) { |
|
295 | + $this->checkError($constraintParameters); |
|
296 | + $qualifierId = $this->config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
297 | + if (!array_key_exists($qualifierId, $constraintParameters)) { |
|
298 | + if ($required) { |
|
299 | 299 | throw new ConstraintParameterException( |
300 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
301 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
302 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $qualifierId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
300 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
301 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
302 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($qualifierId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
303 | 303 | ->escaped() |
304 | 304 | ); |
305 | 305 | } else { |
@@ -308,11 +308,11 @@ discard block |
||
308 | 308 | } |
309 | 309 | |
310 | 310 | $values = []; |
311 | - foreach ( $constraintParameters[$qualifierId] as $parameter ) { |
|
312 | - $snak = $this->snakDeserializer->deserialize( $parameter ); |
|
313 | - switch ( true ) { |
|
311 | + foreach ($constraintParameters[$qualifierId] as $parameter) { |
|
312 | + $snak = $this->snakDeserializer->deserialize($parameter); |
|
313 | + switch (true) { |
|
314 | 314 | case $snak instanceof PropertyValueSnak: |
315 | - $values[] = $this->parseItemIdParameter( $snak, $qualifierId ); |
|
315 | + $values[] = $this->parseItemIdParameter($snak, $qualifierId); |
|
316 | 316 | break; |
317 | 317 | case $snak instanceof PropertySomeValueSnak: |
318 | 318 | $values[] = ItemIdSnakValue::someValue(); |
@@ -331,28 +331,28 @@ discard block |
||
331 | 331 | * @throws ConstraintParameterException if the parameter is invalid or missing |
332 | 332 | * @return PropertyId[] |
333 | 333 | */ |
334 | - public function parsePropertiesParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
335 | - $this->checkError( $constraintParameters ); |
|
336 | - $propertyId = $this->config->get( 'WBQualityConstraintsPropertyId' ); |
|
337 | - if ( !array_key_exists( $propertyId, $constraintParameters ) ) { |
|
334 | + public function parsePropertiesParameter(array $constraintParameters, $constraintTypeItemId) { |
|
335 | + $this->checkError($constraintParameters); |
|
336 | + $propertyId = $this->config->get('WBQualityConstraintsPropertyId'); |
|
337 | + if (!array_key_exists($propertyId, $constraintParameters)) { |
|
338 | 338 | throw new ConstraintParameterException( |
339 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
340 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
341 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
339 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
340 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
341 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($propertyId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
342 | 342 | ->escaped() |
343 | 343 | ); |
344 | 344 | } |
345 | 345 | |
346 | 346 | $parameters = $constraintParameters[$propertyId]; |
347 | - if ( count( $parameters ) === 1 && |
|
348 | - $this->snakDeserializer->deserialize( $parameters[0] ) instanceof PropertyNoValueSnak |
|
347 | + if (count($parameters) === 1 && |
|
348 | + $this->snakDeserializer->deserialize($parameters[0]) instanceof PropertyNoValueSnak |
|
349 | 349 | ) { |
350 | 350 | return []; |
351 | 351 | } |
352 | 352 | |
353 | 353 | $properties = []; |
354 | - foreach ( $parameters as $parameter ) { |
|
355 | - $properties[] = $this->parsePropertyIdParameter( $parameter, $propertyId ); |
|
354 | + foreach ($parameters as $parameter) { |
|
355 | + $properties[] = $this->parsePropertyIdParameter($parameter, $propertyId); |
|
356 | 356 | } |
357 | 357 | return $properties; |
358 | 358 | } |
@@ -363,16 +363,16 @@ discard block |
||
363 | 363 | * @throws ConstraintParameterException |
364 | 364 | * @return DataValue|null |
365 | 365 | */ |
366 | - private function parseValueOrNoValueParameter( array $snakSerialization, $parameterId ) { |
|
367 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
368 | - if ( $snak instanceof PropertyValueSnak ) { |
|
366 | + private function parseValueOrNoValueParameter(array $snakSerialization, $parameterId) { |
|
367 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
368 | + if ($snak instanceof PropertyValueSnak) { |
|
369 | 369 | return $snak->getDataValue(); |
370 | - } elseif ( $snak instanceof PropertyNoValueSnak ) { |
|
370 | + } elseif ($snak instanceof PropertyNoValueSnak) { |
|
371 | 371 | return null; |
372 | 372 | } else { |
373 | 373 | throw new ConstraintParameterException( |
374 | - wfMessage( 'wbqc-violation-message-parameter-value-or-novalue' ) |
|
375 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
374 | + wfMessage('wbqc-violation-message-parameter-value-or-novalue') |
|
375 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
376 | 376 | ->escaped() |
377 | 377 | ); |
378 | 378 | } |
@@ -383,10 +383,10 @@ discard block |
||
383 | 383 | * @param string $parameterId |
384 | 384 | * @return DataValue|null |
385 | 385 | */ |
386 | - private function parseValueOrNoValueOrNowParameter( array $snakSerialization, $parameterId ) { |
|
386 | + private function parseValueOrNoValueOrNowParameter(array $snakSerialization, $parameterId) { |
|
387 | 387 | try { |
388 | - return $this->parseValueOrNoValueParameter( $snakSerialization, $parameterId ); |
|
389 | - } catch ( ConstraintParameterException $e ) { |
|
388 | + return $this->parseValueOrNoValueParameter($snakSerialization, $parameterId); |
|
389 | + } catch (ConstraintParameterException $e) { |
|
390 | 390 | // unknown value means “now” |
391 | 391 | return new NowValue(); |
392 | 392 | } |
@@ -399,14 +399,14 @@ discard block |
||
399 | 399 | * @param string $unit |
400 | 400 | * @return bool |
401 | 401 | */ |
402 | - private function exactlyOneQuantityWithUnit( DataValue $min = null, DataValue $max = null, $unit ) { |
|
403 | - if ( !( $min instanceof UnboundedQuantityValue ) || |
|
404 | - !( $max instanceof UnboundedQuantityValue ) |
|
402 | + private function exactlyOneQuantityWithUnit(DataValue $min = null, DataValue $max = null, $unit) { |
|
403 | + if (!($min instanceof UnboundedQuantityValue) || |
|
404 | + !($max instanceof UnboundedQuantityValue) |
|
405 | 405 | ) { |
406 | 406 | return false; |
407 | 407 | } |
408 | 408 | |
409 | - return ( $min->getUnit() === $unit ) !== ( $max->getUnit() === $unit ); |
|
409 | + return ($min->getUnit() === $unit) !== ($max->getUnit() === $unit); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | /** |
@@ -417,9 +417,9 @@ discard block |
||
417 | 417 | * @throws ConstraintParameterException if the parameter is invalid or missing |
418 | 418 | * @return DataValue[] a pair of two data values, either of which may be null to signify an open range |
419 | 419 | */ |
420 | - public function parseRangeParameter( array $constraintParameters, $constraintTypeItemId, $type ) { |
|
421 | - $this->checkError( $constraintParameters ); |
|
422 | - switch ( $type ) { |
|
420 | + public function parseRangeParameter(array $constraintParameters, $constraintTypeItemId, $type) { |
|
421 | + $this->checkError($constraintParameters); |
|
422 | + switch ($type) { |
|
423 | 423 | case 'quantity': |
424 | 424 | $configKey = 'Quantity'; |
425 | 425 | break; |
@@ -428,58 +428,58 @@ discard block |
||
428 | 428 | break; |
429 | 429 | default: |
430 | 430 | throw new ConstraintParameterException( |
431 | - wfMessage( 'wbqc-violation-message-value-needed-of-types-2' ) |
|
431 | + wfMessage('wbqc-violation-message-value-needed-of-types-2') |
|
432 | 432 | ->rawParams( |
433 | - $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ), |
|
434 | - wfMessage( 'datatypes-type-quantity' )->escaped(), |
|
435 | - wfMessage( 'datatypes-type-time' )->escaped() |
|
433 | + $this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM), |
|
434 | + wfMessage('datatypes-type-quantity')->escaped(), |
|
435 | + wfMessage('datatypes-type-time')->escaped() |
|
436 | 436 | ) |
437 | 437 | ->escaped() |
438 | 438 | ); |
439 | 439 | } |
440 | - $minimumId = $this->config->get( 'WBQualityConstraintsMinimum' . $configKey . 'Id' ); |
|
441 | - $maximumId = $this->config->get( 'WBQualityConstraintsMaximum' . $configKey . 'Id' ); |
|
442 | - if ( !array_key_exists( $minimumId, $constraintParameters ) || |
|
443 | - !array_key_exists( $maximumId, $constraintParameters ) |
|
440 | + $minimumId = $this->config->get('WBQualityConstraintsMinimum'.$configKey.'Id'); |
|
441 | + $maximumId = $this->config->get('WBQualityConstraintsMaximum'.$configKey.'Id'); |
|
442 | + if (!array_key_exists($minimumId, $constraintParameters) || |
|
443 | + !array_key_exists($maximumId, $constraintParameters) |
|
444 | 444 | ) { |
445 | 445 | throw new ConstraintParameterException( |
446 | - wfMessage( 'wbqc-violation-message-range-parameters-needed' ) |
|
446 | + wfMessage('wbqc-violation-message-range-parameters-needed') |
|
447 | 447 | ->rawParams( |
448 | - wfMessage( 'datatypes-type-' . $type )->escaped(), |
|
449 | - $this->constraintParameterRenderer->formatPropertyId( $minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
450 | - $this->constraintParameterRenderer->formatPropertyId( $maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
448 | + wfMessage('datatypes-type-'.$type)->escaped(), |
|
449 | + $this->constraintParameterRenderer->formatPropertyId($minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
450 | + $this->constraintParameterRenderer->formatPropertyId($maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
451 | 451 | ) |
452 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
452 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
453 | 453 | ->escaped() |
454 | 454 | ); |
455 | 455 | } |
456 | 456 | |
457 | - $this->requireSingleParameter( $constraintParameters, $minimumId ); |
|
458 | - $this->requireSingleParameter( $constraintParameters, $maximumId ); |
|
457 | + $this->requireSingleParameter($constraintParameters, $minimumId); |
|
458 | + $this->requireSingleParameter($constraintParameters, $maximumId); |
|
459 | 459 | $parseFunction = $configKey === 'Date' ? 'parseValueOrNoValueOrNowParameter' : 'parseValueOrNoValueParameter'; |
460 | - $min = $this->$parseFunction( $constraintParameters[$minimumId][0], $minimumId ); |
|
461 | - $max = $this->$parseFunction( $constraintParameters[$maximumId][0], $maximumId ); |
|
460 | + $min = $this->$parseFunction($constraintParameters[$minimumId][0], $minimumId); |
|
461 | + $max = $this->$parseFunction($constraintParameters[$maximumId][0], $maximumId); |
|
462 | 462 | |
463 | - $yearUnit = $this->config->get( 'WBQualityConstraintsYearUnit' ); |
|
464 | - if ( $this->exactlyOneQuantityWithUnit( $min, $max, $yearUnit ) ) { |
|
463 | + $yearUnit = $this->config->get('WBQualityConstraintsYearUnit'); |
|
464 | + if ($this->exactlyOneQuantityWithUnit($min, $max, $yearUnit)) { |
|
465 | 465 | throw new ConstraintParameterException( |
466 | - wfMessage( 'wbqc-violation-message-range-parameters-one-year' ) |
|
466 | + wfMessage('wbqc-violation-message-range-parameters-one-year') |
|
467 | 467 | ->escaped() |
468 | 468 | ); |
469 | 469 | } |
470 | - if ( $min === null && $max === null || |
|
471 | - $min !== null && $max !== null && $min->equals( $max ) ) { |
|
470 | + if ($min === null && $max === null || |
|
471 | + $min !== null && $max !== null && $min->equals($max)) { |
|
472 | 472 | throw new ConstraintParameterException( |
473 | - wfMessage( 'wbqc-violation-message-range-parameters-same' ) |
|
473 | + wfMessage('wbqc-violation-message-range-parameters-same') |
|
474 | 474 | ->rawParams( |
475 | - $this->constraintParameterRenderer->formatPropertyId( $minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
476 | - $this->constraintParameterRenderer->formatPropertyId( $maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
475 | + $this->constraintParameterRenderer->formatPropertyId($minimumId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
476 | + $this->constraintParameterRenderer->formatPropertyId($maximumId, Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
477 | 477 | ) |
478 | 478 | ->escaped() |
479 | 479 | ); |
480 | 480 | } |
481 | 481 | |
482 | - return [ $min, $max ]; |
|
482 | + return [$min, $max]; |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
@@ -489,18 +489,18 @@ discard block |
||
489 | 489 | * @throws ConstraintParameterException |
490 | 490 | * @return string |
491 | 491 | */ |
492 | - private function parseStringParameter( array $snakSerialization, $parameterId ) { |
|
493 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
494 | - $this->requireValueParameter( $snak, $parameterId ); |
|
492 | + private function parseStringParameter(array $snakSerialization, $parameterId) { |
|
493 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
494 | + $this->requireValueParameter($snak, $parameterId); |
|
495 | 495 | $value = $snak->getDataValue(); |
496 | - if ( $value instanceof StringValue ) { |
|
496 | + if ($value instanceof StringValue) { |
|
497 | 497 | return $value->getValue(); |
498 | 498 | } else { |
499 | 499 | throw new ConstraintParameterException( |
500 | - wfMessage( 'wbqc-violation-message-parameter-string' ) |
|
500 | + wfMessage('wbqc-violation-message-parameter-string') |
|
501 | 501 | ->rawParams( |
502 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
503 | - $this->constraintParameterRenderer->formatDataValue( $value, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
502 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
503 | + $this->constraintParameterRenderer->formatDataValue($value, Role::CONSTRAINT_PARAMETER_VALUE) |
|
504 | 504 | ) |
505 | 505 | ->escaped() |
506 | 506 | ); |
@@ -513,15 +513,15 @@ discard block |
||
513 | 513 | * @throws ConstraintParameterException if the parameter is invalid or missing |
514 | 514 | * @return string |
515 | 515 | */ |
516 | - public function parseNamespaceParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
517 | - $this->checkError( $constraintParameters ); |
|
518 | - $namespaceId = $this->config->get( 'WBQualityConstraintsNamespaceId' ); |
|
519 | - if ( !array_key_exists( $namespaceId, $constraintParameters ) ) { |
|
516 | + public function parseNamespaceParameter(array $constraintParameters, $constraintTypeItemId) { |
|
517 | + $this->checkError($constraintParameters); |
|
518 | + $namespaceId = $this->config->get('WBQualityConstraintsNamespaceId'); |
|
519 | + if (!array_key_exists($namespaceId, $constraintParameters)) { |
|
520 | 520 | return ''; |
521 | 521 | } |
522 | 522 | |
523 | - $this->requireSingleParameter( $constraintParameters, $namespaceId ); |
|
524 | - return $this->parseStringParameter( $constraintParameters[$namespaceId][0], $namespaceId ); |
|
523 | + $this->requireSingleParameter($constraintParameters, $namespaceId); |
|
524 | + return $this->parseStringParameter($constraintParameters[$namespaceId][0], $namespaceId); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
@@ -530,20 +530,20 @@ discard block |
||
530 | 530 | * @throws ConstraintParameterException if the parameter is invalid or missing |
531 | 531 | * @return string |
532 | 532 | */ |
533 | - public function parseFormatParameter( array $constraintParameters, $constraintTypeItemId ) { |
|
534 | - $this->checkError( $constraintParameters ); |
|
535 | - $formatId = $this->config->get( 'WBQualityConstraintsFormatAsARegularExpressionId' ); |
|
536 | - if ( !array_key_exists( $formatId, $constraintParameters ) ) { |
|
533 | + public function parseFormatParameter(array $constraintParameters, $constraintTypeItemId) { |
|
534 | + $this->checkError($constraintParameters); |
|
535 | + $formatId = $this->config->get('WBQualityConstraintsFormatAsARegularExpressionId'); |
|
536 | + if (!array_key_exists($formatId, $constraintParameters)) { |
|
537 | 537 | throw new ConstraintParameterException( |
538 | - wfMessage( 'wbqc-violation-message-parameter-needed' ) |
|
539 | - ->rawParams( $this->constraintParameterRenderer->formatItemId( $constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM ) ) |
|
540 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $formatId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
538 | + wfMessage('wbqc-violation-message-parameter-needed') |
|
539 | + ->rawParams($this->constraintParameterRenderer->formatItemId($constraintTypeItemId, Role::CONSTRAINT_TYPE_ITEM)) |
|
540 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($formatId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
541 | 541 | ->escaped() |
542 | 542 | ); |
543 | 543 | } |
544 | 544 | |
545 | - $this->requireSingleParameter( $constraintParameters, $formatId ); |
|
546 | - return $this->parseStringParameter( $constraintParameters[$formatId][0], $formatId ); |
|
545 | + $this->requireSingleParameter($constraintParameters, $formatId); |
|
546 | + return $this->parseStringParameter($constraintParameters[$formatId][0], $formatId); |
|
547 | 547 | } |
548 | 548 | |
549 | 549 | /** |
@@ -551,16 +551,16 @@ discard block |
||
551 | 551 | * @throws ConstraintParameterException if the parameter is invalid |
552 | 552 | * @return EntityId[] |
553 | 553 | */ |
554 | - public function parseExceptionParameter( array $constraintParameters ) { |
|
555 | - $this->checkError( $constraintParameters ); |
|
556 | - $exceptionId = $this->config->get( 'WBQualityConstraintsExceptionToConstraintId' ); |
|
557 | - if ( !array_key_exists( $exceptionId, $constraintParameters ) ) { |
|
554 | + public function parseExceptionParameter(array $constraintParameters) { |
|
555 | + $this->checkError($constraintParameters); |
|
556 | + $exceptionId = $this->config->get('WBQualityConstraintsExceptionToConstraintId'); |
|
557 | + if (!array_key_exists($exceptionId, $constraintParameters)) { |
|
558 | 558 | return []; |
559 | 559 | } |
560 | 560 | |
561 | 561 | return array_map( |
562 | - function( $snakSerialization ) use ( $exceptionId ) { |
|
563 | - return $this->parseEntityIdParameter( $snakSerialization, $exceptionId ); |
|
562 | + function($snakSerialization) use ($exceptionId) { |
|
563 | + return $this->parseEntityIdParameter($snakSerialization, $exceptionId); |
|
564 | 564 | }, |
565 | 565 | $constraintParameters[$exceptionId] |
566 | 566 | ); |
@@ -571,27 +571,27 @@ discard block |
||
571 | 571 | * @throws ConstraintParameterException if the parameter is invalid |
572 | 572 | * @return string|null 'mandatory' or null |
573 | 573 | */ |
574 | - public function parseConstraintStatusParameter( array $constraintParameters ) { |
|
575 | - $this->checkError( $constraintParameters ); |
|
576 | - $constraintStatusId = $this->config->get( 'WBQualityConstraintsConstraintStatusId' ); |
|
577 | - if ( !array_key_exists( $constraintStatusId, $constraintParameters ) ) { |
|
574 | + public function parseConstraintStatusParameter(array $constraintParameters) { |
|
575 | + $this->checkError($constraintParameters); |
|
576 | + $constraintStatusId = $this->config->get('WBQualityConstraintsConstraintStatusId'); |
|
577 | + if (!array_key_exists($constraintStatusId, $constraintParameters)) { |
|
578 | 578 | return null; |
579 | 579 | } |
580 | 580 | |
581 | - $mandatoryId = $this->config->get( 'WBQualityConstraintsMandatoryConstraintId' ); |
|
582 | - $this->requireSingleParameter( $constraintParameters, $constraintStatusId ); |
|
583 | - $snak = $this->snakDeserializer->deserialize( $constraintParameters[$constraintStatusId][0] ); |
|
584 | - $this->requireValueParameter( $snak, $constraintStatusId ); |
|
581 | + $mandatoryId = $this->config->get('WBQualityConstraintsMandatoryConstraintId'); |
|
582 | + $this->requireSingleParameter($constraintParameters, $constraintStatusId); |
|
583 | + $snak = $this->snakDeserializer->deserialize($constraintParameters[$constraintStatusId][0]); |
|
584 | + $this->requireValueParameter($snak, $constraintStatusId); |
|
585 | 585 | $statusId = $snak->getDataValue()->getEntityId()->getSerialization(); |
586 | 586 | |
587 | - if ( $statusId === $mandatoryId ) { |
|
587 | + if ($statusId === $mandatoryId) { |
|
588 | 588 | return 'mandatory'; |
589 | 589 | } else { |
590 | 590 | throw new ConstraintParameterException( |
591 | - wfMessage( 'wbqc-violation-message-parameter-oneof' ) |
|
592 | - ->rawParams( $this->constraintParameterRenderer->formatPropertyId( $constraintStatusId, Role::CONSTRAINT_PARAMETER_PROPERTY ) ) |
|
593 | - ->numParams( 1 ) |
|
594 | - ->rawParams( $this->constraintParameterRenderer->formatItemIdList( [ $mandatoryId ], Role::CONSTRAINT_PARAMETER_VALUE ) ) |
|
591 | + wfMessage('wbqc-violation-message-parameter-oneof') |
|
592 | + ->rawParams($this->constraintParameterRenderer->formatPropertyId($constraintStatusId, Role::CONSTRAINT_PARAMETER_PROPERTY)) |
|
593 | + ->numParams(1) |
|
594 | + ->rawParams($this->constraintParameterRenderer->formatItemIdList([$mandatoryId], Role::CONSTRAINT_PARAMETER_VALUE)) |
|
595 | 595 | ->escaped() |
596 | 596 | ); |
597 | 597 | } |
@@ -604,13 +604,13 @@ discard block |
||
604 | 604 | * @return void |
605 | 605 | * @throws ConstraintParameterException |
606 | 606 | */ |
607 | - private function requireMonolingualTextParameter( DataValue $dataValue, $parameterId ) { |
|
608 | - if ( !( $dataValue instanceof MonolingualTextValue ) ) { |
|
607 | + private function requireMonolingualTextParameter(DataValue $dataValue, $parameterId) { |
|
608 | + if (!($dataValue instanceof MonolingualTextValue)) { |
|
609 | 609 | throw new ConstraintParameterException( |
610 | - wfMessage( 'wbqc-violation-message-parameter-monolingualtext' ) |
|
610 | + wfMessage('wbqc-violation-message-parameter-monolingualtext') |
|
611 | 611 | ->rawParams( |
612 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ), |
|
613 | - $this->constraintParameterRenderer->formatDataValue( $dataValue, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
612 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY), |
|
613 | + $this->constraintParameterRenderer->formatDataValue($dataValue, Role::CONSTRAINT_PARAMETER_VALUE) |
|
614 | 614 | ) |
615 | 615 | ->escaped() |
616 | 616 | ); |
@@ -625,26 +625,26 @@ discard block |
||
625 | 625 | * @throws ConstraintParameterException if invalid snaks are found or a language has multiple texts |
626 | 626 | * @return MultilingualTextValue |
627 | 627 | */ |
628 | - private function parseMultilingualTextParameter( array $snakSerializations, $parameterId ) { |
|
628 | + private function parseMultilingualTextParameter(array $snakSerializations, $parameterId) { |
|
629 | 629 | $result = []; |
630 | 630 | |
631 | - foreach ( $snakSerializations as $snakSerialization ) { |
|
632 | - $snak = $this->snakDeserializer->deserialize( $snakSerialization ); |
|
633 | - $this->requireValueParameter( $snak, $parameterId ); |
|
631 | + foreach ($snakSerializations as $snakSerialization) { |
|
632 | + $snak = $this->snakDeserializer->deserialize($snakSerialization); |
|
633 | + $this->requireValueParameter($snak, $parameterId); |
|
634 | 634 | |
635 | 635 | $value = $snak->getDataValue(); |
636 | - $this->requireMonolingualTextParameter( $value, $parameterId ); |
|
636 | + $this->requireMonolingualTextParameter($value, $parameterId); |
|
637 | 637 | /** @var MonolingualTextValue $value */ |
638 | 638 | |
639 | 639 | $code = $value->getLanguageCode(); |
640 | - if ( array_key_exists( $code, $result ) ) { |
|
640 | + if (array_key_exists($code, $result)) { |
|
641 | 641 | throw new ConstraintParameterException( |
642 | - wfMessage( 'wbqc-violation-message-parameter-single-per-language' ) |
|
642 | + wfMessage('wbqc-violation-message-parameter-single-per-language') |
|
643 | 643 | ->rawParams( |
644 | - $this->constraintParameterRenderer->formatPropertyId( $parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY ) |
|
644 | + $this->constraintParameterRenderer->formatPropertyId($parameterId, Role::CONSTRAINT_PARAMETER_PROPERTY) |
|
645 | 645 | ) |
646 | 646 | ->plaintextParams( |
647 | - Language::fetchLanguageName( $code ), |
|
647 | + Language::fetchLanguageName($code), |
|
648 | 648 | $code |
649 | 649 | ) |
650 | 650 | ->escaped() |
@@ -654,7 +654,7 @@ discard block |
||
654 | 654 | $result[$code] = $value; |
655 | 655 | } |
656 | 656 | |
657 | - return new MultilingualTextValue( $result ); |
|
657 | + return new MultilingualTextValue($result); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | /** |
@@ -662,11 +662,11 @@ discard block |
||
662 | 662 | * @throws ConstraintParameterException if the parameter is invalid |
663 | 663 | * @return MultilingualTextValue |
664 | 664 | */ |
665 | - public function parseSyntaxClarificationParameter( array $constraintParameters ) { |
|
666 | - $syntaxClarificationId = $this->config->get( 'WBQualityConstraintsSyntaxClarificationId' ); |
|
665 | + public function parseSyntaxClarificationParameter(array $constraintParameters) { |
|
666 | + $syntaxClarificationId = $this->config->get('WBQualityConstraintsSyntaxClarificationId'); |
|
667 | 667 | |
668 | - if ( !array_key_exists( $syntaxClarificationId, $constraintParameters ) ) { |
|
669 | - return new MultilingualTextValue( [] ); |
|
668 | + if (!array_key_exists($syntaxClarificationId, $constraintParameters)) { |
|
669 | + return new MultilingualTextValue([]); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | $syntaxClarifications = $this->parseMultilingualTextParameter( |
@@ -685,20 +685,20 @@ discard block |
||
685 | 685 | * @throws ConstraintParameterException if the parameter is invalid |
686 | 686 | * @return string[]|null Context::TYPE_* constants |
687 | 687 | */ |
688 | - public function parseConstraintScopeParameter( array $constraintParameters, $constraintTypeItemId, array $validScopes = null ) { |
|
689 | - $constraintScopeId = $this->config->get( 'WBQualityConstraintsConstraintScopeId' ); |
|
690 | - $mainSnakId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnMainValueId' ); |
|
691 | - $qualifiersId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnQualifiersId' ); |
|
692 | - $referencesId = $this->config->get( 'WBQualityConstraintsConstraintCheckedOnReferencesId' ); |
|
688 | + public function parseConstraintScopeParameter(array $constraintParameters, $constraintTypeItemId, array $validScopes = null) { |
|
689 | + $constraintScopeId = $this->config->get('WBQualityConstraintsConstraintScopeId'); |
|
690 | + $mainSnakId = $this->config->get('WBQualityConstraintsConstraintCheckedOnMainValueId'); |
|
691 | + $qualifiersId = $this->config->get('WBQualityConstraintsConstraintCheckedOnQualifiersId'); |
|
692 | + $referencesId = $this->config->get('WBQualityConstraintsConstraintCheckedOnReferencesId'); |
|
693 | 693 | |
694 | - if ( !array_key_exists( $constraintScopeId, $constraintParameters ) ) { |
|
694 | + if (!array_key_exists($constraintScopeId, $constraintParameters)) { |
|
695 | 695 | return null; |
696 | 696 | } |
697 | 697 | |
698 | 698 | $contextTypes = []; |
699 | - foreach ( $constraintParameters[$constraintScopeId] as $snakSerialization ) { |
|
700 | - $scopeEntityId = $this->parseEntityIdParameter( $snakSerialization, $constraintScopeId ); |
|
701 | - switch ( $scopeEntityId->getSerialization() ) { |
|
699 | + foreach ($constraintParameters[$constraintScopeId] as $snakSerialization) { |
|
700 | + $scopeEntityId = $this->parseEntityIdParameter($snakSerialization, $constraintScopeId); |
|
701 | + switch ($scopeEntityId->getSerialization()) { |
|
702 | 702 | case $mainSnakId: |
703 | 703 | $contextTypes[] = Context::TYPE_STATEMENT; |
704 | 704 | break; |
@@ -710,14 +710,14 @@ discard block |
||
710 | 710 | break; |
711 | 711 | default: |
712 | 712 | throw new ConstraintParameterException( |
713 | - wfMessage( 'wbqc-violation-message-parameter-oneof' ) |
|
713 | + wfMessage('wbqc-violation-message-parameter-oneof') |
|
714 | 714 | ->rawParams( |
715 | 715 | $this->constraintParameterRenderer->formatPropertyId( |
716 | 716 | $constraintScopeId, |
717 | 717 | Role::CONSTRAINT_PARAMETER_PROPERTY |
718 | 718 | ) |
719 | 719 | ) |
720 | - ->numParams( 3 ) |
|
720 | + ->numParams(3) |
|
721 | 721 | ->rawParams( |
722 | 722 | $this->constraintParameterRenderer->formatItemIdList( |
723 | 723 | [ |
@@ -733,12 +733,12 @@ discard block |
||
733 | 733 | } |
734 | 734 | } |
735 | 735 | |
736 | - if ( $validScopes !== null ) { |
|
737 | - $invalidScopes = array_diff( $contextTypes, $validScopes ); |
|
738 | - if ( $invalidScopes !== [] ) { |
|
739 | - $invalidScope = array_pop( $invalidScopes ); |
|
736 | + if ($validScopes !== null) { |
|
737 | + $invalidScopes = array_diff($contextTypes, $validScopes); |
|
738 | + if ($invalidScopes !== []) { |
|
739 | + $invalidScope = array_pop($invalidScopes); |
|
740 | 740 | throw new ConstraintParameterException( |
741 | - wfMessage( 'wbqc-violation-message-invalid-scope' ) |
|
741 | + wfMessage('wbqc-violation-message-invalid-scope') |
|
742 | 742 | ->rawParams( |
743 | 743 | $this->constraintParameterRenderer->formatConstraintScope( |
744 | 744 | $invalidScope, |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | Role::CONSTRAINT_TYPE_ITEM |
750 | 750 | ) |
751 | 751 | ) |
752 | - ->numParams( count( $validScopes ) ) |
|
752 | + ->numParams(count($validScopes)) |
|
753 | 753 | ->rawParams( |
754 | 754 | $this->constraintParameterRenderer->formatConstraintScopeList( |
755 | 755 | $validScopes, |
@@ -28,15 +28,15 @@ |
||
28 | 28 | * @return string |
29 | 29 | */ |
30 | 30 | public function getTime() { |
31 | - return gmdate( '+Y-m-d\TH:i:s\Z' ); |
|
31 | + return gmdate('+Y-m-d\TH:i:s\Z'); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | public function getArrayValue() { |
35 | - throw new LogicException( 'NowValue should never be serialized' ); |
|
35 | + throw new LogicException('NowValue should never be serialized'); |
|
36 | 36 | } |
37 | 37 | |
38 | - public function equals( $value ) { |
|
39 | - return get_class( $value ) === self::class; |
|
38 | + public function equals($value) { |
|
39 | + return get_class($value) === self::class; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | } |
@@ -88,9 +88,9 @@ discard block |
||
88 | 88 | * @throws ConstraintParameterException |
89 | 89 | * @return CheckResult |
90 | 90 | */ |
91 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
92 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
93 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
91 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
92 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
93 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | $parameters = []; |
@@ -98,28 +98,28 @@ discard block |
||
98 | 98 | |
99 | 99 | $snak = $context->getSnak(); |
100 | 100 | |
101 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
101 | + if (!$snak instanceof PropertyValueSnak) { |
|
102 | 102 | // nothing to check |
103 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
103 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | $dataValue = $snak->getDataValue(); |
107 | 107 | |
108 | - list( $min, $max ) = $this->constraintParameterParser->parseRangeParameter( |
|
108 | + list($min, $max) = $this->constraintParameterParser->parseRangeParameter( |
|
109 | 109 | $constraintParameters, |
110 | 110 | $constraint->getConstraintTypeItemId(), |
111 | 111 | $dataValue->getType() |
112 | 112 | ); |
113 | 113 | $parameterKey = $dataValue->getType() === 'quantity' ? 'quantity' : 'date'; |
114 | - if ( $min !== null ) { |
|
115 | - $parameters['minimum_' . $parameterKey] = [ $min ]; |
|
114 | + if ($min !== null) { |
|
115 | + $parameters['minimum_'.$parameterKey] = [$min]; |
|
116 | 116 | } |
117 | - if ( $max !== null ) { |
|
118 | - $parameters['maximum_' . $parameterKey] = [ $max ]; |
|
117 | + if ($max !== null) { |
|
118 | + $parameters['maximum_'.$parameterKey] = [$max]; |
|
119 | 119 | } |
120 | 120 | |
121 | - if ( $this->rangeCheckerHelper->getComparison( $min, $dataValue ) > 0 || |
|
122 | - $this->rangeCheckerHelper->getComparison( $dataValue, $max ) > 0 |
|
121 | + if ($this->rangeCheckerHelper->getComparison($min, $dataValue) > 0 || |
|
122 | + $this->rangeCheckerHelper->getComparison($dataValue, $max) > 0 |
|
123 | 123 | ) { |
124 | 124 | $message = $this->getViolationMessage( |
125 | 125 | $context->getSnak()->getPropertyId(), |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | $status = CheckResult::STATUS_COMPLIANCE; |
134 | 134 | } |
135 | 135 | |
136 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
136 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * |
145 | 145 | * @return ViolationMessage |
146 | 146 | */ |
147 | - private function getViolationMessage( PropertyId $predicate, DataValue $value, $min, $max ) { |
|
147 | + private function getViolationMessage(PropertyId $predicate, DataValue $value, $min, $max) { |
|
148 | 148 | // possible message keys: |
149 | 149 | // wbqc-violation-message-range-quantity-closed |
150 | 150 | // wbqc-violation-message-range-quantity-leftopen |
@@ -157,39 +157,39 @@ discard block |
||
157 | 157 | // wbqc-violation-message-range-time-rightopen |
158 | 158 | // wbqc-violation-message-range-time-rightopen-leftnow |
159 | 159 | $messageKey = 'wbqc-violation-message-range'; |
160 | - $messageKey .= '-' . $value->getType(); |
|
160 | + $messageKey .= '-'.$value->getType(); |
|
161 | 161 | // at least one of $min, $max is set, otherwise there could be no violation |
162 | - $messageKey .= '-' . ( $min !== null ? ( $max !== null ? 'closed' : 'rightopen' ) : 'leftopen' ); |
|
163 | - if ( $min instanceof NowValue ) { |
|
162 | + $messageKey .= '-'.($min !== null ? ($max !== null ? 'closed' : 'rightopen') : 'leftopen'); |
|
163 | + if ($min instanceof NowValue) { |
|
164 | 164 | $messageKey .= '-leftnow'; |
165 | - } elseif ( $max instanceof NowValue ) { |
|
165 | + } elseif ($max instanceof NowValue) { |
|
166 | 166 | $messageKey .= '-rightnow'; |
167 | 167 | } |
168 | - $message = ( new ViolationMessage( $messageKey ) ) |
|
169 | - ->withEntityId( $predicate, Role::PREDICATE ) |
|
170 | - ->withDataValue( $value, Role::OBJECT ); |
|
171 | - if ( $min !== null && !( $min instanceof NowValue ) ) { |
|
172 | - $message = $message->withDataValue( $min, Role::OBJECT ); |
|
168 | + $message = (new ViolationMessage($messageKey)) |
|
169 | + ->withEntityId($predicate, Role::PREDICATE) |
|
170 | + ->withDataValue($value, Role::OBJECT); |
|
171 | + if ($min !== null && !($min instanceof NowValue)) { |
|
172 | + $message = $message->withDataValue($min, Role::OBJECT); |
|
173 | 173 | } |
174 | - if ( $max !== null && !( $max instanceof NowValue ) ) { |
|
175 | - $message = $message->withDataValue( $max, Role::OBJECT ); |
|
174 | + if ($max !== null && !($max instanceof NowValue)) { |
|
175 | + $message = $message->withDataValue($max, Role::OBJECT); |
|
176 | 176 | } |
177 | 177 | return $message; |
178 | 178 | } |
179 | 179 | |
180 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
180 | + public function checkConstraintParameters(Constraint $constraint) { |
|
181 | 181 | $constraintParameters = $constraint->getConstraintParameters(); |
182 | 182 | $exceptions = []; |
183 | 183 | try { |
184 | 184 | // we don’t have a data value here, so get the type from the property instead |
185 | 185 | // (the distinction between data type and data value type is irrelevant for 'quantity' and 'time') |
186 | - $type = $this->propertyDataTypeLookup->getDataTypeIdForProperty( $constraint->getPropertyId() ); |
|
186 | + $type = $this->propertyDataTypeLookup->getDataTypeIdForProperty($constraint->getPropertyId()); |
|
187 | 187 | $this->constraintParameterParser->parseRangeParameter( |
188 | 188 | $constraintParameters, |
189 | 189 | $constraint->getConstraintTypeItemId(), |
190 | 190 | $type |
191 | 191 | ); |
192 | - } catch ( ConstraintParameterException $e ) { |
|
192 | + } catch (ConstraintParameterException $e) { |
|
193 | 193 | $exceptions[] = $e; |
194 | 194 | } |
195 | 195 | return $exceptions; |