@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | * @param CachedCheckResults $checkResults |
52 | 52 | * @return CachedCheckConstraintsResponse |
53 | 53 | */ |
54 | - public function render( CachedCheckResults $checkResults ) { |
|
54 | + public function render(CachedCheckResults $checkResults) { |
|
55 | 55 | $response = []; |
56 | - foreach ( $checkResults->getArray() as $checkResult ) { |
|
57 | - $resultArray = $this->checkResultToArray( $checkResult ); |
|
58 | - $checkResult->getContextCursor()->storeCheckResultInArray( $resultArray, $response ); |
|
56 | + foreach ($checkResults->getArray() as $checkResult) { |
|
57 | + $resultArray = $this->checkResultToArray($checkResult); |
|
58 | + $checkResult->getContextCursor()->storeCheckResultInArray($resultArray, $response); |
|
59 | 59 | } |
60 | 60 | return new CachedCheckConstraintsResponse( |
61 | 61 | $response, |
@@ -63,19 +63,19 @@ discard block |
||
63 | 63 | ); |
64 | 64 | } |
65 | 65 | |
66 | - public function checkResultToArray( CheckResult $checkResult ) { |
|
67 | - if ( $checkResult instanceof NullResult ) { |
|
66 | + public function checkResultToArray(CheckResult $checkResult) { |
|
67 | + if ($checkResult instanceof NullResult) { |
|
68 | 68 | return null; |
69 | 69 | } |
70 | 70 | |
71 | 71 | $constraintId = $checkResult->getConstraint()->getConstraintId(); |
72 | 72 | $typeItemId = $checkResult->getConstraint()->getConstraintTypeItemId(); |
73 | - $constraintPropertyId = new PropertyId( $checkResult->getContextCursor()->getSnakPropertyId() ); |
|
73 | + $constraintPropertyId = new PropertyId($checkResult->getContextCursor()->getSnakPropertyId()); |
|
74 | 74 | |
75 | - $title = $this->entityTitleLookup->getTitleForId( $constraintPropertyId ); |
|
75 | + $title = $this->entityTitleLookup->getTitleForId($constraintPropertyId); |
|
76 | 76 | $talkTitle = $title->getTalkPageIfDefined(); |
77 | - $typeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $typeItemId ) ); |
|
78 | - $link = $title->getFullURL() . '#' . $constraintId; |
|
77 | + $typeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($typeItemId)); |
|
78 | + $link = $title->getFullURL().'#'.$constraintId; |
|
79 | 79 | |
80 | 80 | $constraint = [ |
81 | 81 | 'id' => $constraintId, |
@@ -91,14 +91,14 @@ discard block |
||
91 | 91 | 'constraint' => $constraint |
92 | 92 | ]; |
93 | 93 | $message = $checkResult->getMessage(); |
94 | - if ( $message ) { |
|
95 | - $result['message-html'] = $this->violationMessageRenderer->render( $message ); |
|
94 | + if ($message) { |
|
95 | + $result['message-html'] = $this->violationMessageRenderer->render($message); |
|
96 | 96 | } |
97 | - if ( $checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT ) { |
|
97 | + if ($checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT) { |
|
98 | 98 | $result['claim'] = $checkResult->getContextCursor()->getStatementGuid(); |
99 | 99 | } |
100 | 100 | $cachingMetadataArray = $checkResult->getMetadata()->getCachingMetadata()->toArray(); |
101 | - if ( $cachingMetadataArray !== null ) { |
|
101 | + if ($cachingMetadataArray !== null) { |
|
102 | 102 | $result['cached'] = $cachingMetadataArray; |
103 | 103 | } |
104 | 104 |
@@ -28,47 +28,47 @@ discard block |
||
28 | 28 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResultSerializer; |
29 | 29 | |
30 | 30 | return [ |
31 | - ConstraintsServices::EXPIRY_LOCK => function( MediaWikiServices $services ) { |
|
32 | - return new ExpiryLock( ObjectCache::getInstance( CACHE_ANYTHING ) ); |
|
31 | + ConstraintsServices::EXPIRY_LOCK => function(MediaWikiServices $services) { |
|
32 | + return new ExpiryLock(ObjectCache::getInstance(CACHE_ANYTHING)); |
|
33 | 33 | }, |
34 | 34 | |
35 | - ConstraintsServices::LOGGING_HELPER => function( MediaWikiServices $services ) { |
|
35 | + ConstraintsServices::LOGGING_HELPER => function(MediaWikiServices $services) { |
|
36 | 36 | return new LoggingHelper( |
37 | 37 | $services->getStatsdDataFactory(), |
38 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ), |
|
38 | + LoggerFactory::getInstance('WikibaseQualityConstraints'), |
|
39 | 39 | $services->getMainConfig() |
40 | 40 | ); |
41 | 41 | }, |
42 | 42 | |
43 | - ConstraintsServices::CONSTRAINT_STORE => function( MediaWikiServices $services ) { |
|
43 | + ConstraintsServices::CONSTRAINT_STORE => function(MediaWikiServices $services) { |
|
44 | 44 | $wbRepo = WikibaseRepo::getDefaultInstance(); |
45 | 45 | $sourceDefinitions = $wbRepo->getEntitySourceDefinitions(); |
46 | - $propertySource = $sourceDefinitions->getSourceForEntityType( Property::ENTITY_TYPE ); |
|
46 | + $propertySource = $sourceDefinitions->getSourceForEntityType(Property::ENTITY_TYPE); |
|
47 | 47 | $dbName = $propertySource->getDatabaseName(); |
48 | 48 | |
49 | - if ( $propertySource->getSourceName() !== $wbRepo->getLocalEntitySource()->getSourceName() ) { |
|
50 | - throw new \RuntimeException( 'Can\'t get a ConstraintStore for a non local entity source.' ); |
|
49 | + if ($propertySource->getSourceName() !== $wbRepo->getLocalEntitySource()->getSourceName()) { |
|
50 | + throw new \RuntimeException('Can\'t get a ConstraintStore for a non local entity source.'); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | return new ConstraintRepositoryStore( |
54 | - $services->getDBLoadBalancerFactory()->getMainLB( $dbName ), |
|
54 | + $services->getDBLoadBalancerFactory()->getMainLB($dbName), |
|
55 | 55 | $dbName |
56 | 56 | ); |
57 | 57 | }, |
58 | 58 | |
59 | - ConstraintsServices::CONSTRAINT_LOOKUP => function( MediaWikiServices $services ) { |
|
59 | + ConstraintsServices::CONSTRAINT_LOOKUP => function(MediaWikiServices $services) { |
|
60 | 60 | $wbRepo = WikibaseRepo::getDefaultInstance(); |
61 | 61 | $sourceDefinitions = $wbRepo->getEntitySourceDefinitions(); |
62 | - $propertySource = $sourceDefinitions->getSourceForEntityType( Property::ENTITY_TYPE ); |
|
62 | + $propertySource = $sourceDefinitions->getSourceForEntityType(Property::ENTITY_TYPE); |
|
63 | 63 | $dbName = $propertySource->getDatabaseName(); |
64 | 64 | $rawLookup = new ConstraintRepositoryLookup( |
65 | - $services->getDBLoadBalancerFactory()->getMainLB( $dbName ), |
|
65 | + $services->getDBLoadBalancerFactory()->getMainLB($dbName), |
|
66 | 66 | $dbName |
67 | 67 | ); |
68 | - return new CachingConstraintLookup( $rawLookup ); |
|
68 | + return new CachingConstraintLookup($rawLookup); |
|
69 | 69 | }, |
70 | 70 | |
71 | - ConstraintsServices::CHECK_RESULT_SERIALIZER => function( MediaWikiServices $services ) { |
|
71 | + ConstraintsServices::CHECK_RESULT_SERIALIZER => function(MediaWikiServices $services) { |
|
72 | 72 | return new CheckResultSerializer( |
73 | 73 | new ConstraintSerializer( |
74 | 74 | false // constraint parameters are not exposed |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | ); |
80 | 80 | }, |
81 | 81 | |
82 | - ConstraintsServices::CHECK_RESULT_DESERIALIZER => function( MediaWikiServices $services ) { |
|
82 | + ConstraintsServices::CHECK_RESULT_DESERIALIZER => function(MediaWikiServices $services) { |
|
83 | 83 | // TODO in the future, get EntityIdParser and DataValueFactory from $services? |
84 | 84 | $repo = WikibaseRepo::getDefaultInstance(); |
85 | 85 | $entityIdParser = $repo->getEntityIdParser(); |
@@ -96,11 +96,11 @@ discard block |
||
96 | 96 | ); |
97 | 97 | }, |
98 | 98 | |
99 | - ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => function( MediaWikiServices $services ) { |
|
99 | + ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => function(MediaWikiServices $services) { |
|
100 | 100 | return new ViolationMessageSerializer(); |
101 | 101 | }, |
102 | 102 | |
103 | - ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => function( MediaWikiServices $services ) { |
|
103 | + ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => function(MediaWikiServices $services) { |
|
104 | 104 | // TODO in the future, get EntityIdParser and DataValueFactory from $services? |
105 | 105 | $repo = WikibaseRepo::getDefaultInstance(); |
106 | 106 | $entityIdParser = $repo->getEntityIdParser(); |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | ); |
113 | 113 | }, |
114 | 114 | |
115 | - ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => function( MediaWikiServices $services ) { |
|
115 | + ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => function(MediaWikiServices $services) { |
|
116 | 116 | // TODO in the future, get DeserializerFactory and entity source definitions from $services? |
117 | 117 | $repo = WikibaseRepo::getDefaultInstance(); |
118 | 118 | $deserializerFactory = $repo->getBaseDataModelDeserializerFactory(); |
@@ -121,15 +121,15 @@ discard block |
||
121 | 121 | return new ConstraintParameterParser( |
122 | 122 | $services->getMainConfig(), |
123 | 123 | $deserializerFactory, |
124 | - $entitySourceDefinitions->getSourceForEntityType( 'item' )->getConceptBaseUri() |
|
124 | + $entitySourceDefinitions->getSourceForEntityType('item')->getConceptBaseUri() |
|
125 | 125 | ); |
126 | 126 | }, |
127 | 127 | |
128 | - ConstraintsServices::CONNECTION_CHECKER_HELPER => function( MediaWikiServices $services ) { |
|
128 | + ConstraintsServices::CONNECTION_CHECKER_HELPER => function(MediaWikiServices $services) { |
|
129 | 129 | return new ConnectionCheckerHelper(); |
130 | 130 | }, |
131 | 131 | |
132 | - ConstraintsServices::RANGE_CHECKER_HELPER => function( MediaWikiServices $services ) { |
|
132 | + ConstraintsServices::RANGE_CHECKER_HELPER => function(MediaWikiServices $services) { |
|
133 | 133 | // TODO in the future, get UnitConverter from $services? |
134 | 134 | $repo = WikibaseRepo::getDefaultInstance(); |
135 | 135 | $unitConverter = $repo->getUnitConverter(); |
@@ -140,9 +140,9 @@ discard block |
||
140 | 140 | ); |
141 | 141 | }, |
142 | 142 | |
143 | - ConstraintsServices::SPARQL_HELPER => function( MediaWikiServices $services ) { |
|
144 | - $endpoint = $services->getMainConfig()->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
145 | - if ( $endpoint === '' ) { |
|
143 | + ConstraintsServices::SPARQL_HELPER => function(MediaWikiServices $services) { |
|
144 | + $endpoint = $services->getMainConfig()->get('WBQualityConstraintsSparqlEndpoint'); |
|
145 | + if ($endpoint === '') { |
|
146 | 146 | return new DummySparqlHelper(); |
147 | 147 | } |
148 | 148 | |
@@ -158,122 +158,122 @@ discard block |
||
158 | 158 | $entityIdParser, |
159 | 159 | $propertyDataTypeLookup, |
160 | 160 | $services->getMainWANObjectCache(), |
161 | - ConstraintsServices::getViolationMessageSerializer( $services ), |
|
162 | - ConstraintsServices::getViolationMessageDeserializer( $services ), |
|
161 | + ConstraintsServices::getViolationMessageSerializer($services), |
|
162 | + ConstraintsServices::getViolationMessageDeserializer($services), |
|
163 | 163 | $services->getStatsdDataFactory(), |
164 | - ConstraintsServices::getExpiryLock( $services ), |
|
164 | + ConstraintsServices::getExpiryLock($services), |
|
165 | 165 | ConstraintsServices::getLoggingHelper(), |
166 | - wfWikiID() . ' WikibaseQualityConstraints ' . Http::userAgent(), |
|
166 | + wfWikiID().' WikibaseQualityConstraints '.Http::userAgent(), |
|
167 | 167 | $services->getHttpRequestFactory() |
168 | 168 | ); |
169 | 169 | }, |
170 | 170 | |
171 | - ConstraintsServices::TYPE_CHECKER_HELPER => function( MediaWikiServices $services ) { |
|
171 | + ConstraintsServices::TYPE_CHECKER_HELPER => function(MediaWikiServices $services) { |
|
172 | 172 | return new TypeCheckerHelper( |
173 | - WikibaseServices::getEntityLookup( $services ), |
|
173 | + WikibaseServices::getEntityLookup($services), |
|
174 | 174 | $services->getMainConfig(), |
175 | - ConstraintsServices::getSparqlHelper( $services ), |
|
175 | + ConstraintsServices::getSparqlHelper($services), |
|
176 | 176 | $services->getStatsdDataFactory() |
177 | 177 | ); |
178 | 178 | }, |
179 | 179 | |
180 | - ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => function( MediaWikiServices $services ) { |
|
180 | + ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => function(MediaWikiServices $services) { |
|
181 | 181 | // TODO in the future, get StatementGuidParser from $services? |
182 | 182 | $repo = WikibaseRepo::getDefaultInstance(); |
183 | 183 | $statementGuidParser = $repo->getStatementGuidParser(); |
184 | 184 | |
185 | 185 | $config = $services->getMainConfig(); |
186 | 186 | $checkerMap = [ |
187 | - $config->get( 'WBQualityConstraintsConflictsWithConstraintId' ) |
|
188 | - => ConstraintCheckerServices::getConflictsWithChecker( $services ), |
|
189 | - $config->get( 'WBQualityConstraintsItemRequiresClaimConstraintId' ) |
|
190 | - => ConstraintCheckerServices::getItemChecker( $services ), |
|
191 | - $config->get( 'WBQualityConstraintsValueRequiresClaimConstraintId' ) |
|
192 | - => ConstraintCheckerServices::getTargetRequiredClaimChecker( $services ), |
|
193 | - $config->get( 'WBQualityConstraintsSymmetricConstraintId' ) |
|
194 | - => ConstraintCheckerServices::getSymmetricChecker( $services ), |
|
195 | - $config->get( 'WBQualityConstraintsInverseConstraintId' ) |
|
196 | - => ConstraintCheckerServices::getInverseChecker( $services ), |
|
197 | - $config->get( 'WBQualityConstraintsUsedAsQualifierConstraintId' ) |
|
198 | - => ConstraintCheckerServices::getQualifierChecker( $services ), |
|
199 | - $config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' ) |
|
200 | - => ConstraintCheckerServices::getQualifiersChecker( $services ), |
|
201 | - $config->get( 'WBQualityConstraintsMandatoryQualifierConstraintId' ) |
|
202 | - => ConstraintCheckerServices::getMandatoryQualifiersChecker( $services ), |
|
203 | - $config->get( 'WBQualityConstraintsRangeConstraintId' ) |
|
204 | - => ConstraintCheckerServices::getRangeChecker( $services ), |
|
205 | - $config->get( 'WBQualityConstraintsDifferenceWithinRangeConstraintId' ) |
|
206 | - => ConstraintCheckerServices::getDiffWithinRangeChecker( $services ), |
|
207 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ) |
|
208 | - => ConstraintCheckerServices::getTypeChecker( $services ), |
|
209 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ) |
|
210 | - => ConstraintCheckerServices::getValueTypeChecker( $services ), |
|
211 | - $config->get( 'WBQualityConstraintsSingleValueConstraintId' ) |
|
212 | - => ConstraintCheckerServices::getSingleValueChecker( $services ), |
|
213 | - $config->get( 'WBQualityConstraintsMultiValueConstraintId' ) |
|
214 | - => ConstraintCheckerServices::getMultiValueChecker( $services ), |
|
215 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ) |
|
216 | - => ConstraintCheckerServices::getUniqueValueChecker( $services ), |
|
217 | - $config->get( 'WBQualityConstraintsFormatConstraintId' ) |
|
218 | - => ConstraintCheckerServices::getFormatChecker( $services ), |
|
219 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ) |
|
220 | - => ConstraintCheckerServices::getCommonsLinkChecker( $services ), |
|
221 | - $config->get( 'WBQualityConstraintsOneOfConstraintId' ) |
|
222 | - => ConstraintCheckerServices::getOneOfChecker( $services ), |
|
223 | - $config->get( 'WBQualityConstraintsUsedForValuesOnlyConstraintId' ) |
|
224 | - => ConstraintCheckerServices::getValueOnlyChecker( $services ), |
|
225 | - $config->get( 'WBQualityConstraintsUsedAsReferenceConstraintId' ) |
|
226 | - => ConstraintCheckerServices::getReferenceChecker( $services ), |
|
227 | - $config->get( 'WBQualityConstraintsNoBoundsConstraintId' ) |
|
228 | - => ConstraintCheckerServices::getNoBoundsChecker( $services ), |
|
229 | - $config->get( 'WBQualityConstraintsAllowedUnitsConstraintId' ) |
|
230 | - => ConstraintCheckerServices::getAllowedUnitsChecker( $services ), |
|
231 | - $config->get( 'WBQualityConstraintsSingleBestValueConstraintId' ) |
|
232 | - => ConstraintCheckerServices::getSingleBestValueChecker( $services ), |
|
233 | - $config->get( 'WBQualityConstraintsAllowedEntityTypesConstraintId' ) |
|
234 | - => ConstraintCheckerServices::getEntityTypeChecker( $services ), |
|
235 | - $config->get( 'WBQualityConstraintsNoneOfConstraintId' ) |
|
236 | - => ConstraintCheckerServices::getNoneOfChecker( $services ), |
|
237 | - $config->get( 'WBQualityConstraintsIntegerConstraintId' ) |
|
238 | - => ConstraintCheckerServices::getIntegerChecker( $services ), |
|
239 | - $config->get( 'WBQualityConstraintsCitationNeededConstraintId' ) |
|
240 | - => ConstraintCheckerServices::getCitationNeededChecker( $services ), |
|
241 | - $config->get( 'WBQualityConstraintsPropertyScopeConstraintId' ) |
|
242 | - => ConstraintCheckerServices::getPropertyScopeChecker( $services ), |
|
243 | - $config->get( 'WBQualityConstraintsContemporaryConstraintId' ) |
|
244 | - => ConstraintCheckerServices::getContemporaryChecker( $services ), |
|
187 | + $config->get('WBQualityConstraintsConflictsWithConstraintId') |
|
188 | + => ConstraintCheckerServices::getConflictsWithChecker($services), |
|
189 | + $config->get('WBQualityConstraintsItemRequiresClaimConstraintId') |
|
190 | + => ConstraintCheckerServices::getItemChecker($services), |
|
191 | + $config->get('WBQualityConstraintsValueRequiresClaimConstraintId') |
|
192 | + => ConstraintCheckerServices::getTargetRequiredClaimChecker($services), |
|
193 | + $config->get('WBQualityConstraintsSymmetricConstraintId') |
|
194 | + => ConstraintCheckerServices::getSymmetricChecker($services), |
|
195 | + $config->get('WBQualityConstraintsInverseConstraintId') |
|
196 | + => ConstraintCheckerServices::getInverseChecker($services), |
|
197 | + $config->get('WBQualityConstraintsUsedAsQualifierConstraintId') |
|
198 | + => ConstraintCheckerServices::getQualifierChecker($services), |
|
199 | + $config->get('WBQualityConstraintsAllowedQualifiersConstraintId') |
|
200 | + => ConstraintCheckerServices::getQualifiersChecker($services), |
|
201 | + $config->get('WBQualityConstraintsMandatoryQualifierConstraintId') |
|
202 | + => ConstraintCheckerServices::getMandatoryQualifiersChecker($services), |
|
203 | + $config->get('WBQualityConstraintsRangeConstraintId') |
|
204 | + => ConstraintCheckerServices::getRangeChecker($services), |
|
205 | + $config->get('WBQualityConstraintsDifferenceWithinRangeConstraintId') |
|
206 | + => ConstraintCheckerServices::getDiffWithinRangeChecker($services), |
|
207 | + $config->get('WBQualityConstraintsTypeConstraintId') |
|
208 | + => ConstraintCheckerServices::getTypeChecker($services), |
|
209 | + $config->get('WBQualityConstraintsValueTypeConstraintId') |
|
210 | + => ConstraintCheckerServices::getValueTypeChecker($services), |
|
211 | + $config->get('WBQualityConstraintsSingleValueConstraintId') |
|
212 | + => ConstraintCheckerServices::getSingleValueChecker($services), |
|
213 | + $config->get('WBQualityConstraintsMultiValueConstraintId') |
|
214 | + => ConstraintCheckerServices::getMultiValueChecker($services), |
|
215 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId') |
|
216 | + => ConstraintCheckerServices::getUniqueValueChecker($services), |
|
217 | + $config->get('WBQualityConstraintsFormatConstraintId') |
|
218 | + => ConstraintCheckerServices::getFormatChecker($services), |
|
219 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId') |
|
220 | + => ConstraintCheckerServices::getCommonsLinkChecker($services), |
|
221 | + $config->get('WBQualityConstraintsOneOfConstraintId') |
|
222 | + => ConstraintCheckerServices::getOneOfChecker($services), |
|
223 | + $config->get('WBQualityConstraintsUsedForValuesOnlyConstraintId') |
|
224 | + => ConstraintCheckerServices::getValueOnlyChecker($services), |
|
225 | + $config->get('WBQualityConstraintsUsedAsReferenceConstraintId') |
|
226 | + => ConstraintCheckerServices::getReferenceChecker($services), |
|
227 | + $config->get('WBQualityConstraintsNoBoundsConstraintId') |
|
228 | + => ConstraintCheckerServices::getNoBoundsChecker($services), |
|
229 | + $config->get('WBQualityConstraintsAllowedUnitsConstraintId') |
|
230 | + => ConstraintCheckerServices::getAllowedUnitsChecker($services), |
|
231 | + $config->get('WBQualityConstraintsSingleBestValueConstraintId') |
|
232 | + => ConstraintCheckerServices::getSingleBestValueChecker($services), |
|
233 | + $config->get('WBQualityConstraintsAllowedEntityTypesConstraintId') |
|
234 | + => ConstraintCheckerServices::getEntityTypeChecker($services), |
|
235 | + $config->get('WBQualityConstraintsNoneOfConstraintId') |
|
236 | + => ConstraintCheckerServices::getNoneOfChecker($services), |
|
237 | + $config->get('WBQualityConstraintsIntegerConstraintId') |
|
238 | + => ConstraintCheckerServices::getIntegerChecker($services), |
|
239 | + $config->get('WBQualityConstraintsCitationNeededConstraintId') |
|
240 | + => ConstraintCheckerServices::getCitationNeededChecker($services), |
|
241 | + $config->get('WBQualityConstraintsPropertyScopeConstraintId') |
|
242 | + => ConstraintCheckerServices::getPropertyScopeChecker($services), |
|
243 | + $config->get('WBQualityConstraintsContemporaryConstraintId') |
|
244 | + => ConstraintCheckerServices::getContemporaryChecker($services), |
|
245 | 245 | ]; |
246 | 246 | |
247 | 247 | return new DelegatingConstraintChecker( |
248 | - WikibaseServices::getEntityLookup( $services ), |
|
248 | + WikibaseServices::getEntityLookup($services), |
|
249 | 249 | $checkerMap, |
250 | - ConstraintsServices::getConstraintLookup( $services ), |
|
251 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
250 | + ConstraintsServices::getConstraintLookup($services), |
|
251 | + ConstraintsServices::getConstraintParameterParser($services), |
|
252 | 252 | $statementGuidParser, |
253 | - ConstraintsServices::getLoggingHelper( $services ), |
|
254 | - $config->get( 'WBQualityConstraintsCheckQualifiers' ), |
|
255 | - $config->get( 'WBQualityConstraintsCheckReferences' ), |
|
256 | - $config->get( 'WBQualityConstraintsPropertiesWithViolatingQualifiers' ) |
|
253 | + ConstraintsServices::getLoggingHelper($services), |
|
254 | + $config->get('WBQualityConstraintsCheckQualifiers'), |
|
255 | + $config->get('WBQualityConstraintsCheckReferences'), |
|
256 | + $config->get('WBQualityConstraintsPropertiesWithViolatingQualifiers') |
|
257 | 257 | ); |
258 | 258 | }, |
259 | 259 | |
260 | - ConstraintsServices::RESULTS_SOURCE => function( MediaWikiServices $services ) { |
|
260 | + ConstraintsServices::RESULTS_SOURCE => function(MediaWikiServices $services) { |
|
261 | 261 | $config = $services->getMainConfig(); |
262 | 262 | $resultsSource = new CheckingResultsSource( |
263 | - ConstraintsServices::getDelegatingConstraintChecker( $services ) |
|
263 | + ConstraintsServices::getDelegatingConstraintChecker($services) |
|
264 | 264 | ); |
265 | 265 | |
266 | 266 | $cacheCheckConstraintsResults = false; |
267 | 267 | |
268 | - if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) { |
|
268 | + if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) { |
|
269 | 269 | $cacheCheckConstraintsResults = true; |
270 | 270 | // check that we can use getLocalRepoWikiPageMetaDataAccessor() |
271 | 271 | // TODO we should always be able to cache constraint check results (T244726) |
272 | 272 | $repo = WikibaseRepo::getDefaultInstance(); |
273 | - foreach ( $repo->getEntitySourceDefinitions()->getSources() as $entitySource ) { |
|
274 | - if ( $entitySource->getSourceName() !== $repo->getLocalEntitySource()->getSourceName() ) { |
|
275 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' )->warning( |
|
276 | - 'Cannot cache constraint check results for non-local source: ' . |
|
273 | + foreach ($repo->getEntitySourceDefinitions()->getSources() as $entitySource) { |
|
274 | + if ($entitySource->getSourceName() !== $repo->getLocalEntitySource()->getSourceName()) { |
|
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,12 +282,12 @@ 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 | 292 | // TODO in the future, get EntityIdParser and WikiPageEntityMetaDataAccessor from $services? |
293 | 293 | $repo = WikibaseRepo::getDefaultInstance(); |
@@ -297,14 +297,14 @@ discard block |
||
297 | 297 | $resultsSource = new CachingResultsSource( |
298 | 298 | $resultsSource, |
299 | 299 | ResultsCache::getDefaultInstance(), |
300 | - ConstraintsServices::getCheckResultSerializer( $services ), |
|
301 | - ConstraintsServices::getCheckResultDeserializer( $services ), |
|
300 | + ConstraintsServices::getCheckResultSerializer($services), |
|
301 | + ConstraintsServices::getCheckResultDeserializer($services), |
|
302 | 302 | $wikiPageEntityMetaDataAccessor, |
303 | 303 | $entityIdParser, |
304 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ), |
|
304 | + $config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'), |
|
305 | 305 | $possiblyStaleConstraintTypes, |
306 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds' ), |
|
307 | - ConstraintsServices::getLoggingHelper( $services ) |
|
306 | + $config->get('WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds'), |
|
307 | + ConstraintsServices::getLoggingHelper($services) |
|
308 | 308 | ); |
309 | 309 | } |
310 | 310 |
@@ -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( PropertyId $propertyId ); |
|
28 | + public function deleteForProperty(PropertyId $propertyId); |
|
29 | 29 | |
30 | 30 | } |
@@ -143,14 +143,14 @@ discard block |
||
143 | 143 | ) { |
144 | 144 | $results = []; |
145 | 145 | $metadatas = []; |
146 | - if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
146 | + if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
147 | 147 | $storedEntityIds = []; |
148 | - foreach ( $entityIds as $entityId ) { |
|
149 | - $storedResults = $this->getStoredResults( $entityId ); |
|
150 | - if ( $storedResults !== null ) { |
|
151 | - $this->loggingHelper->logCheckConstraintsCacheHit( $entityId ); |
|
152 | - foreach ( $storedResults->getArray() as $checkResult ) { |
|
153 | - if ( $this->statusSelected( $statuses, $checkResult ) ) { |
|
148 | + foreach ($entityIds as $entityId) { |
|
149 | + $storedResults = $this->getStoredResults($entityId); |
|
150 | + if ($storedResults !== null) { |
|
151 | + $this->loggingHelper->logCheckConstraintsCacheHit($entityId); |
|
152 | + foreach ($storedResults->getArray() as $checkResult) { |
|
153 | + if ($this->statusSelected($statuses, $checkResult)) { |
|
154 | 154 | $results[] = $checkResult; |
155 | 155 | } |
156 | 156 | } |
@@ -158,19 +158,19 @@ discard block |
||
158 | 158 | $storedEntityIds[] = $entityId; |
159 | 159 | } |
160 | 160 | } |
161 | - $entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) ); |
|
161 | + $entityIds = array_values(array_diff($entityIds, $storedEntityIds)); |
|
162 | 162 | } |
163 | - if ( $entityIds !== [] || $claimIds !== [] ) { |
|
164 | - if ( $entityIds !== [] ) { |
|
165 | - $this->loggingHelper->logCheckConstraintsCacheMisses( $entityIds ); |
|
163 | + if ($entityIds !== [] || $claimIds !== []) { |
|
164 | + if ($entityIds !== []) { |
|
165 | + $this->loggingHelper->logCheckConstraintsCacheMisses($entityIds); |
|
166 | 166 | } |
167 | - $response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
168 | - $results = array_merge( $results, $response->getArray() ); |
|
167 | + $response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
168 | + $results = array_merge($results, $response->getArray()); |
|
169 | 169 | $metadatas[] = $response->getMetadata(); |
170 | 170 | } |
171 | 171 | return new CachedCheckResults( |
172 | 172 | $results, |
173 | - Metadata::merge( $metadatas ) |
|
173 | + Metadata::merge($metadatas) |
|
174 | 174 | ); |
175 | 175 | } |
176 | 176 | |
@@ -193,13 +193,13 @@ discard block |
||
193 | 193 | ?array $constraintIds, |
194 | 194 | array $statuses |
195 | 195 | ) { |
196 | - if ( $claimIds !== [] ) { |
|
196 | + if ($claimIds !== []) { |
|
197 | 197 | return false; |
198 | 198 | } |
199 | - if ( $constraintIds !== null ) { |
|
199 | + if ($constraintIds !== null) { |
|
200 | 200 | return false; |
201 | 201 | } |
202 | - if ( array_diff( $statuses, self::CACHED_STATUSES ) !== [] ) { |
|
202 | + if (array_diff($statuses, self::CACHED_STATUSES) !== []) { |
|
203 | 203 | return false; |
204 | 204 | } |
205 | 205 | return true; |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | * @param CheckResult $result |
215 | 215 | * @return bool |
216 | 216 | */ |
217 | - private function statusSelected( array $statuses, CheckResult $result ) { |
|
218 | - return in_array( $result->getStatus(), $statuses, true ) || |
|
217 | + private function statusSelected(array $statuses, CheckResult $result) { |
|
218 | + return in_array($result->getStatus(), $statuses, true) || |
|
219 | 219 | $result instanceof NullResult; |
220 | 220 | } |
221 | 221 | |
@@ -232,11 +232,11 @@ discard block |
||
232 | 232 | ?array $constraintIds, |
233 | 233 | array $statuses |
234 | 234 | ) { |
235 | - $results = $this->resultsSource->getResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
235 | + $results = $this->resultsSource->getResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
236 | 236 | |
237 | - if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
238 | - foreach ( $entityIds as $entityId ) { |
|
239 | - $this->storeResults( $entityId, $results ); |
|
237 | + if ($this->canStoreResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
238 | + foreach ($entityIds as $entityId) { |
|
239 | + $this->storeResults($entityId, $results); |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | |
@@ -267,10 +267,10 @@ discard block |
||
267 | 267 | ?array $constraintIds, |
268 | 268 | array $statuses |
269 | 269 | ) { |
270 | - if ( $constraintIds !== null ) { |
|
270 | + if ($constraintIds !== null) { |
|
271 | 271 | return false; |
272 | 272 | } |
273 | - if ( array_diff( self::CACHED_STATUSES, $statuses ) !== [] ) { |
|
273 | + if (array_diff(self::CACHED_STATUSES, $statuses) !== []) { |
|
274 | 274 | return false; |
275 | 275 | } |
276 | 276 | return true; |
@@ -284,21 +284,21 @@ discard block |
||
284 | 284 | * May include check results for other entity IDs as well, |
285 | 285 | * or check results with statuses that we’re not interested in caching. |
286 | 286 | */ |
287 | - private function storeResults( EntityId $entityId, CachedCheckResults $results ) { |
|
287 | + private function storeResults(EntityId $entityId, CachedCheckResults $results) { |
|
288 | 288 | $latestRevisionIds = $this->getLatestRevisionIds( |
289 | 289 | $results->getMetadata()->getDependencyMetadata()->getEntityIds() |
290 | 290 | ); |
291 | - if ( $latestRevisionIds === null ) { |
|
291 | + if ($latestRevisionIds === null) { |
|
292 | 292 | return; |
293 | 293 | } |
294 | 294 | |
295 | 295 | $resultSerializations = []; |
296 | - foreach ( $results->getArray() as $checkResult ) { |
|
297 | - if ( $checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization() ) { |
|
296 | + foreach ($results->getArray() as $checkResult) { |
|
297 | + if ($checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization()) { |
|
298 | 298 | continue; |
299 | 299 | } |
300 | - if ( $this->statusSelected( self::CACHED_STATUSES, $checkResult ) ) { |
|
301 | - $resultSerializations[] = $this->checkResultSerializer->serialize( $checkResult ); |
|
300 | + if ($this->statusSelected(self::CACHED_STATUSES, $checkResult)) { |
|
301 | + $resultSerializations[] = $this->checkResultSerializer->serialize($checkResult); |
|
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
@@ -307,11 +307,11 @@ discard block |
||
307 | 307 | 'latestRevisionIds' => $latestRevisionIds, |
308 | 308 | ]; |
309 | 309 | $futureTime = $results->getMetadata()->getDependencyMetadata()->getFutureTime(); |
310 | - if ( $futureTime !== null ) { |
|
310 | + if ($futureTime !== null) { |
|
311 | 311 | $value['futureTime'] = $futureTime->getArrayValue(); |
312 | 312 | } |
313 | 313 | |
314 | - $this->cache->set( $entityId, $value, $this->ttlInSeconds ); |
|
314 | + $this->cache->set($entityId, $value, $this->ttlInSeconds); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -325,31 +325,30 @@ discard block |
||
325 | 325 | EntityId $entityId, |
326 | 326 | $forRevision = 0 |
327 | 327 | ) { |
328 | - $value = $this->cache->get( $entityId, $curTTL, [], $asOf ); |
|
329 | - $now = call_user_func( $this->microtime, true ); |
|
328 | + $value = $this->cache->get($entityId, $curTTL, [], $asOf); |
|
329 | + $now = call_user_func($this->microtime, true); |
|
330 | 330 | |
331 | - $dependencyMetadata = $this->checkDependencyMetadata( $value, |
|
332 | - [ $entityId->getSerialization() => $forRevision ] ); |
|
333 | - if ( $dependencyMetadata === null ) { |
|
331 | + $dependencyMetadata = $this->checkDependencyMetadata($value, |
|
332 | + [$entityId->getSerialization() => $forRevision]); |
|
333 | + if ($dependencyMetadata === null) { |
|
334 | 334 | return null; |
335 | 335 | } |
336 | 336 | |
337 | - $ageInSeconds = (int)ceil( $now - $asOf ); |
|
337 | + $ageInSeconds = (int) ceil($now - $asOf); |
|
338 | 338 | $cachingMetadata = $ageInSeconds > 0 ? |
339 | - CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) : |
|
340 | - CachingMetadata::fresh(); |
|
339 | + CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh(); |
|
341 | 340 | |
342 | 341 | $results = []; |
343 | - foreach ( $value['results'] as $resultSerialization ) { |
|
344 | - $results[] = $this->deserializeCheckResult( $resultSerialization, $cachingMetadata ); |
|
342 | + foreach ($value['results'] as $resultSerialization) { |
|
343 | + $results[] = $this->deserializeCheckResult($resultSerialization, $cachingMetadata); |
|
345 | 344 | } |
346 | 345 | |
347 | 346 | return new CachedCheckResults( |
348 | 347 | $results, |
349 | - Metadata::merge( [ |
|
350 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
351 | - Metadata::ofDependencyMetadata( $dependencyMetadata ), |
|
352 | - ] ) |
|
348 | + Metadata::merge([ |
|
349 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
350 | + Metadata::ofDependencyMetadata($dependencyMetadata), |
|
351 | + ]) |
|
353 | 352 | ); |
354 | 353 | } |
355 | 354 | |
@@ -365,43 +364,43 @@ discard block |
||
365 | 364 | * @return DependencyMetadata|null the dependency metadata, |
366 | 365 | * or null if $value should no longer be used |
367 | 366 | */ |
368 | - private function checkDependencyMetadata( $value, $paramRevs ) { |
|
369 | - if ( $value === false ) { |
|
367 | + private function checkDependencyMetadata($value, $paramRevs) { |
|
368 | + if ($value === false) { |
|
370 | 369 | return null; |
371 | 370 | } |
372 | 371 | |
373 | - if ( array_key_exists( 'futureTime', $value ) ) { |
|
374 | - $futureTime = TimeValue::newFromArray( $value['futureTime'] ); |
|
375 | - if ( !$this->timeValueComparer->isFutureTime( $futureTime ) ) { |
|
372 | + if (array_key_exists('futureTime', $value)) { |
|
373 | + $futureTime = TimeValue::newFromArray($value['futureTime']); |
|
374 | + if (!$this->timeValueComparer->isFutureTime($futureTime)) { |
|
376 | 375 | return null; |
377 | 376 | } |
378 | - $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime( $futureTime ); |
|
377 | + $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime($futureTime); |
|
379 | 378 | } else { |
380 | 379 | $futureTimeDependencyMetadata = DependencyMetadata::blank(); |
381 | 380 | } |
382 | 381 | |
383 | - foreach ( $paramRevs as $id => $revision ) { |
|
384 | - if ( $revision > 0 ) { |
|
385 | - $value['latestRevisionIds'][$id] = min( $revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX ); |
|
382 | + foreach ($paramRevs as $id => $revision) { |
|
383 | + if ($revision > 0) { |
|
384 | + $value['latestRevisionIds'][$id] = min($revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX); |
|
386 | 385 | } |
387 | 386 | } |
388 | 387 | |
389 | 388 | $dependedEntityIds = array_map( |
390 | - [ $this->entityIdParser, "parse" ], |
|
391 | - array_keys( $value['latestRevisionIds'] ) |
|
389 | + [$this->entityIdParser, "parse"], |
|
390 | + array_keys($value['latestRevisionIds']) |
|
392 | 391 | ); |
393 | 392 | |
394 | - if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) { |
|
393 | + if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) { |
|
395 | 394 | return null; |
396 | 395 | } |
397 | 396 | |
398 | 397 | return array_reduce( |
399 | 398 | $dependedEntityIds, |
400 | - function( DependencyMetadata $metadata, EntityId $entityId ) { |
|
401 | - return DependencyMetadata::merge( [ |
|
399 | + function(DependencyMetadata $metadata, EntityId $entityId) { |
|
400 | + return DependencyMetadata::merge([ |
|
402 | 401 | $metadata, |
403 | - DependencyMetadata::ofEntityId( $entityId ) |
|
404 | - ] ); |
|
402 | + DependencyMetadata::ofEntityId($entityId) |
|
403 | + ]); |
|
405 | 404 | }, |
406 | 405 | $futureTimeDependencyMetadata |
407 | 406 | ); |
@@ -421,13 +420,13 @@ discard block |
||
421 | 420 | array $resultSerialization, |
422 | 421 | CachingMetadata $cachingMetadata |
423 | 422 | ) { |
424 | - $result = $this->checkResultDeserializer->deserialize( $resultSerialization ); |
|
425 | - if ( $this->isPossiblyStaleResult( $result ) ) { |
|
423 | + $result = $this->checkResultDeserializer->deserialize($resultSerialization); |
|
424 | + if ($this->isPossiblyStaleResult($result)) { |
|
426 | 425 | $result->withMetadata( |
427 | - Metadata::merge( [ |
|
426 | + Metadata::merge([ |
|
428 | 427 | $result->getMetadata(), |
429 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
430 | - ] ) |
|
428 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
429 | + ]) |
|
431 | 430 | ); |
432 | 431 | } |
433 | 432 | return $result; |
@@ -437,8 +436,8 @@ discard block |
||
437 | 436 | * @param CheckResult $result |
438 | 437 | * @return bool |
439 | 438 | */ |
440 | - private function isPossiblyStaleResult( CheckResult $result ) { |
|
441 | - if ( $result instanceof NullResult ) { |
|
439 | + private function isPossiblyStaleResult(CheckResult $result) { |
|
440 | + if ($result instanceof NullResult) { |
|
442 | 441 | return false; |
443 | 442 | } |
444 | 443 | |
@@ -453,14 +452,14 @@ discard block |
||
453 | 452 | * @return int[]|null array from entity ID serializations to revision ID, |
454 | 453 | * or null to indicate that not all revision IDs could be loaded |
455 | 454 | */ |
456 | - private function getLatestRevisionIds( array $entityIds ) { |
|
457 | - if ( $entityIds === [] ) { |
|
455 | + private function getLatestRevisionIds(array $entityIds) { |
|
456 | + if ($entityIds === []) { |
|
458 | 457 | $this->loggingHelper->logEmptyDependencyMetadata(); |
459 | 458 | return []; |
460 | 459 | } |
461 | - if ( count( $entityIds ) > $this->maxRevisionIds ) { |
|
460 | + if (count($entityIds) > $this->maxRevisionIds) { |
|
462 | 461 | // one of those entities will probably be edited soon, so might as well skip caching |
463 | - $this->loggingHelper->logHugeDependencyMetadata( $entityIds, $this->maxRevisionIds ); |
|
462 | + $this->loggingHelper->logHugeDependencyMetadata($entityIds, $this->maxRevisionIds); |
|
464 | 463 | return null; |
465 | 464 | } |
466 | 465 | |
@@ -468,7 +467,7 @@ discard block |
||
468 | 467 | $entityIds, |
469 | 468 | LookupConstants::LATEST_FROM_REPLICA |
470 | 469 | ); |
471 | - if ( $this->hasFalseElements( $latestRevisionIds ) ) { |
|
470 | + if ($this->hasFalseElements($latestRevisionIds)) { |
|
472 | 471 | return null; |
473 | 472 | } |
474 | 473 | return $latestRevisionIds; |
@@ -478,8 +477,8 @@ discard block |
||
478 | 477 | * @param array $array |
479 | 478 | * @return bool |
480 | 479 | */ |
481 | - private function hasFalseElements( array $array ) { |
|
482 | - return in_array( false, $array, true ); |
|
480 | + private function hasFalseElements(array $array) { |
|
481 | + return in_array(false, $array, true); |
|
483 | 482 | } |
484 | 483 | |
485 | 484 | /** |
@@ -487,7 +486,7 @@ discard block |
||
487 | 486 | * |
488 | 487 | * @param callable $microtime |
489 | 488 | */ |
490 | - public function setMicrotimeFunction( callable $microtime ) { |
|
489 | + public function setMicrotimeFunction(callable $microtime) { |
|
491 | 490 | $this->microtime = $microtime; |
492 | 491 | } |
493 | 492 |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | |
33 | 33 | const BATCH_SIZE = 10; |
34 | 34 | |
35 | - public static function newFromGlobalState( Title $title, array $params ) { |
|
36 | - Assert::parameterType( 'string', $params['propertyId'], '$params["propertyId"]' ); |
|
35 | + public static function newFromGlobalState(Title $title, array $params) { |
|
36 | + Assert::parameterType('string', $params['propertyId'], '$params["propertyId"]'); |
|
37 | 37 | $repo = WikibaseRepo::getDefaultInstance(); |
38 | 38 | return new UpdateConstraintsTableJob( |
39 | 39 | $title, |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $params['revisionId'] ?? null, |
43 | 43 | MediaWikiServices::getInstance()->getMainConfig(), |
44 | 44 | ConstraintsServices::getConstraintStore(), |
45 | - $repo->getEntityRevisionLookup( Store::LOOKUP_CACHING_DISABLED ), |
|
45 | + $repo->getEntityRevisionLookup(Store::LOOKUP_CACHING_DISABLED), |
|
46 | 46 | $repo->getBaseDataModelSerializerFactory()->newSnakSerializer() |
47 | 47 | ); |
48 | 48 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | EntityRevisionLookup $entityRevisionLookup, |
98 | 98 | Serializer $snakSerializer |
99 | 99 | ) { |
100 | - parent::__construct( 'constraintsTableUpdate', $title, $params ); |
|
100 | + parent::__construct('constraintsTableUpdate', $title, $params); |
|
101 | 101 | |
102 | 102 | $this->propertyId = $propertyId; |
103 | 103 | $this->revisionId = $revisionId; |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | $this->snakSerializer = $snakSerializer; |
108 | 108 | } |
109 | 109 | |
110 | - public function extractParametersFromQualifiers( SnakList $qualifiers ) { |
|
110 | + public function extractParametersFromQualifiers(SnakList $qualifiers) { |
|
111 | 111 | $parameters = []; |
112 | - foreach ( $qualifiers as $qualifier ) { |
|
112 | + foreach ($qualifiers as $qualifier) { |
|
113 | 113 | $qualifierId = $qualifier->getPropertyId()->getSerialization(); |
114 | - $paramSerialization = $this->snakSerializer->serialize( $qualifier ); |
|
114 | + $paramSerialization = $this->snakSerializer->serialize($qualifier); |
|
115 | 115 | $parameters[$qualifierId][] = $paramSerialization; |
116 | 116 | } |
117 | 117 | return $parameters; |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | '@phan-var \Wikibase\DataModel\Entity\EntityIdValue $dataValue'; |
129 | 129 | $entityId = $dataValue->getEntityId(); |
130 | 130 | $constraintTypeQid = $entityId->getSerialization(); |
131 | - $parameters = $this->extractParametersFromQualifiers( $constraintStatement->getQualifiers() ); |
|
131 | + $parameters = $this->extractParametersFromQualifiers($constraintStatement->getQualifiers()); |
|
132 | 132 | return new Constraint( |
133 | 133 | $constraintId, |
134 | 134 | $propertyId, |
@@ -143,17 +143,17 @@ discard block |
||
143 | 143 | PropertyId $propertyConstraintPropertyId |
144 | 144 | ) { |
145 | 145 | $constraintsStatements = $property->getStatements() |
146 | - ->getByPropertyId( $propertyConstraintPropertyId ) |
|
147 | - ->getByRank( [ Statement::RANK_PREFERRED, Statement::RANK_NORMAL ] ); |
|
146 | + ->getByPropertyId($propertyConstraintPropertyId) |
|
147 | + ->getByRank([Statement::RANK_PREFERRED, Statement::RANK_NORMAL]); |
|
148 | 148 | $constraints = []; |
149 | - foreach ( $constraintsStatements->getIterator() as $constraintStatement ) { |
|
150 | - $constraints[] = $this->extractConstraintFromStatement( $property->getId(), $constraintStatement ); |
|
151 | - if ( count( $constraints ) >= self::BATCH_SIZE ) { |
|
152 | - $constraintStore->insertBatch( $constraints ); |
|
149 | + foreach ($constraintsStatements->getIterator() as $constraintStatement) { |
|
150 | + $constraints[] = $this->extractConstraintFromStatement($property->getId(), $constraintStatement); |
|
151 | + if (count($constraints) >= self::BATCH_SIZE) { |
|
152 | + $constraintStore->insertBatch($constraints); |
|
153 | 153 | $constraints = []; |
154 | 154 | } |
155 | 155 | } |
156 | - $constraintStore->insertBatch( $constraints ); |
|
156 | + $constraintStore->insertBatch($constraints); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -164,19 +164,19 @@ discard block |
||
164 | 164 | public function run() { |
165 | 165 | // TODO in the future: only touch constraints affected by the edit (requires T163465) |
166 | 166 | |
167 | - $propertyId = new PropertyId( $this->propertyId ); |
|
167 | + $propertyId = new PropertyId($this->propertyId); |
|
168 | 168 | $propertyRevision = $this->entityRevisionLookup->getEntityRevision( |
169 | 169 | $propertyId, |
170 | 170 | 0, // latest |
171 | 171 | LookupConstants::LATEST_FROM_REPLICA |
172 | 172 | ); |
173 | 173 | |
174 | - if ( $this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId ) { |
|
175 | - JobQueueGroup::singleton()->push( $this ); |
|
174 | + if ($this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId) { |
|
175 | + JobQueueGroup::singleton()->push($this); |
|
176 | 176 | return true; |
177 | 177 | } |
178 | 178 | |
179 | - $this->constraintStore->deleteForProperty( $propertyId ); |
|
179 | + $this->constraintStore->deleteForProperty($propertyId); |
|
180 | 180 | |
181 | 181 | /** @var Property $property */ |
182 | 182 | $property = $propertyRevision->getEntity(); |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | $this->importConstraintsForProperty( |
185 | 185 | $property, |
186 | 186 | $this->constraintStore, |
187 | - new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ) |
|
187 | + new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')) |
|
188 | 188 | ); |
189 | 189 | |
190 | 190 | return true; |
@@ -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_MASTER, [], $this->dbName ); |
|
62 | - return $dbw->insert( 'wbqc_constraints', $accumulator, __METHOD__ ); |
|
61 | + $dbw = $this->lb->getConnection(ILoadBalancer::DB_MASTER, [], $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( PropertyId $propertyId ) { |
|
73 | - $dbw = $this->lb->getConnection( ILoadBalancer::DB_MASTER, [], $this->dbName ); |
|
72 | + public function deleteForProperty(PropertyId $propertyId) { |
|
73 | + $dbw = $this->lb->getConnection(ILoadBalancer::DB_MASTER, [], $this->dbName); |
|
74 | 74 | $dbw->delete( |
75 | 75 | 'wbqc_constraints', |
76 | 76 | [ |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * then using the main DBLoadBalancer service may be incorrect. |
26 | 26 | * @param string|false $dbName Database name ($domain for ILoadBalancer methods). |
27 | 27 | */ |
28 | - public function __construct( ILoadBalancer $lb, $dbName ) { |
|
28 | + public function __construct(ILoadBalancer $lb, $dbName) { |
|
29 | 29 | $this->lb = $lb; |
30 | 30 | $this->dbName = $dbName; |
31 | 31 | } |
@@ -35,17 +35,17 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @return Constraint[] |
37 | 37 | */ |
38 | - public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
39 | - $dbr = $this->lb->getConnectionRef( ILoadBalancer::DB_REPLICA, [], $this->dbName ); |
|
38 | + public function queryConstraintsForProperty(PropertyId $propertyId) { |
|
39 | + $dbr = $this->lb->getConnectionRef(ILoadBalancer::DB_REPLICA, [], $this->dbName); |
|
40 | 40 | |
41 | 41 | $results = $dbr->select( |
42 | 42 | 'wbqc_constraints', |
43 | 43 | '*', |
44 | - [ 'pid' => $propertyId->getNumericId() ], |
|
44 | + ['pid' => $propertyId->getNumericId()], |
|
45 | 45 | __METHOD__ |
46 | 46 | ); |
47 | 47 | |
48 | - return $this->convertToConstraints( $results ); |
|
48 | + return $this->convertToConstraints($results); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -53,26 +53,26 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return Constraint[] |
55 | 55 | */ |
56 | - private function convertToConstraints( IResultWrapper $results ) { |
|
56 | + private function convertToConstraints(IResultWrapper $results) { |
|
57 | 57 | $constraints = []; |
58 | - $logger = LoggerFactory::getInstance( 'WikibaseQualityConstraints' ); |
|
59 | - foreach ( $results as $result ) { |
|
58 | + $logger = LoggerFactory::getInstance('WikibaseQualityConstraints'); |
|
59 | + foreach ($results as $result) { |
|
60 | 60 | $constraintTypeItemId = $result->constraint_type_qid; |
61 | - $constraintParameters = json_decode( $result->constraint_parameters, true ); |
|
61 | + $constraintParameters = json_decode($result->constraint_parameters, true); |
|
62 | 62 | |
63 | - if ( $constraintParameters === null ) { |
|
63 | + if ($constraintParameters === null) { |
|
64 | 64 | // T171295 |
65 | - $logger->warning( 'Constraint {constraintId} has invalid constraint parameters.', [ |
|
65 | + $logger->warning('Constraint {constraintId} has invalid constraint parameters.', [ |
|
66 | 66 | 'method' => __METHOD__, |
67 | 67 | 'constraintId' => $result->constraint_guid, |
68 | 68 | 'constraintParameters' => $result->constraint_parameters, |
69 | - ] ); |
|
70 | - $constraintParameters = [ '@error' => [ /* unknown */ ] ]; |
|
69 | + ]); |
|
70 | + $constraintParameters = ['@error' => [/* unknown */]]; |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | $constraints[] = new Constraint( |
74 | 74 | $result->constraint_guid, |
75 | - PropertyId::newFromNumber( $result->pid ), |
|
75 | + PropertyId::newFromNumber($result->pid), |
|
76 | 76 | $constraintTypeItemId, |
77 | 77 | $constraintParameters |
78 | 78 | ); |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | use Wikibase\Repo\WikibaseRepo; |
18 | 18 | |
19 | 19 | // @codeCoverageIgnoreStart |
20 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
21 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
20 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
21 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
22 | 22 | |
23 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
23 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
24 | 24 | // @codeCoverageIgnoreEnd |
25 | 25 | |
26 | 26 | /** |
@@ -59,20 +59,20 @@ discard block |
||
59 | 59 | parent::__construct(); |
60 | 60 | |
61 | 61 | $this->addDescription( |
62 | - 'Import entities needed for constraint checks ' . |
|
62 | + 'Import entities needed for constraint checks '. |
|
63 | 63 | 'from Wikidata into the local repository.' |
64 | 64 | ); |
65 | 65 | $this->addOption( |
66 | 66 | 'config-format', |
67 | - 'The format in which the resulting configuration will be omitted: ' . |
|
68 | - '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), ' . |
|
67 | + 'The format in which the resulting configuration will be omitted: '. |
|
68 | + '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), '. |
|
69 | 69 | 'or "wgConf" for printing parts of arrays suitable for inclusion in $wgConf->settings.' |
70 | 70 | ); |
71 | 71 | $this->addOption( |
72 | 72 | 'dry-run', |
73 | 73 | 'Don’t actually import entities, just print which ones would be imported.' |
74 | 74 | ); |
75 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
75 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | $this->entityDeserializer = $repo->getInternalFormatEntityDeserializer(); |
85 | 85 | $this->entityStore = $repo->getEntityStore(); |
86 | 86 | $this->httpRequestFactory = MediaWikiServices::getInstance()->getHttpRequestFactory(); |
87 | - if ( !$this->getOption( 'dry-run', false ) ) { |
|
88 | - $this->user = User::newSystemUser( 'WikibaseQualityConstraints importer' ); |
|
87 | + if (!$this->getOption('dry-run', false)) { |
|
88 | + $this->user = User::newSystemUser('WikibaseQualityConstraints importer'); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
@@ -94,21 +94,21 @@ discard block |
||
94 | 94 | |
95 | 95 | $configUpdates = []; |
96 | 96 | |
97 | - $extensionJsonFile = __DIR__ . '/../extension.json'; |
|
98 | - $extensionJsonText = file_get_contents( $extensionJsonFile ); |
|
99 | - $extensionJson = json_decode( $extensionJsonText, /* assoc = */ true ); |
|
97 | + $extensionJsonFile = __DIR__.'/../extension.json'; |
|
98 | + $extensionJsonText = file_get_contents($extensionJsonFile); |
|
99 | + $extensionJson = json_decode($extensionJsonText, /* assoc = */ true); |
|
100 | 100 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
101 | - $wikidataEntityIds = $this->getEntitiesToImport( $extensionJson['config'], $this->getConfig() ); |
|
101 | + $wikidataEntityIds = $this->getEntitiesToImport($extensionJson['config'], $this->getConfig()); |
|
102 | 102 | |
103 | - foreach ( $wikidataEntityIds as $key => $wikidataEntityId ) { |
|
104 | - $localEntityId = $this->importEntityFromWikidata( $wikidataEntityId ); |
|
103 | + foreach ($wikidataEntityIds as $key => $wikidataEntityId) { |
|
104 | + $localEntityId = $this->importEntityFromWikidata($wikidataEntityId); |
|
105 | 105 | $configUpdates[$key] = [ |
106 | 106 | 'wikidata' => $wikidataEntityId, |
107 | 107 | 'local' => $localEntityId, |
108 | 108 | ]; |
109 | 109 | } |
110 | 110 | |
111 | - $this->outputConfigUpdates( $configUpdates ); |
|
111 | + $this->outputConfigUpdates($configUpdates); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -116,18 +116,18 @@ discard block |
||
116 | 116 | * @param Config $wikiConfig |
117 | 117 | * @return string[] |
118 | 118 | */ |
119 | - private function getEntitiesToImport( array $extensionJsonConfig, Config $wikiConfig ) { |
|
119 | + private function getEntitiesToImport(array $extensionJsonConfig, Config $wikiConfig) { |
|
120 | 120 | $wikidataEntityIds = []; |
121 | 121 | |
122 | - foreach ( $extensionJsonConfig as $key => $value ) { |
|
123 | - if ( !preg_match( '/Id$/', $key ) ) { |
|
122 | + foreach ($extensionJsonConfig as $key => $value) { |
|
123 | + if (!preg_match('/Id$/', $key)) { |
|
124 | 124 | continue; |
125 | 125 | } |
126 | 126 | |
127 | 127 | $wikidataEntityId = $value['value']; |
128 | - $localEntityId = $wikiConfig->get( $key ); |
|
128 | + $localEntityId = $wikiConfig->get($key); |
|
129 | 129 | |
130 | - if ( $localEntityId === $wikidataEntityId ) { |
|
130 | + if ($localEntityId === $wikidataEntityId) { |
|
131 | 131 | $wikidataEntityIds[$key] = $wikidataEntityId; |
132 | 132 | } |
133 | 133 | } |
@@ -139,10 +139,10 @@ discard block |
||
139 | 139 | * @param string $wikidataEntityId |
140 | 140 | * @return string local entity ID |
141 | 141 | */ |
142 | - private function importEntityFromWikidata( $wikidataEntityId ) { |
|
142 | + private function importEntityFromWikidata($wikidataEntityId) { |
|
143 | 143 | $wikidataEntityUrl = "https://www.wikidata.org/wiki/Special:EntityData/$wikidataEntityId.json"; |
144 | - $wikidataEntitiesJson = $this->httpRequestFactory->get( $wikidataEntityUrl, [], __METHOD__ ); |
|
145 | - return $this->importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ); |
|
144 | + $wikidataEntitiesJson = $this->httpRequestFactory->get($wikidataEntityUrl, [], __METHOD__); |
|
145 | + return $this->importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -150,24 +150,24 @@ discard block |
||
150 | 150 | * @param string $wikidataEntitiesJson |
151 | 151 | * @return string local entity ID |
152 | 152 | */ |
153 | - private function importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ) { |
|
153 | + private function importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson) { |
|
154 | 154 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
155 | - $wikidataEntityArray = json_decode( $wikidataEntitiesJson, true )['entities'][$wikidataEntityId]; |
|
156 | - $wikidataEntity = $this->entityDeserializer->deserialize( $wikidataEntityArray ); |
|
155 | + $wikidataEntityArray = json_decode($wikidataEntitiesJson, true)['entities'][$wikidataEntityId]; |
|
156 | + $wikidataEntity = $this->entityDeserializer->deserialize($wikidataEntityArray); |
|
157 | 157 | |
158 | - $wikidataEntity->setId( null ); |
|
158 | + $wikidataEntity->setId(null); |
|
159 | 159 | |
160 | - if ( $wikidataEntity instanceof StatementListProvider ) { |
|
160 | + if ($wikidataEntity instanceof StatementListProvider) { |
|
161 | 161 | $wikidataEntity->getStatements()->clear(); |
162 | 162 | } |
163 | 163 | |
164 | - if ( $wikidataEntity instanceof Item ) { |
|
165 | - $wikidataEntity->setSiteLinkList( new SiteLinkList() ); |
|
164 | + if ($wikidataEntity instanceof Item) { |
|
165 | + $wikidataEntity->setSiteLinkList(new SiteLinkList()); |
|
166 | 166 | } |
167 | 167 | |
168 | - if ( $this->getOption( 'dry-run', false ) ) { |
|
169 | - $wikidataEntityJson = json_encode( $this->entitySerializer->serialize( $wikidataEntity ) ); |
|
170 | - $this->output( $wikidataEntityJson . "\n" ); |
|
168 | + if ($this->getOption('dry-run', false)) { |
|
169 | + $wikidataEntityJson = json_encode($this->entitySerializer->serialize($wikidataEntity)); |
|
170 | + $this->output($wikidataEntityJson."\n"); |
|
171 | 171 | return "-$wikidataEntityId"; |
172 | 172 | } |
173 | 173 | |
@@ -180,12 +180,12 @@ discard block |
||
180 | 180 | )->getEntity(); |
181 | 181 | |
182 | 182 | return $localEntity->getId()->getSerialization(); |
183 | - } catch ( StorageException $storageException ) { |
|
184 | - return $this->storageExceptionToEntityId( $storageException ); |
|
183 | + } catch (StorageException $storageException) { |
|
184 | + return $this->storageExceptionToEntityId($storageException); |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
188 | - private function storageExceptionToEntityId( StorageException $storageException ) { |
|
188 | + private function storageExceptionToEntityId(StorageException $storageException) { |
|
189 | 189 | $message = $storageException->getMessage(); |
190 | 190 | // example messages: |
191 | 191 | // * Item [[Item:Q475|Q475]] already has label "as references" |
@@ -195,25 +195,25 @@ discard block |
||
195 | 195 | // * Property [[Property:P694|P694]] already has label "instance of" |
196 | 196 | // associated with language code en. |
197 | 197 | $pattern = '/[[|]([^][|]*)]] already has label .* associated with language code/'; |
198 | - if ( preg_match( $pattern, $message, $matches ) ) { |
|
198 | + if (preg_match($pattern, $message, $matches)) { |
|
199 | 199 | return $matches[1]; |
200 | 200 | } else { |
201 | 201 | throw $storageException; |
202 | 202 | } |
203 | 203 | } |
204 | 204 | |
205 | - private function outputConfigUpdates( array $configUpdates ) { |
|
206 | - $configFormat = $this->getOption( 'config-format', 'globals' ); |
|
207 | - switch ( $configFormat ) { |
|
205 | + private function outputConfigUpdates(array $configUpdates) { |
|
206 | + $configFormat = $this->getOption('config-format', 'globals'); |
|
207 | + switch ($configFormat) { |
|
208 | 208 | case 'globals': |
209 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
209 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
210 | 210 | break; |
211 | 211 | case 'wgConf': |
212 | - $this->outputConfigUpdatesWgConf( $configUpdates ); |
|
212 | + $this->outputConfigUpdatesWgConf($configUpdates); |
|
213 | 213 | break; |
214 | 214 | default: |
215 | - $this->error( "Invalid config format \"$configFormat\", using \"globals\"" ); |
|
216 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
215 | + $this->error("Invalid config format \"$configFormat\", using \"globals\""); |
|
216 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
217 | 217 | break; |
218 | 218 | } |
219 | 219 | } |
@@ -221,22 +221,22 @@ discard block |
||
221 | 221 | /** |
222 | 222 | * @param array[] $configUpdates |
223 | 223 | */ |
224 | - private function outputConfigUpdatesGlobals( array $configUpdates ) { |
|
225 | - foreach ( $configUpdates as $key => $value ) { |
|
226 | - $localValueCode = var_export( $value['local'], true ); |
|
227 | - $this->output( "\$wg$key = $localValueCode;\n" ); |
|
224 | + private function outputConfigUpdatesGlobals(array $configUpdates) { |
|
225 | + foreach ($configUpdates as $key => $value) { |
|
226 | + $localValueCode = var_export($value['local'], true); |
|
227 | + $this->output("\$wg$key = $localValueCode;\n"); |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
232 | 232 | * @param array[] $configUpdates |
233 | 233 | */ |
234 | - private function outputConfigUpdatesWgConf( array $configUpdates ) { |
|
235 | - foreach ( $configUpdates as $key => $value ) { |
|
236 | - $keyCode = var_export( "wg$key", true ); |
|
237 | - $wikidataValueCode = var_export( $value['wikidata'], true ); |
|
238 | - $localValueCode = var_export( $value['local'], true ); |
|
239 | - $wikiIdCode = var_export( wfWikiID(), true ); |
|
234 | + private function outputConfigUpdatesWgConf(array $configUpdates) { |
|
235 | + foreach ($configUpdates as $key => $value) { |
|
236 | + $keyCode = var_export("wg$key", true); |
|
237 | + $wikidataValueCode = var_export($value['wikidata'], true); |
|
238 | + $localValueCode = var_export($value['local'], true); |
|
239 | + $wikiIdCode = var_export(wfWikiID(), true); |
|
240 | 240 | $block = <<< EOF |
241 | 241 | $keyCode => [ |
242 | 242 | 'default' => $wikidataValueCode, |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | |
246 | 246 | |
247 | 247 | EOF; |
248 | - $this->output( $block ); |
|
248 | + $this->output($block); |
|
249 | 249 | } |
250 | 250 | } |
251 | 251 |
@@ -8,19 +8,19 @@ |
||
8 | 8 | use Wikibase\Repo\WikibaseRepo; |
9 | 9 | |
10 | 10 | return [ |
11 | - WikibaseServices::ENTITY_LOOKUP => function( MediaWikiServices $services ) { |
|
11 | + WikibaseServices::ENTITY_LOOKUP => function(MediaWikiServices $services) { |
|
12 | 12 | return new ExceptionIgnoringEntityLookup( |
13 | 13 | WikibaseRepo::getDefaultInstance()->getEntityLookup() |
14 | 14 | ); |
15 | 15 | }, |
16 | 16 | |
17 | - WikibaseServices::ENTITY_LOOKUP_WITHOUT_CACHE => function( MediaWikiServices $services ) { |
|
17 | + WikibaseServices::ENTITY_LOOKUP_WITHOUT_CACHE => function(MediaWikiServices $services) { |
|
18 | 18 | return new ExceptionIgnoringEntityLookup( |
19 | - WikibaseRepo::getDefaultInstance()->getEntityLookup( Store::LOOKUP_CACHING_RETRIEVE_ONLY ) |
|
19 | + WikibaseRepo::getDefaultInstance()->getEntityLookup(Store::LOOKUP_CACHING_RETRIEVE_ONLY) |
|
20 | 20 | ); |
21 | 21 | }, |
22 | 22 | |
23 | - WikibaseServices::PROPERTY_DATA_TYPE_LOOKUP => function( MediaWikiServices $services ) { |
|
23 | + WikibaseServices::PROPERTY_DATA_TYPE_LOOKUP => function(MediaWikiServices $services) { |
|
24 | 24 | return WikibaseRepo::getDefaultInstance()->getPropertyDataTypeLookup(); |
25 | 25 | }, |
26 | 26 | ]; |