@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @codeCoverageIgnore This method is purely declarative. |
80 | 80 | */ |
81 | 81 | public function getDefaultContextTypes() { |
82 | - return [ Context::TYPE_STATEMENT ]; |
|
82 | + return [Context::TYPE_STATEMENT]; |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** @codeCoverageIgnore This method is purely declarative. */ |
@@ -96,31 +96,31 @@ discard block |
||
96 | 96 | * @return CheckResult |
97 | 97 | * @throws \ConfigException |
98 | 98 | */ |
99 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
100 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
101 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
99 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
100 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
101 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
102 | 102 | } |
103 | 103 | $snak = $context->getSnak(); |
104 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
104 | + if (!$snak instanceof PropertyValueSnak) { |
|
105 | 105 | // nothing to check |
106 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
106 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | $dataValue = $snak->getDataValue(); |
110 | - if ( !$dataValue instanceof EntityIdValue ) { |
|
110 | + if (!$dataValue instanceof EntityIdValue) { |
|
111 | 111 | // wrong data type |
112 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
113 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ) |
|
114 | - ->withDataValueType( 'wikibase-entityid' ); |
|
115 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
112 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
113 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM) |
|
114 | + ->withDataValueType('wikibase-entityid'); |
|
115 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | $objectId = $dataValue->getEntityId(); |
119 | - $objectItem = $this->entityLookup->getEntity( $objectId ); |
|
120 | - if ( !( $objectItem instanceof StatementListProvider ) ) { |
|
119 | + $objectItem = $this->entityLookup->getEntity($objectId); |
|
120 | + if (!($objectItem instanceof StatementListProvider)) { |
|
121 | 121 | // object was deleted/doesn't exist |
122 | - $message = new ViolationMessage( 'wbqc-violation-message-value-entity-must-exist' ); |
|
123 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
122 | + $message = new ViolationMessage('wbqc-violation-message-value-entity-must-exist'); |
|
123 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
124 | 124 | } |
125 | 125 | /** @var Statement[] $objectStatements */ |
126 | 126 | $objectStatements = $objectItem->getStatements()->toArray(); |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | $subjectId = $context->getEntity()->getId(); |
129 | 129 | $subjectStatements = $context->getEntity()->getStatements()->toArray(); |
130 | 130 | /** @var String[] $startPropertyIds */ |
131 | - $startPropertyIds = $this->config->get( self::CONFIG_VARIABLE_START_PROPERTY_IDS ); |
|
131 | + $startPropertyIds = $this->config->get(self::CONFIG_VARIABLE_START_PROPERTY_IDS); |
|
132 | 132 | /** @var String[] $endPropertyIds */ |
133 | - $endPropertyIds = $this->config->get( self::CONFIG_VARIABLE_END_PROPERTY_IDS ); |
|
133 | + $endPropertyIds = $this->config->get(self::CONFIG_VARIABLE_END_PROPERTY_IDS); |
|
134 | 134 | $subjectStartValue = $this->getExtremeValue( |
135 | 135 | $startPropertyIds, |
136 | 136 | $subjectStatements, |
@@ -152,15 +152,15 @@ discard block |
||
152 | 152 | 'end' |
153 | 153 | ); |
154 | 154 | if ( |
155 | - $this->rangeCheckerHelper->getComparison( $subjectStartValue, $subjectEndValue ) <= 0 && |
|
156 | - $this->rangeCheckerHelper->getComparison( $objectStartValue, $objectEndValue ) <= 0 && ( |
|
157 | - $this->rangeCheckerHelper->getComparison( $subjectEndValue, $objectStartValue ) < 0 || |
|
158 | - $this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectStartValue ) < 0 |
|
155 | + $this->rangeCheckerHelper->getComparison($subjectStartValue, $subjectEndValue) <= 0 && |
|
156 | + $this->rangeCheckerHelper->getComparison($objectStartValue, $objectEndValue) <= 0 && ( |
|
157 | + $this->rangeCheckerHelper->getComparison($subjectEndValue, $objectStartValue) < 0 || |
|
158 | + $this->rangeCheckerHelper->getComparison($objectEndValue, $subjectStartValue) < 0 |
|
159 | 159 | ) |
160 | 160 | ) { |
161 | 161 | if ( |
162 | 162 | $subjectEndValue == null || |
163 | - $this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectEndValue ) < 0 |
|
163 | + $this->rangeCheckerHelper->getComparison($objectEndValue, $subjectEndValue) < 0 |
|
164 | 164 | ) { |
165 | 165 | $earlierEntityId = $objectId; |
166 | 166 | $minEndValue = $objectEndValue; |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | $message = null; |
184 | 184 | $status = CheckResult::STATUS_COMPLIANCE; |
185 | 185 | } |
186 | - return new CheckResult( $context, $constraint, [], $status, $message ); |
|
186 | + return new CheckResult($context, $constraint, [], $status, $message); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -193,19 +193,19 @@ discard block |
||
193 | 193 | * |
194 | 194 | * @return DataValue|null |
195 | 195 | */ |
196 | - private function getExtremeValue( $extremePropertyIds, $statements, $startOrEnd ) { |
|
197 | - if ( $startOrEnd !== 'start' && $startOrEnd !== 'end' ) { |
|
198 | - throw new \InvalidArgumentException( '$startOrEnd must be \'start\' or \'end\'.' ); |
|
196 | + private function getExtremeValue($extremePropertyIds, $statements, $startOrEnd) { |
|
197 | + if ($startOrEnd !== 'start' && $startOrEnd !== 'end') { |
|
198 | + throw new \InvalidArgumentException('$startOrEnd must be \'start\' or \'end\'.'); |
|
199 | 199 | } |
200 | 200 | $extremeValue = null; |
201 | - foreach ( $extremePropertyIds as $extremePropertyId ) { |
|
202 | - $statementList = new StatementList( ...$statements ); |
|
203 | - $extremeStatements = $statementList->getByPropertyId( new NumericPropertyId( $extremePropertyId ) ); |
|
201 | + foreach ($extremePropertyIds as $extremePropertyId) { |
|
202 | + $statementList = new StatementList(...$statements); |
|
203 | + $extremeStatements = $statementList->getByPropertyId(new NumericPropertyId($extremePropertyId)); |
|
204 | 204 | /** @var Statement $extremeStatement */ |
205 | - foreach ( $extremeStatements as $extremeStatement ) { |
|
206 | - if ( $extremeStatement->getRank() !== Statement::RANK_DEPRECATED ) { |
|
205 | + foreach ($extremeStatements as $extremeStatement) { |
|
206 | + if ($extremeStatement->getRank() !== Statement::RANK_DEPRECATED) { |
|
207 | 207 | $snak = $extremeStatement->getMainSnak(); |
208 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
208 | + if (!$snak instanceof PropertyValueSnak) { |
|
209 | 209 | return null; |
210 | 210 | } else { |
211 | 211 | $comparison = $this->rangeCheckerHelper->getComparison( |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | ); |
215 | 215 | if ( |
216 | 216 | $extremeValue === null || |
217 | - ( $startOrEnd === 'start' && $comparison < 0 ) || |
|
218 | - ( $startOrEnd === 'end' && $comparison > 0 ) |
|
217 | + ($startOrEnd === 'start' && $comparison < 0) || |
|
218 | + ($startOrEnd === 'end' && $comparison > 0) |
|
219 | 219 | ) { |
220 | 220 | $extremeValue = $snak->getDataValue(); |
221 | 221 | } |
@@ -245,17 +245,16 @@ discard block |
||
245 | 245 | DataValue $maxStartValue |
246 | 246 | ) { |
247 | 247 | $messageKey = $earlierEntityId === $subjectId ? |
248 | - 'wbqc-violation-message-contemporary-subject-earlier' : |
|
249 | - 'wbqc-violation-message-contemporary-value-earlier'; |
|
250 | - return ( new ViolationMessage( $messageKey ) ) |
|
251 | - ->withEntityId( $subjectId, Role::SUBJECT ) |
|
252 | - ->withEntityId( $propertyId, Role::PREDICATE ) |
|
253 | - ->withEntityId( $objectId, Role::OBJECT ) |
|
254 | - ->withDataValue( $minEndValue, Role::OBJECT ) |
|
255 | - ->withDataValue( $maxStartValue, Role::OBJECT ); |
|
248 | + 'wbqc-violation-message-contemporary-subject-earlier' : 'wbqc-violation-message-contemporary-value-earlier'; |
|
249 | + return (new ViolationMessage($messageKey)) |
|
250 | + ->withEntityId($subjectId, Role::SUBJECT) |
|
251 | + ->withEntityId($propertyId, Role::PREDICATE) |
|
252 | + ->withEntityId($objectId, Role::OBJECT) |
|
253 | + ->withDataValue($minEndValue, Role::OBJECT) |
|
254 | + ->withDataValue($maxStartValue, Role::OBJECT); |
|
256 | 255 | } |
257 | 256 | |
258 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
257 | + public function checkConstraintParameters(Constraint $constraint) { |
|
259 | 258 | // no parameters |
260 | 259 | return []; |
261 | 260 | } |
@@ -25,22 +25,22 @@ |
||
25 | 25 | */ |
26 | 26 | private const NULL_PROPERTY_ID = 'P2147483647'; |
27 | 27 | |
28 | - public function __construct( ContextCursor $contextCursor ) { |
|
28 | + public function __construct(ContextCursor $contextCursor) { |
|
29 | 29 | $constraint = new Constraint( |
30 | 30 | 'null', |
31 | - new NumericPropertyId( self::NULL_PROPERTY_ID ), |
|
31 | + new NumericPropertyId(self::NULL_PROPERTY_ID), |
|
32 | 32 | 'none', |
33 | 33 | [] |
34 | 34 | ); |
35 | - parent::__construct( $contextCursor, $constraint ); |
|
35 | + parent::__construct($contextCursor, $constraint); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | public function getConstraint() { |
39 | - throw new DomainException( 'NullResult holds no constraint' ); |
|
39 | + throw new DomainException('NullResult holds no constraint'); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | public function getConstraintId() { |
43 | - throw new DomainException( 'NullResult holds no constraint' ); |
|
43 | + throw new DomainException('NullResult holds no constraint'); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | } |
@@ -10,14 +10,13 @@ |
||
10 | 10 | */ |
11 | 11 | class ConstraintDeserializer { |
12 | 12 | |
13 | - public function deserialize( array $serialization ) { |
|
13 | + public function deserialize(array $serialization) { |
|
14 | 14 | return new Constraint( |
15 | 15 | $serialization['id'], |
16 | - new NumericPropertyId( $serialization['pid'] ), |
|
16 | + new NumericPropertyId($serialization['pid']), |
|
17 | 17 | $serialization['qid'], |
18 | - array_key_exists( 'params', $serialization ) ? |
|
19 | - $serialization['params'] : |
|
20 | - [] |
|
18 | + array_key_exists('params', $serialization) ? |
|
19 | + $serialization['params'] : [] |
|
21 | 20 | ); |
22 | 21 | } |
23 | 22 |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | * @param CachedCheckResults $checkResults |
51 | 51 | * @return CachedCheckConstraintsResponse |
52 | 52 | */ |
53 | - public function render( CachedCheckResults $checkResults ) { |
|
53 | + public function render(CachedCheckResults $checkResults) { |
|
54 | 54 | $response = []; |
55 | - foreach ( $checkResults->getArray() as $checkResult ) { |
|
56 | - $resultArray = $this->checkResultToArray( $checkResult ); |
|
57 | - $checkResult->getContextCursor()->storeCheckResultInArray( $resultArray, $response ); |
|
55 | + foreach ($checkResults->getArray() as $checkResult) { |
|
56 | + $resultArray = $this->checkResultToArray($checkResult); |
|
57 | + $checkResult->getContextCursor()->storeCheckResultInArray($resultArray, $response); |
|
58 | 58 | } |
59 | 59 | return new CachedCheckConstraintsResponse( |
60 | 60 | $response, |
@@ -62,19 +62,19 @@ discard block |
||
62 | 62 | ); |
63 | 63 | } |
64 | 64 | |
65 | - public function checkResultToArray( CheckResult $checkResult ) { |
|
66 | - if ( $checkResult instanceof NullResult ) { |
|
65 | + public function checkResultToArray(CheckResult $checkResult) { |
|
66 | + if ($checkResult instanceof NullResult) { |
|
67 | 67 | return null; |
68 | 68 | } |
69 | 69 | |
70 | 70 | $constraintId = $checkResult->getConstraint()->getConstraintId(); |
71 | 71 | $typeItemId = $checkResult->getConstraint()->getConstraintTypeItemId(); |
72 | - $constraintPropertyId = new NumericPropertyId( $checkResult->getContextCursor()->getSnakPropertyId() ); |
|
72 | + $constraintPropertyId = new NumericPropertyId($checkResult->getContextCursor()->getSnakPropertyId()); |
|
73 | 73 | |
74 | - $title = $this->entityTitleLookup->getTitleForId( $constraintPropertyId ); |
|
74 | + $title = $this->entityTitleLookup->getTitleForId($constraintPropertyId); |
|
75 | 75 | $talkTitle = $title->getTalkPageIfDefined(); |
76 | - $typeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $typeItemId ) ); |
|
77 | - $link = $title->getFullURL() . '#' . $constraintId; |
|
76 | + $typeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($typeItemId)); |
|
77 | + $link = $title->getFullURL().'#'.$constraintId; |
|
78 | 78 | |
79 | 79 | $constraint = [ |
80 | 80 | 'id' => $constraintId, |
@@ -90,14 +90,14 @@ discard block |
||
90 | 90 | 'constraint' => $constraint |
91 | 91 | ]; |
92 | 92 | $message = $checkResult->getMessage(); |
93 | - if ( $message ) { |
|
94 | - $result['message-html'] = $this->violationMessageRenderer->render( $message ); |
|
93 | + if ($message) { |
|
94 | + $result['message-html'] = $this->violationMessageRenderer->render($message); |
|
95 | 95 | } |
96 | - if ( $checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT ) { |
|
96 | + if ($checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT) { |
|
97 | 97 | $result['claim'] = $checkResult->getContextCursor()->getStatementGuid(); |
98 | 98 | } |
99 | 99 | $cachingMetadataArray = $checkResult->getMetadata()->getCachingMetadata()->toArray(); |
100 | - if ( $cachingMetadataArray !== null ) { |
|
100 | + if ($cachingMetadataArray !== null) { |
|
101 | 101 | $result['cached'] = $cachingMetadataArray; |
102 | 102 | } |
103 | 103 |
@@ -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 | [ |
@@ -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 | } |