@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | StatementGuidParser $statementGuidParser, |
104 | 104 | IBufferingStatsdDataFactory $dataFactory |
105 | 105 | ) { |
106 | - parent::__construct( $main, $name ); |
|
106 | + parent::__construct($main, $name); |
|
107 | 107 | |
108 | - $this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
108 | + $this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this); |
|
109 | 109 | $this->delegatingConstraintChecker = $delegatingConstraintChecker; |
110 | 110 | $this->violationMessageRendererFactory = $violationMessageRendererFactory; |
111 | 111 | $this->statementGuidParser = $statementGuidParser; |
@@ -120,39 +120,39 @@ discard block |
||
120 | 120 | $params = $this->extractRequestParams(); |
121 | 121 | $result = $this->getResult(); |
122 | 122 | |
123 | - $propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] ); |
|
124 | - $constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] ); |
|
123 | + $propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]); |
|
124 | + $constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]); |
|
125 | 125 | |
126 | - $this->checkPropertyIds( $propertyIds, $result ); |
|
127 | - $this->checkConstraintIds( $constraintIds, $result ); |
|
126 | + $this->checkPropertyIds($propertyIds, $result); |
|
127 | + $this->checkConstraintIds($constraintIds, $result); |
|
128 | 128 | |
129 | - $result->addValue( null, 'success', 1 ); |
|
129 | + $result->addValue(null, 'success', 1); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
133 | 133 | * @param array|null $propertyIdSerializations |
134 | 134 | * @return PropertyId[] |
135 | 135 | */ |
136 | - private function parsePropertyIds( $propertyIdSerializations ) { |
|
137 | - if ( $propertyIdSerializations === null ) { |
|
136 | + private function parsePropertyIds($propertyIdSerializations) { |
|
137 | + if ($propertyIdSerializations === null) { |
|
138 | 138 | return []; |
139 | - } elseif ( empty( $propertyIdSerializations ) ) { |
|
139 | + } elseif (empty($propertyIdSerializations)) { |
|
140 | 140 | $this->apiErrorReporter->dieError( |
141 | - 'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.', |
|
141 | + 'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.', |
|
142 | 142 | 'no-data' |
143 | 143 | ); |
144 | 144 | } |
145 | 145 | |
146 | 146 | return array_map( |
147 | - function ( $propertyIdSerialization ) { |
|
147 | + function($propertyIdSerialization) { |
|
148 | 148 | try { |
149 | - return new NumericPropertyId( $propertyIdSerialization ); |
|
150 | - } catch ( InvalidArgumentException $e ) { |
|
149 | + return new NumericPropertyId($propertyIdSerialization); |
|
150 | + } catch (InvalidArgumentException $e) { |
|
151 | 151 | $this->apiErrorReporter->dieError( |
152 | 152 | "Invalid id: $propertyIdSerialization", |
153 | 153 | 'invalid-property-id', |
154 | 154 | 0, // default argument |
155 | - [ self::PARAM_PROPERTY_ID => $propertyIdSerialization ] |
|
155 | + [self::PARAM_PROPERTY_ID => $propertyIdSerialization] |
|
156 | 156 | ); |
157 | 157 | } |
158 | 158 | }, |
@@ -164,35 +164,35 @@ discard block |
||
164 | 164 | * @param array|null $constraintIds |
165 | 165 | * @return string[] |
166 | 166 | */ |
167 | - private function parseConstraintIds( $constraintIds ) { |
|
168 | - if ( $constraintIds === null ) { |
|
167 | + private function parseConstraintIds($constraintIds) { |
|
168 | + if ($constraintIds === null) { |
|
169 | 169 | return []; |
170 | - } elseif ( empty( $constraintIds ) ) { |
|
170 | + } elseif (empty($constraintIds)) { |
|
171 | 171 | $this->apiErrorReporter->dieError( |
172 | - 'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.', |
|
172 | + 'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.', |
|
173 | 173 | 'no-data' |
174 | 174 | ); |
175 | 175 | } |
176 | 176 | |
177 | 177 | return array_map( |
178 | - function ( $constraintId ) { |
|
178 | + function($constraintId) { |
|
179 | 179 | try { |
180 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
181 | - if ( !$propertyId instanceof PropertyId ) { |
|
180 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
181 | + if (!$propertyId instanceof PropertyId) { |
|
182 | 182 | $this->apiErrorReporter->dieError( |
183 | 183 | "Invalid property ID: {$propertyId->getSerialization()}", |
184 | 184 | 'invalid-property-id', |
185 | 185 | 0, // default argument |
186 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
186 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
187 | 187 | ); |
188 | 188 | } |
189 | 189 | return $constraintId; |
190 | - } catch ( StatementGuidParsingException $e ) { |
|
190 | + } catch (StatementGuidParsingException $e) { |
|
191 | 191 | $this->apiErrorReporter->dieError( |
192 | 192 | "Invalid statement GUID: $constraintId", |
193 | 193 | 'invalid-guid', |
194 | 194 | 0, // default argument |
195 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
195 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
196 | 196 | ); |
197 | 197 | } |
198 | 198 | }, |
@@ -204,12 +204,12 @@ discard block |
||
204 | 204 | * @param PropertyId[] $propertyIds |
205 | 205 | * @param ApiResult $result |
206 | 206 | */ |
207 | - private function checkPropertyIds( array $propertyIds, ApiResult $result ) { |
|
208 | - foreach ( $propertyIds as $propertyId ) { |
|
209 | - $result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' ); |
|
207 | + private function checkPropertyIds(array $propertyIds, ApiResult $result) { |
|
208 | + foreach ($propertyIds as $propertyId) { |
|
209 | + $result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc'); |
|
210 | 210 | $allConstraintExceptions = $this->delegatingConstraintChecker |
211 | - ->checkConstraintParametersOnPropertyId( $propertyId ); |
|
212 | - foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) { |
|
211 | + ->checkConstraintParametersOnPropertyId($propertyId); |
|
212 | + foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) { |
|
213 | 213 | $this->addConstraintParameterExceptionsToResult( |
214 | 214 | $constraintId, |
215 | 215 | $constraintParameterExceptions, |
@@ -223,15 +223,15 @@ discard block |
||
223 | 223 | * @param string[] $constraintIds |
224 | 224 | * @param ApiResult $result |
225 | 225 | */ |
226 | - private function checkConstraintIds( array $constraintIds, ApiResult $result ) { |
|
227 | - foreach ( $constraintIds as $constraintId ) { |
|
228 | - if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) { |
|
226 | + private function checkConstraintIds(array $constraintIds, ApiResult $result) { |
|
227 | + foreach ($constraintIds as $constraintId) { |
|
228 | + if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) { |
|
229 | 229 | // already checked as part of checkPropertyIds() |
230 | 230 | continue; |
231 | 231 | } |
232 | 232 | $constraintParameterExceptions = $this->delegatingConstraintChecker |
233 | - ->checkConstraintParametersOnConstraintId( $constraintId ); |
|
234 | - $this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result ); |
|
233 | + ->checkConstraintParametersOnConstraintId($constraintId); |
|
234 | + $this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result); |
|
235 | 235 | } |
236 | 236 | } |
237 | 237 | |
@@ -239,18 +239,18 @@ discard block |
||
239 | 239 | * @param PropertyId $propertyId |
240 | 240 | * @return string[] |
241 | 241 | */ |
242 | - private function getResultPathForPropertyId( PropertyId $propertyId ) { |
|
243 | - return [ $this->getModuleName(), $propertyId->getSerialization() ]; |
|
242 | + private function getResultPathForPropertyId(PropertyId $propertyId) { |
|
243 | + return [$this->getModuleName(), $propertyId->getSerialization()]; |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
247 | 247 | * @param string $constraintId |
248 | 248 | * @return string[] |
249 | 249 | */ |
250 | - private function getResultPathForConstraintId( $constraintId ) { |
|
251 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
250 | + private function getResultPathForConstraintId($constraintId) { |
|
251 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
252 | 252 | '@phan-var PropertyId $propertyId'; |
253 | - return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] ); |
|
253 | + return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | /** |
@@ -265,8 +265,8 @@ discard block |
||
265 | 265 | $constraintParameterExceptions, |
266 | 266 | ApiResult $result |
267 | 267 | ) { |
268 | - $path = $this->getResultPathForConstraintId( $constraintId ); |
|
269 | - if ( $constraintParameterExceptions === null ) { |
|
268 | + $path = $this->getResultPathForConstraintId($constraintId); |
|
269 | + if ($constraintParameterExceptions === null) { |
|
270 | 270 | $result->addValue( |
271 | 271 | $path, |
272 | 272 | self::KEY_STATUS, |
@@ -276,13 +276,13 @@ discard block |
||
276 | 276 | $result->addValue( |
277 | 277 | $path, |
278 | 278 | self::KEY_STATUS, |
279 | - empty( $constraintParameterExceptions ) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
279 | + empty($constraintParameterExceptions) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
280 | 280 | ); |
281 | 281 | |
282 | 282 | $violationMessageRenderer = $this->violationMessageRendererFactory |
283 | - ->getViolationMessageRenderer( $this->getLanguage() ); |
|
283 | + ->getViolationMessageRenderer($this->getLanguage()); |
|
284 | 284 | $problems = []; |
285 | - foreach ( $constraintParameterExceptions as $constraintParameterException ) { |
|
285 | + foreach ($constraintParameterExceptions as $constraintParameterException) { |
|
286 | 286 | $problems[] = [ |
287 | 287 | self::KEY_MESSAGE_HTML => $violationMessageRenderer->render( |
288 | 288 | $constraintParameterException->getViolationMessage() ), |
@@ -321,8 +321,8 @@ discard block |
||
321 | 321 | return [ |
322 | 322 | 'action=wbcheckconstraintparameters&propertyid=P247' |
323 | 323 | => 'apihelp-wbcheckconstraintparameters-example-propertyid-1', |
324 | - 'action=wbcheckconstraintparameters&' . |
|
325 | - 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|' . |
|
324 | + 'action=wbcheckconstraintparameters&'. |
|
325 | + 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|'. |
|
326 | 326 | 'P225$cdc71e4a-47a0-12c5-dfb3-3f6fc0b6613f' |
327 | 327 | => 'apihelp-wbcheckconstraintparameters-example-constraintid-2', |
328 | 328 | ]; |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * then using the main DBLoadBalancer service may be incorrect. |
27 | 27 | * @param string|false $dbName Database name ($domain for ILoadBalancer methods). |
28 | 28 | */ |
29 | - public function __construct( ILoadBalancer $lb, $dbName ) { |
|
29 | + public function __construct(ILoadBalancer $lb, $dbName) { |
|
30 | 30 | $this->lb = $lb; |
31 | 31 | $this->dbName = $dbName; |
32 | 32 | } |
@@ -36,17 +36,17 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @return Constraint[] |
38 | 38 | */ |
39 | - public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
40 | - $dbr = $this->lb->getConnectionRef( ILoadBalancer::DB_REPLICA, [], $this->dbName ); |
|
39 | + public function queryConstraintsForProperty(PropertyId $propertyId) { |
|
40 | + $dbr = $this->lb->getConnectionRef(ILoadBalancer::DB_REPLICA, [], $this->dbName); |
|
41 | 41 | |
42 | 42 | $results = $dbr->select( |
43 | 43 | 'wbqc_constraints', |
44 | 44 | '*', |
45 | - [ 'pid' => $propertyId->getNumericId() ], |
|
45 | + ['pid' => $propertyId->getNumericId()], |
|
46 | 46 | __METHOD__ |
47 | 47 | ); |
48 | 48 | |
49 | - return $this->convertToConstraints( $results ); |
|
49 | + return $this->convertToConstraints($results); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -54,26 +54,26 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return Constraint[] |
56 | 56 | */ |
57 | - private function convertToConstraints( IResultWrapper $results ) { |
|
57 | + private function convertToConstraints(IResultWrapper $results) { |
|
58 | 58 | $constraints = []; |
59 | - $logger = LoggerFactory::getInstance( 'WikibaseQualityConstraints' ); |
|
60 | - foreach ( $results as $result ) { |
|
59 | + $logger = LoggerFactory::getInstance('WikibaseQualityConstraints'); |
|
60 | + foreach ($results as $result) { |
|
61 | 61 | $constraintTypeItemId = $result->constraint_type_qid; |
62 | - $constraintParameters = json_decode( $result->constraint_parameters, true ); |
|
62 | + $constraintParameters = json_decode($result->constraint_parameters, true); |
|
63 | 63 | |
64 | - if ( $constraintParameters === null ) { |
|
64 | + if ($constraintParameters === null) { |
|
65 | 65 | // T171295 |
66 | - $logger->warning( 'Constraint {constraintId} has invalid constraint parameters.', [ |
|
66 | + $logger->warning('Constraint {constraintId} has invalid constraint parameters.', [ |
|
67 | 67 | 'method' => __METHOD__, |
68 | 68 | 'constraintId' => $result->constraint_guid, |
69 | 69 | 'constraintParameters' => $result->constraint_parameters, |
70 | - ] ); |
|
71 | - $constraintParameters = [ '@error' => [ /* unknown */ ] ]; |
|
70 | + ]); |
|
71 | + $constraintParameters = ['@error' => [/* unknown */]]; |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | $constraints[] = new Constraint( |
75 | 75 | $result->constraint_guid, |
76 | - NumericPropertyId::newFromNumber( $result->pid ), |
|
76 | + NumericPropertyId::newFromNumber($result->pid), |
|
77 | 77 | $constraintTypeItemId, |
78 | 78 | $constraintParameters |
79 | 79 | ); |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * @return bool |
17 | 17 | * @throws DBUnexpectedError |
18 | 18 | */ |
19 | - public function insertBatch( array $constraints ); |
|
19 | + public function insertBatch(array $constraints); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Delete all constraints for the property ID. |
@@ -25,6 +25,6 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @throws DBUnexpectedError |
27 | 27 | */ |
28 | - public function deleteForProperty( NumericPropertyId $propertyId ); |
|
28 | + public function deleteForProperty(NumericPropertyId $propertyId); |
|
29 | 29 | |
30 | 30 | } |
@@ -24,16 +24,16 @@ discard block |
||
24 | 24 | * then using the main DBLoadBalancer service may be incorrect. |
25 | 25 | * @param string|false $dbName Database name ($domain for ILoadBalancer methods). |
26 | 26 | */ |
27 | - public function __construct( ILoadBalancer $lb, $dbName ) { |
|
27 | + public function __construct(ILoadBalancer $lb, $dbName) { |
|
28 | 28 | $this->lb = $lb; |
29 | 29 | $this->dbName = $dbName; |
30 | 30 | } |
31 | 31 | |
32 | - private function encodeConstraintParameters( array $constraintParameters ) { |
|
33 | - $json = json_encode( $constraintParameters, JSON_FORCE_OBJECT ); |
|
32 | + private function encodeConstraintParameters(array $constraintParameters) { |
|
33 | + $json = json_encode($constraintParameters, JSON_FORCE_OBJECT); |
|
34 | 34 | |
35 | - if ( strlen( $json ) > 50000 ) { |
|
36 | - $json = json_encode( [ '@error' => [ 'toolong' => true ] ] ); |
|
35 | + if (strlen($json) > 50000) { |
|
36 | + $json = json_encode(['@error' => ['toolong' => true]]); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | return $json; |
@@ -45,21 +45,21 @@ discard block |
||
45 | 45 | * @throws DBUnexpectedError |
46 | 46 | * @return bool |
47 | 47 | */ |
48 | - public function insertBatch( array $constraints ) { |
|
48 | + public function insertBatch(array $constraints) { |
|
49 | 49 | $accumulator = array_map( |
50 | - function ( Constraint $constraint ) { |
|
50 | + function(Constraint $constraint) { |
|
51 | 51 | return [ |
52 | 52 | 'constraint_guid' => $constraint->getConstraintId(), |
53 | 53 | 'pid' => $constraint->getPropertyId()->getNumericId(), |
54 | 54 | 'constraint_type_qid' => $constraint->getConstraintTypeItemId(), |
55 | - 'constraint_parameters' => $this->encodeConstraintParameters( $constraint->getConstraintParameters() ) |
|
55 | + 'constraint_parameters' => $this->encodeConstraintParameters($constraint->getConstraintParameters()) |
|
56 | 56 | ]; |
57 | 57 | }, |
58 | 58 | $constraints |
59 | 59 | ); |
60 | 60 | |
61 | - $dbw = $this->lb->getConnection( ILoadBalancer::DB_PRIMARY, [], $this->dbName ); |
|
62 | - return $dbw->insert( 'wbqc_constraints', $accumulator, __METHOD__ ); |
|
61 | + $dbw = $this->lb->getConnection(ILoadBalancer::DB_PRIMARY, [], $this->dbName); |
|
62 | + return $dbw->insert('wbqc_constraints', $accumulator, __METHOD__); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @throws DBUnexpectedError |
71 | 71 | */ |
72 | - public function deleteForProperty( NumericPropertyId $propertyId ) { |
|
73 | - $dbw = $this->lb->getConnection( ILoadBalancer::DB_PRIMARY, [], $this->dbName ); |
|
72 | + public function deleteForProperty(NumericPropertyId $propertyId) { |
|
73 | + $dbw = $this->lb->getConnection(ILoadBalancer::DB_PRIMARY, [], $this->dbName); |
|
74 | 74 | $dbw->delete( |
75 | 75 | 'wbqc_constraints', |
76 | 76 | [ |
@@ -30,53 +30,53 @@ discard block |
||
30 | 30 | use WikiMap; |
31 | 31 | |
32 | 32 | return [ |
33 | - ConstraintsServices::EXPIRY_LOCK => static function ( MediaWikiServices $services ) { |
|
34 | - return new ExpiryLock( ObjectCache::getInstance( CACHE_ANYTHING ) ); |
|
33 | + ConstraintsServices::EXPIRY_LOCK => static function(MediaWikiServices $services) { |
|
34 | + return new ExpiryLock(ObjectCache::getInstance(CACHE_ANYTHING)); |
|
35 | 35 | }, |
36 | 36 | |
37 | - ConstraintsServices::LOGGING_HELPER => static function ( MediaWikiServices $services ) { |
|
37 | + ConstraintsServices::LOGGING_HELPER => static function(MediaWikiServices $services) { |
|
38 | 38 | return new LoggingHelper( |
39 | 39 | $services->getStatsdDataFactory(), |
40 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ), |
|
40 | + LoggerFactory::getInstance('WikibaseQualityConstraints'), |
|
41 | 41 | $services->getMainConfig() |
42 | 42 | ); |
43 | 43 | }, |
44 | 44 | |
45 | - ConstraintsServices::CONSTRAINT_STORE => static function ( MediaWikiServices $services ) { |
|
46 | - $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
47 | - $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType( Property::ENTITY_TYPE ); |
|
48 | - if ( $propertySource === null ) { |
|
49 | - throw new RuntimeException( 'Can\'t get a ConstraintStore for properties not stored in a database.' ); |
|
45 | + ConstraintsServices::CONSTRAINT_STORE => static function(MediaWikiServices $services) { |
|
46 | + $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
47 | + $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType(Property::ENTITY_TYPE); |
|
48 | + if ($propertySource === null) { |
|
49 | + throw new RuntimeException('Can\'t get a ConstraintStore for properties not stored in a database.'); |
|
50 | 50 | } |
51 | 51 | |
52 | - $localEntitySourceName = WikibaseRepo::getLocalEntitySource( $services )->getSourceName(); |
|
53 | - if ( $propertySource->getSourceName() !== $localEntitySourceName ) { |
|
54 | - throw new RuntimeException( 'Can\'t get a ConstraintStore for a non local entity source.' ); |
|
52 | + $localEntitySourceName = WikibaseRepo::getLocalEntitySource($services)->getSourceName(); |
|
53 | + if ($propertySource->getSourceName() !== $localEntitySourceName) { |
|
54 | + throw new RuntimeException('Can\'t get a ConstraintStore for a non local entity source.'); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | $dbName = $propertySource->getDatabaseName(); |
58 | 58 | return new ConstraintRepositoryStore( |
59 | - $services->getDBLoadBalancerFactory()->getMainLB( $dbName ), |
|
59 | + $services->getDBLoadBalancerFactory()->getMainLB($dbName), |
|
60 | 60 | $dbName |
61 | 61 | ); |
62 | 62 | }, |
63 | 63 | |
64 | - ConstraintsServices::CONSTRAINT_LOOKUP => static function ( MediaWikiServices $services ) { |
|
65 | - $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
66 | - $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType( Property::ENTITY_TYPE ); |
|
67 | - if ( $propertySource === null ) { |
|
68 | - throw new RuntimeException( 'Can\'t get a ConstraintStore for properties not stored in a database.' ); |
|
64 | + ConstraintsServices::CONSTRAINT_LOOKUP => static function(MediaWikiServices $services) { |
|
65 | + $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
66 | + $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType(Property::ENTITY_TYPE); |
|
67 | + if ($propertySource === null) { |
|
68 | + throw new RuntimeException('Can\'t get a ConstraintStore for properties not stored in a database.'); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | $dbName = $propertySource->getDatabaseName(); |
72 | 72 | $rawLookup = new ConstraintRepositoryLookup( |
73 | - $services->getDBLoadBalancerFactory()->getMainLB( $dbName ), |
|
73 | + $services->getDBLoadBalancerFactory()->getMainLB($dbName), |
|
74 | 74 | $dbName |
75 | 75 | ); |
76 | - return new CachingConstraintLookup( $rawLookup ); |
|
76 | + return new CachingConstraintLookup($rawLookup); |
|
77 | 77 | }, |
78 | 78 | |
79 | - ConstraintsServices::CHECK_RESULT_SERIALIZER => static function ( MediaWikiServices $services ) { |
|
79 | + ConstraintsServices::CHECK_RESULT_SERIALIZER => static function(MediaWikiServices $services) { |
|
80 | 80 | return new CheckResultSerializer( |
81 | 81 | new ConstraintSerializer( |
82 | 82 | false // constraint parameters are not exposed |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | ); |
88 | 88 | }, |
89 | 89 | |
90 | - ConstraintsServices::CHECK_RESULT_DESERIALIZER => static function ( MediaWikiServices $services ) { |
|
91 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
92 | - $dataValueFactory = WikibaseRepo::getDataValueFactory( $services ); |
|
90 | + ConstraintsServices::CHECK_RESULT_DESERIALIZER => static function(MediaWikiServices $services) { |
|
91 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
92 | + $dataValueFactory = WikibaseRepo::getDataValueFactory($services); |
|
93 | 93 | |
94 | 94 | return new CheckResultDeserializer( |
95 | 95 | new ConstraintDeserializer(), |
@@ -102,13 +102,13 @@ discard block |
||
102 | 102 | ); |
103 | 103 | }, |
104 | 104 | |
105 | - ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => static function ( MediaWikiServices $services ) { |
|
105 | + ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => static function(MediaWikiServices $services) { |
|
106 | 106 | return new ViolationMessageSerializer(); |
107 | 107 | }, |
108 | 108 | |
109 | - ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => static function ( MediaWikiServices $services ) { |
|
110 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
111 | - $dataValueFactory = WikibaseRepo::getDataValueFactory( $services ); |
|
109 | + ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => static function(MediaWikiServices $services) { |
|
110 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
111 | + $dataValueFactory = WikibaseRepo::getDataValueFactory($services); |
|
112 | 112 | |
113 | 113 | return new ViolationMessageDeserializer( |
114 | 114 | $entityIdParser, |
@@ -116,37 +116,37 @@ discard block |
||
116 | 116 | ); |
117 | 117 | }, |
118 | 118 | |
119 | - ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => static function ( MediaWikiServices $services ) { |
|
120 | - $deserializerFactory = WikibaseRepo::getBaseDataModelDeserializerFactory( $services ); |
|
121 | - $entitySourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
119 | + ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => static function(MediaWikiServices $services) { |
|
120 | + $deserializerFactory = WikibaseRepo::getBaseDataModelDeserializerFactory($services); |
|
121 | + $entitySourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
122 | 122 | |
123 | 123 | return new ConstraintParameterParser( |
124 | 124 | $services->getMainConfig(), |
125 | 125 | $deserializerFactory, |
126 | - $entitySourceDefinitions->getDatabaseSourceForEntityType( 'item' )->getConceptBaseUri() |
|
126 | + $entitySourceDefinitions->getDatabaseSourceForEntityType('item')->getConceptBaseUri() |
|
127 | 127 | ); |
128 | 128 | }, |
129 | 129 | |
130 | - ConstraintsServices::CONNECTION_CHECKER_HELPER => static function ( MediaWikiServices $services ) { |
|
130 | + ConstraintsServices::CONNECTION_CHECKER_HELPER => static function(MediaWikiServices $services) { |
|
131 | 131 | return new ConnectionCheckerHelper(); |
132 | 132 | }, |
133 | 133 | |
134 | - ConstraintsServices::RANGE_CHECKER_HELPER => static function ( MediaWikiServices $services ) { |
|
134 | + ConstraintsServices::RANGE_CHECKER_HELPER => static function(MediaWikiServices $services) { |
|
135 | 135 | return new RangeCheckerHelper( |
136 | 136 | $services->getMainConfig(), |
137 | - WikibaseRepo::getUnitConverter( $services ) |
|
137 | + WikibaseRepo::getUnitConverter($services) |
|
138 | 138 | ); |
139 | 139 | }, |
140 | 140 | |
141 | - ConstraintsServices::SPARQL_HELPER => static function ( MediaWikiServices $services ) { |
|
142 | - $endpoint = $services->getMainConfig()->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
143 | - if ( $endpoint === '' ) { |
|
141 | + ConstraintsServices::SPARQL_HELPER => static function(MediaWikiServices $services) { |
|
142 | + $endpoint = $services->getMainConfig()->get('WBQualityConstraintsSparqlEndpoint'); |
|
143 | + if ($endpoint === '') { |
|
144 | 144 | return new DummySparqlHelper(); |
145 | 145 | } |
146 | 146 | |
147 | - $rdfVocabulary = WikibaseRepo::getRdfVocabulary( $services ); |
|
148 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
149 | - $propertyDataTypeLookup = WikibaseRepo::getPropertyDataTypeLookup( $services ); |
|
147 | + $rdfVocabulary = WikibaseRepo::getRdfVocabulary($services); |
|
148 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
149 | + $propertyDataTypeLookup = WikibaseRepo::getPropertyDataTypeLookup($services); |
|
150 | 150 | |
151 | 151 | return new SparqlHelper( |
152 | 152 | $services->getMainConfig(), |
@@ -154,126 +154,126 @@ discard block |
||
154 | 154 | $entityIdParser, |
155 | 155 | $propertyDataTypeLookup, |
156 | 156 | $services->getMainWANObjectCache(), |
157 | - ConstraintsServices::getViolationMessageSerializer( $services ), |
|
158 | - ConstraintsServices::getViolationMessageDeserializer( $services ), |
|
157 | + ConstraintsServices::getViolationMessageSerializer($services), |
|
158 | + ConstraintsServices::getViolationMessageDeserializer($services), |
|
159 | 159 | $services->getStatsdDataFactory(), |
160 | - ConstraintsServices::getExpiryLock( $services ), |
|
161 | - ConstraintsServices::getLoggingHelper( $services ), |
|
162 | - WikiMap::getCurrentWikiId() . ' WikibaseQualityConstraints ' . Http::userAgent(), |
|
160 | + ConstraintsServices::getExpiryLock($services), |
|
161 | + ConstraintsServices::getLoggingHelper($services), |
|
162 | + WikiMap::getCurrentWikiId().' WikibaseQualityConstraints '.Http::userAgent(), |
|
163 | 163 | $services->getHttpRequestFactory() |
164 | 164 | ); |
165 | 165 | }, |
166 | 166 | |
167 | - ConstraintsServices::TYPE_CHECKER_HELPER => static function ( MediaWikiServices $services ) { |
|
167 | + ConstraintsServices::TYPE_CHECKER_HELPER => static function(MediaWikiServices $services) { |
|
168 | 168 | return new TypeCheckerHelper( |
169 | - WikibaseServices::getEntityLookup( $services ), |
|
169 | + WikibaseServices::getEntityLookup($services), |
|
170 | 170 | $services->getMainConfig(), |
171 | - ConstraintsServices::getSparqlHelper( $services ), |
|
171 | + ConstraintsServices::getSparqlHelper($services), |
|
172 | 172 | $services->getStatsdDataFactory() |
173 | 173 | ); |
174 | 174 | }, |
175 | 175 | |
176 | - ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => static function ( MediaWikiServices $services ) { |
|
177 | - $statementGuidParser = WikibaseRepo::getStatementGuidParser( $services ); |
|
176 | + ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => static function(MediaWikiServices $services) { |
|
177 | + $statementGuidParser = WikibaseRepo::getStatementGuidParser($services); |
|
178 | 178 | |
179 | 179 | $config = $services->getMainConfig(); |
180 | 180 | $checkerMap = [ |
181 | - $config->get( 'WBQualityConstraintsConflictsWithConstraintId' ) |
|
182 | - => ConstraintCheckerServices::getConflictsWithChecker( $services ), |
|
183 | - $config->get( 'WBQualityConstraintsItemRequiresClaimConstraintId' ) |
|
184 | - => ConstraintCheckerServices::getItemChecker( $services ), |
|
185 | - $config->get( 'WBQualityConstraintsValueRequiresClaimConstraintId' ) |
|
186 | - => ConstraintCheckerServices::getTargetRequiredClaimChecker( $services ), |
|
187 | - $config->get( 'WBQualityConstraintsSymmetricConstraintId' ) |
|
188 | - => ConstraintCheckerServices::getSymmetricChecker( $services ), |
|
189 | - $config->get( 'WBQualityConstraintsInverseConstraintId' ) |
|
190 | - => ConstraintCheckerServices::getInverseChecker( $services ), |
|
191 | - $config->get( 'WBQualityConstraintsUsedAsQualifierConstraintId' ) |
|
192 | - => ConstraintCheckerServices::getQualifierChecker( $services ), |
|
193 | - $config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' ) |
|
194 | - => ConstraintCheckerServices::getQualifiersChecker( $services ), |
|
195 | - $config->get( 'WBQualityConstraintsMandatoryQualifierConstraintId' ) |
|
196 | - => ConstraintCheckerServices::getMandatoryQualifiersChecker( $services ), |
|
197 | - $config->get( 'WBQualityConstraintsRangeConstraintId' ) |
|
198 | - => ConstraintCheckerServices::getRangeChecker( $services ), |
|
199 | - $config->get( 'WBQualityConstraintsDifferenceWithinRangeConstraintId' ) |
|
200 | - => ConstraintCheckerServices::getDiffWithinRangeChecker( $services ), |
|
201 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ) |
|
202 | - => ConstraintCheckerServices::getTypeChecker( $services ), |
|
203 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ) |
|
204 | - => ConstraintCheckerServices::getValueTypeChecker( $services ), |
|
205 | - $config->get( 'WBQualityConstraintsSingleValueConstraintId' ) |
|
206 | - => ConstraintCheckerServices::getSingleValueChecker( $services ), |
|
207 | - $config->get( 'WBQualityConstraintsMultiValueConstraintId' ) |
|
208 | - => ConstraintCheckerServices::getMultiValueChecker( $services ), |
|
209 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ) |
|
210 | - => ConstraintCheckerServices::getUniqueValueChecker( $services ), |
|
211 | - $config->get( 'WBQualityConstraintsFormatConstraintId' ) |
|
212 | - => ConstraintCheckerServices::getFormatChecker( $services ), |
|
213 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ) |
|
214 | - => ConstraintCheckerServices::getCommonsLinkChecker( $services ), |
|
215 | - $config->get( 'WBQualityConstraintsOneOfConstraintId' ) |
|
216 | - => ConstraintCheckerServices::getOneOfChecker( $services ), |
|
217 | - $config->get( 'WBQualityConstraintsUsedForValuesOnlyConstraintId' ) |
|
218 | - => ConstraintCheckerServices::getValueOnlyChecker( $services ), |
|
219 | - $config->get( 'WBQualityConstraintsUsedAsReferenceConstraintId' ) |
|
220 | - => ConstraintCheckerServices::getReferenceChecker( $services ), |
|
221 | - $config->get( 'WBQualityConstraintsNoBoundsConstraintId' ) |
|
222 | - => ConstraintCheckerServices::getNoBoundsChecker( $services ), |
|
223 | - $config->get( 'WBQualityConstraintsAllowedUnitsConstraintId' ) |
|
224 | - => ConstraintCheckerServices::getAllowedUnitsChecker( $services ), |
|
225 | - $config->get( 'WBQualityConstraintsSingleBestValueConstraintId' ) |
|
226 | - => ConstraintCheckerServices::getSingleBestValueChecker( $services ), |
|
227 | - $config->get( 'WBQualityConstraintsAllowedEntityTypesConstraintId' ) |
|
228 | - => ConstraintCheckerServices::getEntityTypeChecker( $services ), |
|
229 | - $config->get( 'WBQualityConstraintsNoneOfConstraintId' ) |
|
230 | - => ConstraintCheckerServices::getNoneOfChecker( $services ), |
|
231 | - $config->get( 'WBQualityConstraintsIntegerConstraintId' ) |
|
232 | - => ConstraintCheckerServices::getIntegerChecker( $services ), |
|
233 | - $config->get( 'WBQualityConstraintsCitationNeededConstraintId' ) |
|
234 | - => ConstraintCheckerServices::getCitationNeededChecker( $services ), |
|
235 | - $config->get( 'WBQualityConstraintsPropertyScopeConstraintId' ) |
|
236 | - => ConstraintCheckerServices::getPropertyScopeChecker( $services ), |
|
237 | - $config->get( 'WBQualityConstraintsContemporaryConstraintId' ) |
|
238 | - => ConstraintCheckerServices::getContemporaryChecker( $services ), |
|
239 | - $config->get( 'WBQualityConstraintsLexemeLanguageConstraintId' ) |
|
240 | - => ConstraintCheckerServices::getLexemeLanguageChecker( $services ), |
|
241 | - $config->get( 'WBQualityConstraintsLabelInLanguageConstraintId' ) |
|
242 | - => ConstraintCheckerServices::getLabelInLanguageChecker( $services ), |
|
181 | + $config->get('WBQualityConstraintsConflictsWithConstraintId') |
|
182 | + => ConstraintCheckerServices::getConflictsWithChecker($services), |
|
183 | + $config->get('WBQualityConstraintsItemRequiresClaimConstraintId') |
|
184 | + => ConstraintCheckerServices::getItemChecker($services), |
|
185 | + $config->get('WBQualityConstraintsValueRequiresClaimConstraintId') |
|
186 | + => ConstraintCheckerServices::getTargetRequiredClaimChecker($services), |
|
187 | + $config->get('WBQualityConstraintsSymmetricConstraintId') |
|
188 | + => ConstraintCheckerServices::getSymmetricChecker($services), |
|
189 | + $config->get('WBQualityConstraintsInverseConstraintId') |
|
190 | + => ConstraintCheckerServices::getInverseChecker($services), |
|
191 | + $config->get('WBQualityConstraintsUsedAsQualifierConstraintId') |
|
192 | + => ConstraintCheckerServices::getQualifierChecker($services), |
|
193 | + $config->get('WBQualityConstraintsAllowedQualifiersConstraintId') |
|
194 | + => ConstraintCheckerServices::getQualifiersChecker($services), |
|
195 | + $config->get('WBQualityConstraintsMandatoryQualifierConstraintId') |
|
196 | + => ConstraintCheckerServices::getMandatoryQualifiersChecker($services), |
|
197 | + $config->get('WBQualityConstraintsRangeConstraintId') |
|
198 | + => ConstraintCheckerServices::getRangeChecker($services), |
|
199 | + $config->get('WBQualityConstraintsDifferenceWithinRangeConstraintId') |
|
200 | + => ConstraintCheckerServices::getDiffWithinRangeChecker($services), |
|
201 | + $config->get('WBQualityConstraintsTypeConstraintId') |
|
202 | + => ConstraintCheckerServices::getTypeChecker($services), |
|
203 | + $config->get('WBQualityConstraintsValueTypeConstraintId') |
|
204 | + => ConstraintCheckerServices::getValueTypeChecker($services), |
|
205 | + $config->get('WBQualityConstraintsSingleValueConstraintId') |
|
206 | + => ConstraintCheckerServices::getSingleValueChecker($services), |
|
207 | + $config->get('WBQualityConstraintsMultiValueConstraintId') |
|
208 | + => ConstraintCheckerServices::getMultiValueChecker($services), |
|
209 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId') |
|
210 | + => ConstraintCheckerServices::getUniqueValueChecker($services), |
|
211 | + $config->get('WBQualityConstraintsFormatConstraintId') |
|
212 | + => ConstraintCheckerServices::getFormatChecker($services), |
|
213 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId') |
|
214 | + => ConstraintCheckerServices::getCommonsLinkChecker($services), |
|
215 | + $config->get('WBQualityConstraintsOneOfConstraintId') |
|
216 | + => ConstraintCheckerServices::getOneOfChecker($services), |
|
217 | + $config->get('WBQualityConstraintsUsedForValuesOnlyConstraintId') |
|
218 | + => ConstraintCheckerServices::getValueOnlyChecker($services), |
|
219 | + $config->get('WBQualityConstraintsUsedAsReferenceConstraintId') |
|
220 | + => ConstraintCheckerServices::getReferenceChecker($services), |
|
221 | + $config->get('WBQualityConstraintsNoBoundsConstraintId') |
|
222 | + => ConstraintCheckerServices::getNoBoundsChecker($services), |
|
223 | + $config->get('WBQualityConstraintsAllowedUnitsConstraintId') |
|
224 | + => ConstraintCheckerServices::getAllowedUnitsChecker($services), |
|
225 | + $config->get('WBQualityConstraintsSingleBestValueConstraintId') |
|
226 | + => ConstraintCheckerServices::getSingleBestValueChecker($services), |
|
227 | + $config->get('WBQualityConstraintsAllowedEntityTypesConstraintId') |
|
228 | + => ConstraintCheckerServices::getEntityTypeChecker($services), |
|
229 | + $config->get('WBQualityConstraintsNoneOfConstraintId') |
|
230 | + => ConstraintCheckerServices::getNoneOfChecker($services), |
|
231 | + $config->get('WBQualityConstraintsIntegerConstraintId') |
|
232 | + => ConstraintCheckerServices::getIntegerChecker($services), |
|
233 | + $config->get('WBQualityConstraintsCitationNeededConstraintId') |
|
234 | + => ConstraintCheckerServices::getCitationNeededChecker($services), |
|
235 | + $config->get('WBQualityConstraintsPropertyScopeConstraintId') |
|
236 | + => ConstraintCheckerServices::getPropertyScopeChecker($services), |
|
237 | + $config->get('WBQualityConstraintsContemporaryConstraintId') |
|
238 | + => ConstraintCheckerServices::getContemporaryChecker($services), |
|
239 | + $config->get('WBQualityConstraintsLexemeLanguageConstraintId') |
|
240 | + => ConstraintCheckerServices::getLexemeLanguageChecker($services), |
|
241 | + $config->get('WBQualityConstraintsLabelInLanguageConstraintId') |
|
242 | + => ConstraintCheckerServices::getLabelInLanguageChecker($services), |
|
243 | 243 | ]; |
244 | 244 | |
245 | 245 | return new DelegatingConstraintChecker( |
246 | - WikibaseServices::getEntityLookup( $services ), |
|
246 | + WikibaseServices::getEntityLookup($services), |
|
247 | 247 | $checkerMap, |
248 | - ConstraintsServices::getConstraintLookup( $services ), |
|
249 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
248 | + ConstraintsServices::getConstraintLookup($services), |
|
249 | + ConstraintsServices::getConstraintParameterParser($services), |
|
250 | 250 | $statementGuidParser, |
251 | - ConstraintsServices::getLoggingHelper( $services ), |
|
252 | - $config->get( 'WBQualityConstraintsCheckQualifiers' ), |
|
253 | - $config->get( 'WBQualityConstraintsCheckReferences' ), |
|
254 | - $config->get( 'WBQualityConstraintsPropertiesWithViolatingQualifiers' ) |
|
251 | + ConstraintsServices::getLoggingHelper($services), |
|
252 | + $config->get('WBQualityConstraintsCheckQualifiers'), |
|
253 | + $config->get('WBQualityConstraintsCheckReferences'), |
|
254 | + $config->get('WBQualityConstraintsPropertiesWithViolatingQualifiers') |
|
255 | 255 | ); |
256 | 256 | }, |
257 | 257 | |
258 | - ConstraintsServices::RESULTS_SOURCE => static function ( MediaWikiServices $services ) { |
|
258 | + ConstraintsServices::RESULTS_SOURCE => static function(MediaWikiServices $services) { |
|
259 | 259 | $config = $services->getMainConfig(); |
260 | 260 | $resultsSource = new CheckingResultsSource( |
261 | - ConstraintsServices::getDelegatingConstraintChecker( $services ) |
|
261 | + ConstraintsServices::getDelegatingConstraintChecker($services) |
|
262 | 262 | ); |
263 | 263 | |
264 | 264 | $cacheCheckConstraintsResults = false; |
265 | 265 | |
266 | - if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) { |
|
266 | + if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) { |
|
267 | 267 | $cacheCheckConstraintsResults = true; |
268 | 268 | // check that we can use getLocalRepoWikiPageMetaDataAccessor() |
269 | 269 | // TODO we should always be able to cache constraint check results (T244726) |
270 | - $entitySources = WikibaseRepo::getEntitySourceDefinitions( $services )->getSources(); |
|
271 | - $localEntitySourceName = WikibaseRepo::getLocalEntitySource( $services )->getSourceName(); |
|
270 | + $entitySources = WikibaseRepo::getEntitySourceDefinitions($services)->getSources(); |
|
271 | + $localEntitySourceName = WikibaseRepo::getLocalEntitySource($services)->getSourceName(); |
|
272 | 272 | |
273 | - foreach ( $entitySources as $entitySource ) { |
|
274 | - if ( $entitySource->getSourceName() !== $localEntitySourceName ) { |
|
275 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' )->warning( |
|
276 | - 'Cannot cache constraint check results for non-local source: ' . |
|
273 | + foreach ($entitySources as $entitySource) { |
|
274 | + if ($entitySource->getSourceName() !== $localEntitySourceName) { |
|
275 | + LoggerFactory::getInstance('WikibaseQualityConstraints')->warning( |
|
276 | + 'Cannot cache constraint check results for non-local source: '. |
|
277 | 277 | $entitySource->getSourceName() |
278 | 278 | ); |
279 | 279 | $cacheCheckConstraintsResults = false; |
@@ -282,28 +282,28 @@ discard block |
||
282 | 282 | } |
283 | 283 | } |
284 | 284 | |
285 | - if ( $cacheCheckConstraintsResults ) { |
|
285 | + if ($cacheCheckConstraintsResults) { |
|
286 | 286 | $possiblyStaleConstraintTypes = [ |
287 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ), |
|
288 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ), |
|
289 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ), |
|
290 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ), |
|
287 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId'), |
|
288 | + $config->get('WBQualityConstraintsTypeConstraintId'), |
|
289 | + $config->get('WBQualityConstraintsValueTypeConstraintId'), |
|
290 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId'), |
|
291 | 291 | ]; |
292 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
292 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
293 | 293 | $wikiPageEntityMetaDataAccessor = WikibaseRepo::getLocalRepoWikiPageMetaDataAccessor( |
294 | 294 | $services ); |
295 | 295 | |
296 | 296 | $resultsSource = new CachingResultsSource( |
297 | 297 | $resultsSource, |
298 | 298 | ResultsCache::getDefaultInstance(), |
299 | - ConstraintsServices::getCheckResultSerializer( $services ), |
|
300 | - ConstraintsServices::getCheckResultDeserializer( $services ), |
|
299 | + ConstraintsServices::getCheckResultSerializer($services), |
|
300 | + ConstraintsServices::getCheckResultDeserializer($services), |
|
301 | 301 | $wikiPageEntityMetaDataAccessor, |
302 | 302 | $entityIdParser, |
303 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ), |
|
303 | + $config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'), |
|
304 | 304 | $possiblyStaleConstraintTypes, |
305 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds' ), |
|
306 | - ConstraintsServices::getLoggingHelper( $services ) |
|
305 | + $config->get('WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds'), |
|
306 | + ConstraintsServices::getLoggingHelper($services) |
|
307 | 307 | ); |
308 | 308 | } |
309 | 309 |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | */ |
39 | 39 | private const BATCH_SIZE = 50; |
40 | 40 | |
41 | - public static function newFromGlobalState( Title $title, array $params ) { |
|
42 | - Assert::parameterType( 'string', $params['propertyId'], '$params["propertyId"]' ); |
|
41 | + public static function newFromGlobalState(Title $title, array $params) { |
|
42 | + Assert::parameterType('string', $params['propertyId'], '$params["propertyId"]'); |
|
43 | 43 | $services = MediaWikiServices::getInstance(); |
44 | 44 | return new UpdateConstraintsTableJob( |
45 | 45 | $title, |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | $services->getMainConfig(), |
50 | 50 | ConstraintsServices::getConstraintStore(), |
51 | 51 | $services->getDBLoadBalancerFactory(), |
52 | - WikibaseRepo::getStore()->getEntityRevisionLookup( Store::LOOKUP_CACHING_DISABLED ), |
|
53 | - WikibaseRepo::getBaseDataModelSerializerFactory( $services ) |
|
52 | + WikibaseRepo::getStore()->getEntityRevisionLookup(Store::LOOKUP_CACHING_DISABLED), |
|
53 | + WikibaseRepo::getBaseDataModelSerializerFactory($services) |
|
54 | 54 | ->newSnakSerializer() |
55 | 55 | ); |
56 | 56 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | EntityRevisionLookup $entityRevisionLookup, |
111 | 111 | Serializer $snakSerializer |
112 | 112 | ) { |
113 | - parent::__construct( 'constraintsTableUpdate', $title, $params ); |
|
113 | + parent::__construct('constraintsTableUpdate', $title, $params); |
|
114 | 114 | |
115 | 115 | $this->propertyId = $propertyId; |
116 | 116 | $this->revisionId = $revisionId; |
@@ -121,11 +121,11 @@ discard block |
||
121 | 121 | $this->snakSerializer = $snakSerializer; |
122 | 122 | } |
123 | 123 | |
124 | - public function extractParametersFromQualifiers( SnakList $qualifiers ) { |
|
124 | + public function extractParametersFromQualifiers(SnakList $qualifiers) { |
|
125 | 125 | $parameters = []; |
126 | - foreach ( $qualifiers as $qualifier ) { |
|
126 | + foreach ($qualifiers as $qualifier) { |
|
127 | 127 | $qualifierId = $qualifier->getPropertyId()->getSerialization(); |
128 | - $paramSerialization = $this->snakSerializer->serialize( $qualifier ); |
|
128 | + $paramSerialization = $this->snakSerializer->serialize($qualifier); |
|
129 | 129 | $parameters[$qualifierId][] = $paramSerialization; |
130 | 130 | } |
131 | 131 | return $parameters; |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | '@phan-var \Wikibase\DataModel\Entity\EntityIdValue $dataValue'; |
143 | 143 | $entityId = $dataValue->getEntityId(); |
144 | 144 | $constraintTypeQid = $entityId->getSerialization(); |
145 | - $parameters = $this->extractParametersFromQualifiers( $constraintStatement->getQualifiers() ); |
|
145 | + $parameters = $this->extractParametersFromQualifiers($constraintStatement->getQualifiers()); |
|
146 | 146 | return new Constraint( |
147 | 147 | $constraintId, |
148 | 148 | $propertyId, |
@@ -157,25 +157,25 @@ discard block |
||
157 | 157 | NumericPropertyId $propertyConstraintPropertyId |
158 | 158 | ) { |
159 | 159 | $constraintsStatements = $property->getStatements() |
160 | - ->getByPropertyId( $propertyConstraintPropertyId ) |
|
161 | - ->getByRank( [ Statement::RANK_PREFERRED, Statement::RANK_NORMAL ] ); |
|
160 | + ->getByPropertyId($propertyConstraintPropertyId) |
|
161 | + ->getByRank([Statement::RANK_PREFERRED, Statement::RANK_NORMAL]); |
|
162 | 162 | $constraints = []; |
163 | - foreach ( $constraintsStatements->getIterator() as $constraintStatement ) { |
|
163 | + foreach ($constraintsStatements->getIterator() as $constraintStatement) { |
|
164 | 164 | // @phan-suppress-next-line PhanTypeMismatchArgumentSuperType |
165 | - $constraints[] = $this->extractConstraintFromStatement( $property->getId(), $constraintStatement ); |
|
166 | - if ( count( $constraints ) >= self::BATCH_SIZE ) { |
|
167 | - $constraintStore->insertBatch( $constraints ); |
|
165 | + $constraints[] = $this->extractConstraintFromStatement($property->getId(), $constraintStatement); |
|
166 | + if (count($constraints) >= self::BATCH_SIZE) { |
|
167 | + $constraintStore->insertBatch($constraints); |
|
168 | 168 | // interrupt transaction and wait for replication |
169 | - $connection = $this->lbFactory->getMainLB()->getConnection( DB_PRIMARY ); |
|
170 | - $connection->endAtomic( __CLASS__ ); |
|
171 | - if ( !$connection->explicitTrxActive() ) { |
|
169 | + $connection = $this->lbFactory->getMainLB()->getConnection(DB_PRIMARY); |
|
170 | + $connection->endAtomic(__CLASS__); |
|
171 | + if (!$connection->explicitTrxActive()) { |
|
172 | 172 | $this->lbFactory->waitForReplication(); |
173 | 173 | } |
174 | - $connection->startAtomic( __CLASS__ ); |
|
174 | + $connection->startAtomic(__CLASS__); |
|
175 | 175 | $constraints = []; |
176 | 176 | } |
177 | 177 | } |
178 | - $constraintStore->insertBatch( $constraints ); |
|
178 | + $constraintStore->insertBatch($constraints); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -186,24 +186,24 @@ discard block |
||
186 | 186 | public function run() { |
187 | 187 | // TODO in the future: only touch constraints affected by the edit (requires T163465) |
188 | 188 | |
189 | - $propertyId = new NumericPropertyId( $this->propertyId ); |
|
189 | + $propertyId = new NumericPropertyId($this->propertyId); |
|
190 | 190 | $propertyRevision = $this->entityRevisionLookup->getEntityRevision( |
191 | 191 | $propertyId, |
192 | 192 | 0, // latest |
193 | 193 | LookupConstants::LATEST_FROM_REPLICA |
194 | 194 | ); |
195 | 195 | |
196 | - if ( $this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId ) { |
|
197 | - JobQueueGroup::singleton()->push( $this ); |
|
196 | + if ($this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId) { |
|
197 | + JobQueueGroup::singleton()->push($this); |
|
198 | 198 | return true; |
199 | 199 | } |
200 | 200 | |
201 | - $connection = $this->lbFactory->getMainLB()->getConnection( DB_PRIMARY ); |
|
201 | + $connection = $this->lbFactory->getMainLB()->getConnection(DB_PRIMARY); |
|
202 | 202 | // start transaction (if not started yet) – using __CLASS__, not __METHOD__, |
203 | 203 | // because importConstraintsForProperty() can interrupt the transaction |
204 | - $connection->startAtomic( __CLASS__ ); |
|
204 | + $connection->startAtomic(__CLASS__); |
|
205 | 205 | |
206 | - $this->constraintStore->deleteForProperty( $propertyId ); |
|
206 | + $this->constraintStore->deleteForProperty($propertyId); |
|
207 | 207 | |
208 | 208 | /** @var Property $property */ |
209 | 209 | $property = $propertyRevision->getEntity(); |
@@ -211,10 +211,10 @@ discard block |
||
211 | 211 | $this->importConstraintsForProperty( |
212 | 212 | $property, |
213 | 213 | $this->constraintStore, |
214 | - new NumericPropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ) |
|
214 | + new NumericPropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')) |
|
215 | 215 | ); |
216 | 216 | |
217 | - $connection->endAtomic( __CLASS__ ); |
|
217 | + $connection->endAtomic(__CLASS__); |
|
218 | 218 | |
219 | 219 | return true; |
220 | 220 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | /** |
27 | 27 | * @param BagOStuff $cache |
28 | 28 | */ |
29 | - public function __construct( BagOStuff $cache ) { |
|
29 | + public function __construct(BagOStuff $cache) { |
|
30 | 30 | $this->cache = $cache; |
31 | 31 | } |
32 | 32 | |
@@ -37,17 +37,17 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @throws \Wikimedia\Assert\ParameterTypeException |
39 | 39 | */ |
40 | - private function makeKey( $id ) { |
|
41 | - if ( empty( trim( $id ) ) ) { |
|
42 | - throw new ParameterTypeException( '$id', 'non-empty string' ); |
|
40 | + private function makeKey($id) { |
|
41 | + if (empty(trim($id))) { |
|
42 | + throw new ParameterTypeException('$id', 'non-empty string'); |
|
43 | 43 | } |
44 | 44 | |
45 | - Assert::parameterType( 'string', $id, '$id' ); |
|
45 | + Assert::parameterType('string', $id, '$id'); |
|
46 | 46 | |
47 | 47 | return $this->cache->makeKey( |
48 | 48 | 'WikibaseQualityConstraints', |
49 | 49 | 'ExpiryLock', |
50 | - (string)$id |
|
50 | + (string) $id |
|
51 | 51 | ); |
52 | 52 | } |
53 | 53 | |
@@ -59,15 +59,15 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @throws \Wikimedia\Assert\ParameterTypeException |
61 | 61 | */ |
62 | - public function lock( $id, ConvertibleTimestamp $expiryTimestamp ) { |
|
62 | + public function lock($id, ConvertibleTimestamp $expiryTimestamp) { |
|
63 | 63 | |
64 | - $cacheId = $this->makeKey( $id ); |
|
64 | + $cacheId = $this->makeKey($id); |
|
65 | 65 | |
66 | - if ( !$this->isLockedInternal( $cacheId ) ) { |
|
66 | + if (!$this->isLockedInternal($cacheId)) { |
|
67 | 67 | return $this->cache->set( |
68 | 68 | $cacheId, |
69 | - $expiryTimestamp->getTimestamp( TS_UNIX ), |
|
70 | - (int)$expiryTimestamp->getTimestamp( TS_UNIX ) |
|
69 | + $expiryTimestamp->getTimestamp(TS_UNIX), |
|
70 | + (int) $expiryTimestamp->getTimestamp(TS_UNIX) |
|
71 | 71 | ); |
72 | 72 | } else { |
73 | 73 | return false; |
@@ -81,20 +81,20 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @throws \Wikimedia\Assert\ParameterTypeException |
83 | 83 | */ |
84 | - private function isLockedInternal( $cacheId ) { |
|
85 | - $expiryTime = $this->cache->get( $cacheId ); |
|
86 | - if ( !$expiryTime ) { |
|
84 | + private function isLockedInternal($cacheId) { |
|
85 | + $expiryTime = $this->cache->get($cacheId); |
|
86 | + if (!$expiryTime) { |
|
87 | 87 | return false; |
88 | 88 | } |
89 | 89 | |
90 | 90 | try { |
91 | - $lockExpiryTimeStamp = new ConvertibleTimestamp( $expiryTime ); |
|
92 | - } catch ( TimestampException $exception ) { |
|
91 | + $lockExpiryTimeStamp = new ConvertibleTimestamp($expiryTime); |
|
92 | + } catch (TimestampException $exception) { |
|
93 | 93 | return false; |
94 | 94 | } |
95 | 95 | |
96 | 96 | $now = new ConvertibleTimestamp(); |
97 | - if ( $now->timestamp < $lockExpiryTimeStamp->timestamp ) { |
|
97 | + if ($now->timestamp < $lockExpiryTimeStamp->timestamp) { |
|
98 | 98 | return true; |
99 | 99 | } else { |
100 | 100 | return false; |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @throws \Wikimedia\Assert\ParameterTypeException |
110 | 110 | */ |
111 | - public function isLocked( $id ) { |
|
112 | - return $this->isLockedInternal( $this->makeKey( $id ) ); |
|
111 | + public function isLocked($id) { |
|
112 | + return $this->isLockedInternal($this->makeKey($id)); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | } |
@@ -71,20 +71,20 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return string HTML |
73 | 73 | */ |
74 | - public function formatValue( $value ) { |
|
75 | - if ( is_string( $value ) ) { |
|
74 | + public function formatValue($value) { |
|
75 | + if (is_string($value)) { |
|
76 | 76 | // Cases like 'Format' 'pattern' or 'minimum'/'maximum' values, which we have stored as |
77 | 77 | // strings |
78 | - return htmlspecialchars( $value ); |
|
79 | - } elseif ( $value instanceof EntityId ) { |
|
78 | + return htmlspecialchars($value); |
|
79 | + } elseif ($value instanceof EntityId) { |
|
80 | 80 | // Cases like 'Conflicts with' 'property', to which we can link |
81 | - return $this->formatEntityId( $value ); |
|
82 | - } elseif ( $value instanceof ItemIdSnakValue ) { |
|
81 | + return $this->formatEntityId($value); |
|
82 | + } elseif ($value instanceof ItemIdSnakValue) { |
|
83 | 83 | // Cases like EntityId but can also be somevalue or novalue |
84 | - return $this->formatItemIdSnakValue( $value ); |
|
84 | + return $this->formatItemIdSnakValue($value); |
|
85 | 85 | } else { |
86 | 86 | // Cases where we format a DataValue |
87 | - return $this->formatDataValue( $value ); |
|
87 | + return $this->formatDataValue($value); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
@@ -95,23 +95,23 @@ discard block |
||
95 | 95 | * |
96 | 96 | * @return string|null HTML |
97 | 97 | */ |
98 | - public function formatParameters( $parameters ) { |
|
99 | - if ( $parameters === null || $parameters === [] ) { |
|
98 | + public function formatParameters($parameters) { |
|
99 | + if ($parameters === null || $parameters === []) { |
|
100 | 100 | return null; |
101 | 101 | } |
102 | 102 | |
103 | - $valueFormatter = function ( $value ) { |
|
104 | - return $this->formatValue( $value ); |
|
103 | + $valueFormatter = function($value) { |
|
104 | + return $this->formatValue($value); |
|
105 | 105 | }; |
106 | 106 | |
107 | 107 | $formattedParameters = []; |
108 | - foreach ( $parameters as $parameterName => $parameterValue ) { |
|
109 | - $formattedParameterValues = implode( ', ', |
|
110 | - $this->limitArrayLength( array_map( $valueFormatter, $parameterValue ) ) ); |
|
111 | - $formattedParameters[] = sprintf( '%s: %s', $parameterName, $formattedParameterValues ); |
|
108 | + foreach ($parameters as $parameterName => $parameterValue) { |
|
109 | + $formattedParameterValues = implode(', ', |
|
110 | + $this->limitArrayLength(array_map($valueFormatter, $parameterValue))); |
|
111 | + $formattedParameters[] = sprintf('%s: %s', $parameterName, $formattedParameterValues); |
|
112 | 112 | } |
113 | 113 | |
114 | - return implode( '; ', $formattedParameters ); |
|
114 | + return implode('; ', $formattedParameters); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -121,10 +121,10 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @return string[] |
123 | 123 | */ |
124 | - private function limitArrayLength( array $array ) { |
|
125 | - if ( count( $array ) > self::MAX_PARAMETER_ARRAY_LENGTH ) { |
|
126 | - $array = array_slice( $array, 0, self::MAX_PARAMETER_ARRAY_LENGTH ); |
|
127 | - array_push( $array, '...' ); |
|
124 | + private function limitArrayLength(array $array) { |
|
125 | + if (count($array) > self::MAX_PARAMETER_ARRAY_LENGTH) { |
|
126 | + $array = array_slice($array, 0, self::MAX_PARAMETER_ARRAY_LENGTH); |
|
127 | + array_push($array, '...'); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | return $array; |
@@ -134,16 +134,16 @@ discard block |
||
134 | 134 | * @param DataValue $value |
135 | 135 | * @return string HTML |
136 | 136 | */ |
137 | - public function formatDataValue( DataValue $value ) { |
|
138 | - return $this->dataValueFormatter->format( $value ); |
|
137 | + public function formatDataValue(DataValue $value) { |
|
138 | + return $this->dataValueFormatter->format($value); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
142 | 142 | * @param EntityId $entityId |
143 | 143 | * @return string HTML |
144 | 144 | */ |
145 | - public function formatEntityId( EntityId $entityId ) { |
|
146 | - return $this->entityIdLabelFormatter->formatEntityId( $entityId ); |
|
145 | + public function formatEntityId(EntityId $entityId) { |
|
146 | + return $this->entityIdLabelFormatter->formatEntityId($entityId); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -152,17 +152,17 @@ discard block |
||
152 | 152 | * @param ItemIdSnakValue $value |
153 | 153 | * @return string HTML |
154 | 154 | */ |
155 | - public function formatItemIdSnakValue( ItemIdSnakValue $value ) { |
|
156 | - switch ( true ) { |
|
155 | + public function formatItemIdSnakValue(ItemIdSnakValue $value) { |
|
156 | + switch (true) { |
|
157 | 157 | case $value->isValue(): |
158 | - return $this->formatEntityId( $value->getItemId() ); |
|
158 | + return $this->formatEntityId($value->getItemId()); |
|
159 | 159 | case $value->isSomeValue(): |
160 | 160 | return $this->messageLocalizer |
161 | - ->msg( 'wikibase-snakview-snaktypeselector-somevalue' ) |
|
161 | + ->msg('wikibase-snakview-snaktypeselector-somevalue') |
|
162 | 162 | ->escaped(); |
163 | 163 | case $value->isNoValue(): |
164 | 164 | return $this->messageLocalizer |
165 | - ->msg( 'wikibase-snakview-snaktypeselector-novalue' ) |
|
165 | + ->msg('wikibase-snakview-snaktypeselector-novalue') |
|
166 | 166 | ->escaped(); |
167 | 167 | } |
168 | 168 | } |
@@ -200,73 +200,73 @@ discard block |
||
200 | 200 | $this->defaultUserAgent = $defaultUserAgent; |
201 | 201 | $this->requestFactory = $requestFactory; |
202 | 202 | $this->entityPrefixes = []; |
203 | - foreach ( $rdfVocabulary->entityNamespaceNames as $namespaceName ) { |
|
204 | - $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI( $namespaceName ); |
|
203 | + foreach ($rdfVocabulary->entityNamespaceNames as $namespaceName) { |
|
204 | + $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI($namespaceName); |
|
205 | 205 | } |
206 | 206 | |
207 | - $this->endpoint = $config->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
208 | - $this->maxQueryTimeMillis = $config->get( 'WBQualityConstraintsSparqlMaxMillis' ); |
|
209 | - $this->instanceOfId = $config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
210 | - $this->subclassOfId = $config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
211 | - $this->cacheMapSize = $config->get( 'WBQualityConstraintsFormatCacheMapSize' ); |
|
207 | + $this->endpoint = $config->get('WBQualityConstraintsSparqlEndpoint'); |
|
208 | + $this->maxQueryTimeMillis = $config->get('WBQualityConstraintsSparqlMaxMillis'); |
|
209 | + $this->instanceOfId = $config->get('WBQualityConstraintsInstanceOfId'); |
|
210 | + $this->subclassOfId = $config->get('WBQualityConstraintsSubclassOfId'); |
|
211 | + $this->cacheMapSize = $config->get('WBQualityConstraintsFormatCacheMapSize'); |
|
212 | 212 | $this->timeoutExceptionClasses = $config->get( |
213 | 213 | 'WBQualityConstraintsSparqlTimeoutExceptionClasses' |
214 | 214 | ); |
215 | 215 | $this->sparqlHasWikibaseSupport = $config->get( |
216 | 216 | 'WBQualityConstraintsSparqlHasWikibaseSupport' |
217 | 217 | ); |
218 | - $this->sparqlThrottlingFallbackDuration = (int)$config->get( |
|
218 | + $this->sparqlThrottlingFallbackDuration = (int) $config->get( |
|
219 | 219 | 'WBQualityConstraintsSparqlThrottlingFallbackDuration' |
220 | 220 | ); |
221 | 221 | |
222 | - $this->prefixes = $this->getQueryPrefixes( $rdfVocabulary ); |
|
222 | + $this->prefixes = $this->getQueryPrefixes($rdfVocabulary); |
|
223 | 223 | } |
224 | 224 | |
225 | - private function getQueryPrefixes( RdfVocabulary $rdfVocabulary ) { |
|
225 | + private function getQueryPrefixes(RdfVocabulary $rdfVocabulary) { |
|
226 | 226 | // TODO: it would probably be smarter that RdfVocubulary exposed these prefixes somehow |
227 | 227 | $prefixes = ''; |
228 | - foreach ( $rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName ) { |
|
228 | + foreach ($rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName) { |
|
229 | 229 | $prefixes .= <<<END |
230 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
230 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
231 | 231 | END; |
232 | 232 | } |
233 | 233 | $prefixes .= <<<END |
234 | -PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}> |
|
235 | -PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}>\n |
|
234 | +PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}> |
|
235 | +PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}>\n |
|
236 | 236 | END; |
237 | 237 | |
238 | - foreach ( $rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces ) { |
|
238 | + foreach ($rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces) { |
|
239 | 239 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_DIRECT_CLAIM]; |
240 | 240 | $prefixes .= <<<END |
241 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
241 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
242 | 242 | END; |
243 | 243 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM]; |
244 | 244 | $prefixes .= <<<END |
245 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
245 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
246 | 246 | END; |
247 | 247 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM_STATEMENT]; |
248 | 248 | $prefixes .= <<<END |
249 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
249 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
250 | 250 | END; |
251 | 251 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER]; |
252 | 252 | $prefixes .= <<<END |
253 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
253 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
254 | 254 | END; |
255 | 255 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER_VALUE]; |
256 | 256 | $prefixes .= <<<END |
257 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
257 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
258 | 258 | END; |
259 | 259 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE]; |
260 | 260 | $prefixes .= <<<END |
261 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
261 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
262 | 262 | END; |
263 | 263 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE_VALUE]; |
264 | 264 | $prefixes .= <<<END |
265 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
265 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
266 | 266 | END; |
267 | 267 | } |
268 | 268 | $prefixes .= <<<END |
269 | -PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ONTOLOGY )}>\n |
|
269 | +PREFIX wikibase: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ONTOLOGY)}>\n |
|
270 | 270 | END; |
271 | 271 | return $prefixes; |
272 | 272 | } |
@@ -278,21 +278,20 @@ discard block |
||
278 | 278 | * @return CachedBool |
279 | 279 | * @throws SparqlHelperException if the query times out or some other error occurs |
280 | 280 | */ |
281 | - public function hasType( $id, array $classes ) { |
|
281 | + public function hasType($id, array $classes) { |
|
282 | 282 | // TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually |
283 | 283 | $gearingHint = $this->sparqlHasWikibaseSupport ? |
284 | - ' hint:Prior hint:gearing "forward".' : |
|
285 | - ''; |
|
284 | + ' hint:Prior hint:gearing "forward".' : ''; |
|
286 | 285 | |
287 | 286 | $metadatas = []; |
288 | 287 | |
289 | - foreach ( array_chunk( $classes, 20 ) as $classesChunk ) { |
|
290 | - $classesValues = implode( ' ', array_map( |
|
291 | - static function ( $class ) { |
|
292 | - return 'wd:' . $class; |
|
288 | + foreach (array_chunk($classes, 20) as $classesChunk) { |
|
289 | + $classesValues = implode(' ', array_map( |
|
290 | + static function($class) { |
|
291 | + return 'wd:'.$class; |
|
293 | 292 | }, |
294 | 293 | $classesChunk |
295 | - ) ); |
|
294 | + )); |
|
296 | 295 | |
297 | 296 | $query = <<<EOF |
298 | 297 | ASK { |
@@ -302,19 +301,19 @@ discard block |
||
302 | 301 | } |
303 | 302 | EOF; |
304 | 303 | |
305 | - $result = $this->runQuery( $query ); |
|
304 | + $result = $this->runQuery($query); |
|
306 | 305 | $metadatas[] = $result->getMetadata(); |
307 | - if ( $result->getArray()['boolean'] ) { |
|
306 | + if ($result->getArray()['boolean']) { |
|
308 | 307 | return new CachedBool( |
309 | 308 | true, |
310 | - Metadata::merge( $metadatas ) |
|
309 | + Metadata::merge($metadatas) |
|
311 | 310 | ); |
312 | 311 | } |
313 | 312 | } |
314 | 313 | |
315 | 314 | return new CachedBool( |
316 | 315 | false, |
317 | - Metadata::merge( $metadatas ) |
|
316 | + Metadata::merge($metadatas) |
|
318 | 317 | ); |
319 | 318 | } |
320 | 319 | |
@@ -325,7 +324,7 @@ discard block |
||
325 | 324 | * @param PropertyId $separator |
326 | 325 | * @return string |
327 | 326 | */ |
328 | - private function nestedSeparatorFilter( PropertyId $separator ) { |
|
327 | + private function nestedSeparatorFilter(PropertyId $separator) { |
|
329 | 328 | $filter = <<<EOF |
330 | 329 | MINUS { |
331 | 330 | ?statement pq:$separator ?qualifier. |
@@ -367,10 +366,10 @@ discard block |
||
367 | 366 | array $separators |
368 | 367 | ) { |
369 | 368 | $pid = $statement->getPropertyId()->serialize(); |
370 | - $guid = str_replace( '$', '-', $statement->getGuid() ); |
|
369 | + $guid = str_replace('$', '-', $statement->getGuid()); |
|
371 | 370 | |
372 | - $separatorFilters = array_map( [ $this, 'nestedSeparatorFilter' ], $separators ); |
|
373 | - $finalSeparatorFilter = implode( "\n", $separatorFilters ); |
|
371 | + $separatorFilters = array_map([$this, 'nestedSeparatorFilter'], $separators); |
|
372 | + $finalSeparatorFilter = implode("\n", $separatorFilters); |
|
374 | 373 | |
375 | 374 | $query = <<<EOF |
376 | 375 | SELECT DISTINCT ?otherEntity WHERE { |
@@ -388,9 +387,9 @@ discard block |
||
388 | 387 | LIMIT 10 |
389 | 388 | EOF; |
390 | 389 | |
391 | - $result = $this->runQuery( $query ); |
|
390 | + $result = $this->runQuery($query); |
|
392 | 391 | |
393 | - return $this->getOtherEntities( $result ); |
|
392 | + return $this->getOtherEntities($result); |
|
394 | 393 | } |
395 | 394 | |
396 | 395 | /** |
@@ -415,16 +414,15 @@ discard block |
||
415 | 414 | $dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty( |
416 | 415 | $snak->getPropertyId() |
417 | 416 | ); |
418 | - list( $value, $isFullValue ) = $this->getRdfLiteral( $dataType, $dataValue ); |
|
419 | - if ( $isFullValue ) { |
|
417 | + list($value, $isFullValue) = $this->getRdfLiteral($dataType, $dataValue); |
|
418 | + if ($isFullValue) { |
|
420 | 419 | $prefix .= 'v'; |
421 | 420 | } |
422 | 421 | $path = $type === Context::TYPE_QUALIFIER ? |
423 | - "$prefix:$pid" : |
|
424 | - "prov:wasDerivedFrom/$prefix:$pid"; |
|
422 | + "$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid"; |
|
425 | 423 | |
426 | 424 | $deprecatedFilter = ''; |
427 | - if ( $ignoreDeprecatedStatements ) { |
|
425 | + if ($ignoreDeprecatedStatements) { |
|
428 | 426 | $deprecatedFilter = <<< EOF |
429 | 427 | MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. } |
430 | 428 | EOF; |
@@ -444,9 +442,9 @@ discard block |
||
444 | 442 | LIMIT 10 |
445 | 443 | EOF; |
446 | 444 | |
447 | - $result = $this->runQuery( $query ); |
|
445 | + $result = $this->runQuery($query); |
|
448 | 446 | |
449 | - return $this->getOtherEntities( $result ); |
|
447 | + return $this->getOtherEntities($result); |
|
450 | 448 | } |
451 | 449 | |
452 | 450 | /** |
@@ -456,8 +454,8 @@ discard block |
||
456 | 454 | * |
457 | 455 | * @return string |
458 | 456 | */ |
459 | - private function stringLiteral( $text ) { |
|
460 | - return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"'; |
|
457 | + private function stringLiteral($text) { |
|
458 | + return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"'; |
|
461 | 459 | } |
462 | 460 | |
463 | 461 | /** |
@@ -467,18 +465,18 @@ discard block |
||
467 | 465 | * |
468 | 466 | * @return CachedEntityIds |
469 | 467 | */ |
470 | - private function getOtherEntities( CachedQueryResults $results ) { |
|
471 | - return new CachedEntityIds( array_map( |
|
472 | - function ( $resultBindings ) { |
|
468 | + private function getOtherEntities(CachedQueryResults $results) { |
|
469 | + return new CachedEntityIds(array_map( |
|
470 | + function($resultBindings) { |
|
473 | 471 | $entityIRI = $resultBindings['otherEntity']['value']; |
474 | - foreach ( $this->entityPrefixes as $entityPrefix ) { |
|
475 | - $entityPrefixLength = strlen( $entityPrefix ); |
|
476 | - if ( substr( $entityIRI, 0, $entityPrefixLength ) === $entityPrefix ) { |
|
472 | + foreach ($this->entityPrefixes as $entityPrefix) { |
|
473 | + $entityPrefixLength = strlen($entityPrefix); |
|
474 | + if (substr($entityIRI, 0, $entityPrefixLength) === $entityPrefix) { |
|
477 | 475 | try { |
478 | 476 | return $this->entityIdParser->parse( |
479 | - substr( $entityIRI, $entityPrefixLength ) |
|
477 | + substr($entityIRI, $entityPrefixLength) |
|
480 | 478 | ); |
481 | - } catch ( EntityIdParsingException $e ) { |
|
479 | + } catch (EntityIdParsingException $e) { |
|
482 | 480 | // fall through |
483 | 481 | } |
484 | 482 | } |
@@ -489,7 +487,7 @@ discard block |
||
489 | 487 | return null; |
490 | 488 | }, |
491 | 489 | $results->getArray()['results']['bindings'] |
492 | - ), $results->getMetadata() ); |
|
490 | + ), $results->getMetadata()); |
|
493 | 491 | } |
494 | 492 | |
495 | 493 | // phpcs:disable Generic.Metrics.CyclomaticComplexity,Squiz.WhiteSpace.FunctionSpacing |
@@ -502,50 +500,50 @@ discard block |
||
502 | 500 | * @return array the literal or IRI as a string in SPARQL syntax, |
503 | 501 | * and a boolean indicating whether it refers to a full value node or not |
504 | 502 | */ |
505 | - private function getRdfLiteral( $dataType, DataValue $dataValue ) { |
|
506 | - switch ( $dataType ) { |
|
503 | + private function getRdfLiteral($dataType, DataValue $dataValue) { |
|
504 | + switch ($dataType) { |
|
507 | 505 | case 'string': |
508 | 506 | case 'external-id': |
509 | - return [ $this->stringLiteral( $dataValue->getValue() ), false ]; |
|
507 | + return [$this->stringLiteral($dataValue->getValue()), false]; |
|
510 | 508 | case 'commonsMedia': |
511 | - $url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() ); |
|
512 | - return [ '<' . $url . '>', false ]; |
|
509 | + $url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue()); |
|
510 | + return ['<'.$url.'>', false]; |
|
513 | 511 | case 'geo-shape': |
514 | - $url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() ); |
|
515 | - return [ '<' . $url . '>', false ]; |
|
512 | + $url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue()); |
|
513 | + return ['<'.$url.'>', false]; |
|
516 | 514 | case 'tabular-data': |
517 | - $url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() ); |
|
518 | - return [ '<' . $url . '>', false ]; |
|
515 | + $url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue()); |
|
516 | + return ['<'.$url.'>', false]; |
|
519 | 517 | case 'url': |
520 | 518 | $url = $dataValue->getValue(); |
521 | - if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) { |
|
519 | + if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) { |
|
522 | 520 | // not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF) |
523 | 521 | // such an URL should never reach us, so just throw |
524 | - throw new InvalidArgumentException( 'invalid URL: ' . $url ); |
|
522 | + throw new InvalidArgumentException('invalid URL: '.$url); |
|
525 | 523 | } |
526 | - return [ '<' . $url . '>', false ]; |
|
524 | + return ['<'.$url.'>', false]; |
|
527 | 525 | case 'wikibase-item': |
528 | 526 | case 'wikibase-property': |
529 | 527 | /** @var EntityIdValue $dataValue */ |
530 | 528 | '@phan-var EntityIdValue $dataValue'; |
531 | - return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ]; |
|
529 | + return ['wd:'.$dataValue->getEntityId()->getSerialization(), false]; |
|
532 | 530 | case 'monolingualtext': |
533 | 531 | /** @var MonolingualTextValue $dataValue */ |
534 | 532 | '@phan-var MonolingualTextValue $dataValue'; |
535 | 533 | $lang = $dataValue->getLanguageCode(); |
536 | - if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) { |
|
534 | + if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) { |
|
537 | 535 | // not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG) |
538 | 536 | // such a language tag should never reach us, so just throw |
539 | - throw new InvalidArgumentException( 'invalid language tag: ' . $lang ); |
|
537 | + throw new InvalidArgumentException('invalid language tag: '.$lang); |
|
540 | 538 | } |
541 | - return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ]; |
|
539 | + return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false]; |
|
542 | 540 | case 'globe-coordinate': |
543 | 541 | case 'quantity': |
544 | 542 | case 'time': |
545 | 543 | // @phan-suppress-next-line PhanUndeclaredMethod |
546 | - return [ 'wdv:' . $dataValue->getHash(), true ]; |
|
544 | + return ['wdv:'.$dataValue->getHash(), true]; |
|
547 | 545 | default: |
548 | - throw new InvalidArgumentException( 'unknown data type: ' . $dataType ); |
|
546 | + throw new InvalidArgumentException('unknown data type: '.$dataType); |
|
549 | 547 | } |
550 | 548 | } |
551 | 549 | // phpcs:enable |
@@ -558,43 +556,43 @@ discard block |
||
558 | 556 | * @throws SparqlHelperException if the query times out or some other error occurs |
559 | 557 | * @throws ConstraintParameterException if the $regex is invalid |
560 | 558 | */ |
561 | - public function matchesRegularExpression( $text, $regex ) { |
|
559 | + public function matchesRegularExpression($text, $regex) { |
|
562 | 560 | // caching wrapper around matchesRegularExpressionWithSparql |
563 | 561 | |
564 | - $textHash = hash( 'sha256', $text ); |
|
562 | + $textHash = hash('sha256', $text); |
|
565 | 563 | $cacheKey = $this->cache->makeKey( |
566 | 564 | 'WikibaseQualityConstraints', // extension |
567 | 565 | 'regex', // action |
568 | 566 | 'WDQS-Java', // regex flavor |
569 | - hash( 'sha256', $regex ) |
|
567 | + hash('sha256', $regex) |
|
570 | 568 | ); |
571 | 569 | |
572 | 570 | $cacheMapArray = $this->cache->getWithSetCallback( |
573 | 571 | $cacheKey, |
574 | 572 | WANObjectCache::TTL_DAY, |
575 | - function ( $cacheMapArray ) use ( $text, $regex, $textHash ) { |
|
573 | + function($cacheMapArray) use ($text, $regex, $textHash) { |
|
576 | 574 | // Initialize the cache map if not set |
577 | - if ( $cacheMapArray === false ) { |
|
575 | + if ($cacheMapArray === false) { |
|
578 | 576 | $key = 'wikibase.quality.constraints.regex.cache.refresh.init'; |
579 | - $this->dataFactory->increment( $key ); |
|
577 | + $this->dataFactory->increment($key); |
|
580 | 578 | return []; |
581 | 579 | } |
582 | 580 | |
583 | 581 | $key = 'wikibase.quality.constraints.regex.cache.refresh'; |
584 | - $this->dataFactory->increment( $key ); |
|
585 | - $cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $this->cacheMapSize ); |
|
586 | - if ( $cacheMap->has( $textHash ) ) { |
|
582 | + $this->dataFactory->increment($key); |
|
583 | + $cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $this->cacheMapSize); |
|
584 | + if ($cacheMap->has($textHash)) { |
|
587 | 585 | $key = 'wikibase.quality.constraints.regex.cache.refresh.hit'; |
588 | - $this->dataFactory->increment( $key ); |
|
589 | - $cacheMap->get( $textHash ); // ping cache |
|
586 | + $this->dataFactory->increment($key); |
|
587 | + $cacheMap->get($textHash); // ping cache |
|
590 | 588 | } else { |
591 | 589 | $key = 'wikibase.quality.constraints.regex.cache.refresh.miss'; |
592 | - $this->dataFactory->increment( $key ); |
|
590 | + $this->dataFactory->increment($key); |
|
593 | 591 | try { |
594 | - $matches = $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
595 | - } catch ( ConstraintParameterException $e ) { |
|
596 | - $matches = $this->serializeConstraintParameterException( $e ); |
|
597 | - } catch ( SparqlHelperException $e ) { |
|
592 | + $matches = $this->matchesRegularExpressionWithSparql($text, $regex); |
|
593 | + } catch (ConstraintParameterException $e) { |
|
594 | + $matches = $this->serializeConstraintParameterException($e); |
|
595 | + } catch (SparqlHelperException $e) { |
|
598 | 596 | // don’t cache this |
599 | 597 | return $cacheMap->toArray(); |
600 | 598 | } |
@@ -618,42 +616,42 @@ discard block |
||
618 | 616 | ] |
619 | 617 | ); |
620 | 618 | |
621 | - if ( isset( $cacheMapArray[$textHash] ) ) { |
|
619 | + if (isset($cacheMapArray[$textHash])) { |
|
622 | 620 | $key = 'wikibase.quality.constraints.regex.cache.hit'; |
623 | - $this->dataFactory->increment( $key ); |
|
621 | + $this->dataFactory->increment($key); |
|
624 | 622 | $matches = $cacheMapArray[$textHash]; |
625 | - if ( is_bool( $matches ) ) { |
|
623 | + if (is_bool($matches)) { |
|
626 | 624 | return $matches; |
627 | - } elseif ( is_array( $matches ) && |
|
628 | - $matches['type'] == ConstraintParameterException::class ) { |
|
629 | - throw $this->deserializeConstraintParameterException( $matches ); |
|
625 | + } elseif (is_array($matches) && |
|
626 | + $matches['type'] == ConstraintParameterException::class) { |
|
627 | + throw $this->deserializeConstraintParameterException($matches); |
|
630 | 628 | } else { |
631 | 629 | throw new MWException( |
632 | - 'Value of unknown type in object cache (' . |
|
633 | - 'cache key: ' . $cacheKey . ', ' . |
|
634 | - 'cache map key: ' . $textHash . ', ' . |
|
635 | - 'value type: ' . gettype( $matches ) . ')' |
|
630 | + 'Value of unknown type in object cache ('. |
|
631 | + 'cache key: '.$cacheKey.', '. |
|
632 | + 'cache map key: '.$textHash.', '. |
|
633 | + 'value type: '.gettype($matches).')' |
|
636 | 634 | ); |
637 | 635 | } |
638 | 636 | } else { |
639 | 637 | $key = 'wikibase.quality.constraints.regex.cache.miss'; |
640 | - $this->dataFactory->increment( $key ); |
|
641 | - return $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
638 | + $this->dataFactory->increment($key); |
|
639 | + return $this->matchesRegularExpressionWithSparql($text, $regex); |
|
642 | 640 | } |
643 | 641 | } |
644 | 642 | |
645 | - private function serializeConstraintParameterException( ConstraintParameterException $cpe ) { |
|
643 | + private function serializeConstraintParameterException(ConstraintParameterException $cpe) { |
|
646 | 644 | return [ |
647 | 645 | 'type' => ConstraintParameterException::class, |
648 | - 'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ), |
|
646 | + 'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()), |
|
649 | 647 | ]; |
650 | 648 | } |
651 | 649 | |
652 | - private function deserializeConstraintParameterException( array $serialization ) { |
|
650 | + private function deserializeConstraintParameterException(array $serialization) { |
|
653 | 651 | $message = $this->violationMessageDeserializer->deserialize( |
654 | 652 | $serialization['violationMessage'] |
655 | 653 | ); |
656 | - return new ConstraintParameterException( $message ); |
|
654 | + return new ConstraintParameterException($message); |
|
657 | 655 | } |
658 | 656 | |
659 | 657 | /** |
@@ -667,25 +665,25 @@ discard block |
||
667 | 665 | * @throws SparqlHelperException if the query times out or some other error occurs |
668 | 666 | * @throws ConstraintParameterException if the $regex is invalid |
669 | 667 | */ |
670 | - public function matchesRegularExpressionWithSparql( $text, $regex ) { |
|
671 | - $textStringLiteral = $this->stringLiteral( $text ); |
|
672 | - $regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' ); |
|
668 | + public function matchesRegularExpressionWithSparql($text, $regex) { |
|
669 | + $textStringLiteral = $this->stringLiteral($text); |
|
670 | + $regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$'); |
|
673 | 671 | |
674 | 672 | $query = <<<EOF |
675 | 673 | SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {} |
676 | 674 | EOF; |
677 | 675 | |
678 | - $result = $this->runQuery( $query, false ); |
|
676 | + $result = $this->runQuery($query, false); |
|
679 | 677 | |
680 | 678 | $vars = $result->getArray()['results']['bindings'][0]; |
681 | - if ( array_key_exists( 'matches', $vars ) ) { |
|
679 | + if (array_key_exists('matches', $vars)) { |
|
682 | 680 | // true or false ⇒ regex okay, text matches or not |
683 | 681 | return $vars['matches']['value'] === 'true'; |
684 | 682 | } else { |
685 | 683 | // empty result: regex broken |
686 | 684 | throw new ConstraintParameterException( |
687 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
688 | - ->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
685 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
686 | + ->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE) |
|
689 | 687 | ); |
690 | 688 | } |
691 | 689 | } |
@@ -697,14 +695,14 @@ discard block |
||
697 | 695 | * |
698 | 696 | * @return boolean |
699 | 697 | */ |
700 | - public function isTimeout( $responseContent ) { |
|
701 | - $timeoutRegex = implode( '|', array_map( |
|
702 | - static function ( $fqn ) { |
|
703 | - return preg_quote( $fqn, '/' ); |
|
698 | + public function isTimeout($responseContent) { |
|
699 | + $timeoutRegex = implode('|', array_map( |
|
700 | + static function($fqn) { |
|
701 | + return preg_quote($fqn, '/'); |
|
704 | 702 | }, |
705 | 703 | $this->timeoutExceptionClasses |
706 | - ) ); |
|
707 | - return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent ); |
|
704 | + )); |
|
705 | + return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent); |
|
708 | 706 | } |
709 | 707 | |
710 | 708 | /** |
@@ -716,17 +714,17 @@ discard block |
||
716 | 714 | * @return int|boolean the max-age (in seconds) |
717 | 715 | * or a plain boolean if no max-age can be determined |
718 | 716 | */ |
719 | - public function getCacheMaxAge( $responseHeaders ) { |
|
717 | + public function getCacheMaxAge($responseHeaders) { |
|
720 | 718 | if ( |
721 | - array_key_exists( 'x-cache-status', $responseHeaders ) && |
|
722 | - preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] ) |
|
719 | + array_key_exists('x-cache-status', $responseHeaders) && |
|
720 | + preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0]) |
|
723 | 721 | ) { |
724 | 722 | $maxage = []; |
725 | 723 | if ( |
726 | - array_key_exists( 'cache-control', $responseHeaders ) && |
|
727 | - preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage ) |
|
724 | + array_key_exists('cache-control', $responseHeaders) && |
|
725 | + preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage) |
|
728 | 726 | ) { |
729 | - return intval( $maxage[1] ); |
|
727 | + return intval($maxage[1]); |
|
730 | 728 | } else { |
731 | 729 | return true; |
732 | 730 | } |
@@ -747,34 +745,34 @@ discard block |
||
747 | 745 | * or SparlHelper::EMPTY_RETRY_AFTER if there is an empty Retry-After |
748 | 746 | * or SparlHelper::INVALID_RETRY_AFTER if there is something wrong with the format |
749 | 747 | */ |
750 | - public function getThrottling( MWHttpRequest $request ) { |
|
751 | - $retryAfterValue = $request->getResponseHeader( 'Retry-After' ); |
|
752 | - if ( $retryAfterValue === null ) { |
|
748 | + public function getThrottling(MWHttpRequest $request) { |
|
749 | + $retryAfterValue = $request->getResponseHeader('Retry-After'); |
|
750 | + if ($retryAfterValue === null) { |
|
753 | 751 | return self::NO_RETRY_AFTER; |
754 | 752 | } |
755 | 753 | |
756 | - $trimmedRetryAfterValue = trim( $retryAfterValue ); |
|
757 | - if ( empty( $trimmedRetryAfterValue ) ) { |
|
754 | + $trimmedRetryAfterValue = trim($retryAfterValue); |
|
755 | + if (empty($trimmedRetryAfterValue)) { |
|
758 | 756 | return self::EMPTY_RETRY_AFTER; |
759 | 757 | } |
760 | 758 | |
761 | - if ( is_numeric( $trimmedRetryAfterValue ) ) { |
|
762 | - $delaySeconds = (int)$trimmedRetryAfterValue; |
|
763 | - if ( $delaySeconds >= 0 ) { |
|
764 | - return $this->getTimestampInFuture( new DateInterval( 'PT' . $delaySeconds . 'S' ) ); |
|
759 | + if (is_numeric($trimmedRetryAfterValue)) { |
|
760 | + $delaySeconds = (int) $trimmedRetryAfterValue; |
|
761 | + if ($delaySeconds >= 0) { |
|
762 | + return $this->getTimestampInFuture(new DateInterval('PT'.$delaySeconds.'S')); |
|
765 | 763 | } |
766 | 764 | } else { |
767 | - $return = strtotime( $trimmedRetryAfterValue ); |
|
768 | - if ( !empty( $return ) ) { |
|
769 | - return new ConvertibleTimestamp( $return ); |
|
765 | + $return = strtotime($trimmedRetryAfterValue); |
|
766 | + if (!empty($return)) { |
|
767 | + return new ConvertibleTimestamp($return); |
|
770 | 768 | } |
771 | 769 | } |
772 | 770 | return self::INVALID_RETRY_AFTER; |
773 | 771 | } |
774 | 772 | |
775 | - private function getTimestampInFuture( DateInterval $delta ) { |
|
773 | + private function getTimestampInFuture(DateInterval $delta) { |
|
776 | 774 | $now = new ConvertibleTimestamp(); |
777 | - return new ConvertibleTimestamp( $now->timestamp->add( $delta ) ); |
|
775 | + return new ConvertibleTimestamp($now->timestamp->add($delta)); |
|
778 | 776 | } |
779 | 777 | |
780 | 778 | /** |
@@ -788,65 +786,64 @@ discard block |
||
788 | 786 | * |
789 | 787 | * @throws SparqlHelperException if the query times out or some other error occurs |
790 | 788 | */ |
791 | - public function runQuery( $query, $needsPrefixes = true ) { |
|
789 | + public function runQuery($query, $needsPrefixes = true) { |
|
792 | 790 | |
793 | - if ( $this->throttlingLock->isLocked( self::EXPIRY_LOCK_ID ) ) { |
|
794 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
791 | + if ($this->throttlingLock->isLocked(self::EXPIRY_LOCK_ID)) { |
|
792 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
795 | 793 | throw new TooManySparqlRequestsException(); |
796 | 794 | } |
797 | 795 | |
798 | - if ( $this->sparqlHasWikibaseSupport ) { |
|
796 | + if ($this->sparqlHasWikibaseSupport) { |
|
799 | 797 | $needsPrefixes = false; |
800 | 798 | } |
801 | 799 | |
802 | - if ( $needsPrefixes ) { |
|
803 | - $query = $this->prefixes . $query; |
|
800 | + if ($needsPrefixes) { |
|
801 | + $query = $this->prefixes.$query; |
|
804 | 802 | } |
805 | - $query = "#wbqc\n" . $query; |
|
803 | + $query = "#wbqc\n".$query; |
|
806 | 804 | |
807 | - $url = $this->endpoint . '?' . http_build_query( |
|
805 | + $url = $this->endpoint.'?'.http_build_query( |
|
808 | 806 | [ |
809 | 807 | 'query' => $query, |
810 | 808 | 'format' => 'json', |
811 | 809 | 'maxQueryTimeMillis' => $this->maxQueryTimeMillis, |
812 | 810 | ], |
813 | - '', ini_get( 'arg_separator.output' ), |
|
811 | + '', ini_get('arg_separator.output'), |
|
814 | 812 | // encode spaces with %20, not + |
815 | 813 | PHP_QUERY_RFC3986 |
816 | 814 | ); |
817 | 815 | |
818 | 816 | $options = [ |
819 | 817 | 'method' => 'GET', |
820 | - 'timeout' => (int)round( ( $this->maxQueryTimeMillis + 1000 ) / 1000 ), |
|
818 | + 'timeout' => (int) round(($this->maxQueryTimeMillis + 1000) / 1000), |
|
821 | 819 | 'connectTimeout' => 'default', |
822 | 820 | 'userAgent' => $this->defaultUserAgent, |
823 | 821 | ]; |
824 | - $request = $this->requestFactory->create( $url, $options, __METHOD__ ); |
|
825 | - $startTime = microtime( true ); |
|
822 | + $request = $this->requestFactory->create($url, $options, __METHOD__); |
|
823 | + $startTime = microtime(true); |
|
826 | 824 | $requestStatus = $request->execute(); |
827 | - $endTime = microtime( true ); |
|
825 | + $endTime = microtime(true); |
|
828 | 826 | $this->dataFactory->timing( |
829 | 827 | 'wikibase.quality.constraints.sparql.timing', |
830 | - ( $endTime - $startTime ) * 1000 |
|
828 | + ($endTime - $startTime) * 1000 |
|
831 | 829 | ); |
832 | 830 | |
833 | - $this->guardAgainstTooManyRequestsError( $request ); |
|
831 | + $this->guardAgainstTooManyRequestsError($request); |
|
834 | 832 | |
835 | - $maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() ); |
|
836 | - if ( $maxAge ) { |
|
837 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' ); |
|
833 | + $maxAge = $this->getCacheMaxAge($request->getResponseHeaders()); |
|
834 | + if ($maxAge) { |
|
835 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.cached'); |
|
838 | 836 | } |
839 | 837 | |
840 | - if ( $requestStatus->isOK() ) { |
|
838 | + if ($requestStatus->isOK()) { |
|
841 | 839 | $json = $request->getContent(); |
842 | - $jsonStatus = FormatJson::parse( $json, FormatJson::FORCE_ASSOC ); |
|
843 | - if ( $jsonStatus->isOK() ) { |
|
840 | + $jsonStatus = FormatJson::parse($json, FormatJson::FORCE_ASSOC); |
|
841 | + if ($jsonStatus->isOK()) { |
|
844 | 842 | return new CachedQueryResults( |
845 | 843 | $jsonStatus->getValue(), |
846 | 844 | Metadata::ofCachingMetadata( |
847 | 845 | $maxAge ? |
848 | - CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) : |
|
849 | - CachingMetadata::fresh() |
|
846 | + CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh() |
|
850 | 847 | ) |
851 | 848 | ); |
852 | 849 | } else { |
@@ -863,9 +860,9 @@ discard block |
||
863 | 860 | // fall through to general error handling |
864 | 861 | } |
865 | 862 | |
866 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' ); |
|
863 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.error'); |
|
867 | 864 | |
868 | - if ( $this->isTimeout( $request->getContent() ) ) { |
|
865 | + if ($this->isTimeout($request->getContent())) { |
|
869 | 866 | $this->dataFactory->increment( |
870 | 867 | 'wikibase.quality.constraints.sparql.error.timeout' |
871 | 868 | ); |
@@ -880,29 +877,29 @@ discard block |
||
880 | 877 | * @param MWHttpRequest $request |
881 | 878 | * @throws TooManySparqlRequestsException |
882 | 879 | */ |
883 | - private function guardAgainstTooManyRequestsError( MWHttpRequest $request ): void { |
|
884 | - if ( $request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS ) { |
|
880 | + private function guardAgainstTooManyRequestsError(MWHttpRequest $request): void { |
|
881 | + if ($request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS) { |
|
885 | 882 | return; |
886 | 883 | } |
887 | 884 | |
888 | 885 | $fallbackBlockDuration = $this->sparqlThrottlingFallbackDuration; |
889 | 886 | |
890 | - if ( $fallbackBlockDuration < 0 ) { |
|
891 | - throw new InvalidArgumentException( 'Fallback duration must be positive int but is: ' . |
|
892 | - $fallbackBlockDuration ); |
|
887 | + if ($fallbackBlockDuration < 0) { |
|
888 | + throw new InvalidArgumentException('Fallback duration must be positive int but is: '. |
|
889 | + $fallbackBlockDuration); |
|
893 | 890 | } |
894 | 891 | |
895 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
896 | - $throttlingUntil = $this->getThrottling( $request ); |
|
897 | - if ( !( $throttlingUntil instanceof ConvertibleTimestamp ) ) { |
|
898 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid( $request ); |
|
892 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
893 | + $throttlingUntil = $this->getThrottling($request); |
|
894 | + if (!($throttlingUntil instanceof ConvertibleTimestamp)) { |
|
895 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid($request); |
|
899 | 896 | $this->throttlingLock->lock( |
900 | 897 | self::EXPIRY_LOCK_ID, |
901 | - $this->getTimestampInFuture( new DateInterval( 'PT' . $fallbackBlockDuration . 'S' ) ) |
|
898 | + $this->getTimestampInFuture(new DateInterval('PT'.$fallbackBlockDuration.'S')) |
|
902 | 899 | ); |
903 | 900 | } else { |
904 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent( $throttlingUntil, $request ); |
|
905 | - $this->throttlingLock->lock( self::EXPIRY_LOCK_ID, $throttlingUntil ); |
|
901 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent($throttlingUntil, $request); |
|
902 | + $this->throttlingLock->lock(self::EXPIRY_LOCK_ID, $throttlingUntil); |
|
906 | 903 | } |
907 | 904 | throw new TooManySparqlRequestsException(); |
908 | 905 | } |