@@ -27,24 +27,24 @@ discard block |
||
27 | 27 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResultSerializer; |
28 | 28 | |
29 | 29 | return [ |
30 | - ConstraintsServices::LOGGING_HELPER => function( MediaWikiServices $services ) { |
|
30 | + ConstraintsServices::LOGGING_HELPER => function(MediaWikiServices $services) { |
|
31 | 31 | return new LoggingHelper( |
32 | 32 | $services->getStatsdDataFactory(), |
33 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ), |
|
33 | + LoggerFactory::getInstance('WikibaseQualityConstraints'), |
|
34 | 34 | $services->getMainConfig() |
35 | 35 | ); |
36 | 36 | }, |
37 | 37 | |
38 | - ConstraintsServices::CONSTRAINT_REPOSITORY => function( MediaWikiServices $services ) { |
|
38 | + ConstraintsServices::CONSTRAINT_REPOSITORY => function(MediaWikiServices $services) { |
|
39 | 39 | return new ConstraintRepository(); |
40 | 40 | }, |
41 | 41 | |
42 | - ConstraintsServices::CONSTRAINT_LOOKUP => function( MediaWikiServices $services ) { |
|
43 | - $constraintRepository = ConstraintsServices::getConstraintRepository( $services ); |
|
44 | - return new CachingConstraintLookup( $constraintRepository ); |
|
42 | + ConstraintsServices::CONSTRAINT_LOOKUP => function(MediaWikiServices $services) { |
|
43 | + $constraintRepository = ConstraintsServices::getConstraintRepository($services); |
|
44 | + return new CachingConstraintLookup($constraintRepository); |
|
45 | 45 | }, |
46 | 46 | |
47 | - ConstraintsServices::CHECK_RESULT_SERIALIZER => function( MediaWikiServices $services ) { |
|
47 | + ConstraintsServices::CHECK_RESULT_SERIALIZER => function(MediaWikiServices $services) { |
|
48 | 48 | return new CheckResultSerializer( |
49 | 49 | new ConstraintSerializer( |
50 | 50 | false // constraint parameters are not exposed |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | ); |
56 | 56 | }, |
57 | 57 | |
58 | - ConstraintsServices::CHECK_RESULT_DESERIALIZER => function( MediaWikiServices $services ) { |
|
58 | + ConstraintsServices::CHECK_RESULT_DESERIALIZER => function(MediaWikiServices $services) { |
|
59 | 59 | // TODO in the future, get EntityIdParser and DataValueFactory from $services? |
60 | 60 | $repo = WikibaseRepo::getDefaultInstance(); |
61 | 61 | $entityIdParser = $repo->getEntityIdParser(); |
@@ -72,11 +72,11 @@ discard block |
||
72 | 72 | ); |
73 | 73 | }, |
74 | 74 | |
75 | - ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => function( MediaWikiServices $services ) { |
|
75 | + ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => function(MediaWikiServices $services) { |
|
76 | 76 | return new ViolationMessageSerializer(); |
77 | 77 | }, |
78 | 78 | |
79 | - ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => function( MediaWikiServices $services ) { |
|
79 | + ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => function(MediaWikiServices $services) { |
|
80 | 80 | // TODO in the future, get EntityIdParser and DataValueFactory from $services? |
81 | 81 | $repo = WikibaseRepo::getDefaultInstance(); |
82 | 82 | $entityIdParser = $repo->getEntityIdParser(); |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | ); |
89 | 89 | }, |
90 | 90 | |
91 | - ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => function( MediaWikiServices $services ) { |
|
91 | + ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => function(MediaWikiServices $services) { |
|
92 | 92 | // TODO in the future, get DeserializerFactory and concept base URIs from $services? |
93 | 93 | $repo = WikibaseRepo::getDefaultInstance(); |
94 | 94 | $deserializerFactory = $repo->getBaseDataModelDeserializerFactory(); |
@@ -101,11 +101,11 @@ discard block |
||
101 | 101 | ); |
102 | 102 | }, |
103 | 103 | |
104 | - ConstraintsServices::CONNECTION_CHECKER_HELPER => function( MediaWikiServices $services ) { |
|
104 | + ConstraintsServices::CONNECTION_CHECKER_HELPER => function(MediaWikiServices $services) { |
|
105 | 105 | return new ConnectionCheckerHelper(); |
106 | 106 | }, |
107 | 107 | |
108 | - ConstraintsServices::RANGE_CHECKER_HELPER => function( MediaWikiServices $services ) { |
|
108 | + ConstraintsServices::RANGE_CHECKER_HELPER => function(MediaWikiServices $services) { |
|
109 | 109 | // TODO in the future, get UnitConverter from $services? |
110 | 110 | $repo = WikibaseRepo::getDefaultInstance(); |
111 | 111 | $unitConverter = $repo->getUnitConverter(); |
@@ -116,9 +116,9 @@ discard block |
||
116 | 116 | ); |
117 | 117 | }, |
118 | 118 | |
119 | - ConstraintsServices::SPARQL_HELPER => function( MediaWikiServices $services ) { |
|
120 | - $endpoint = $services->getMainConfig()->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
121 | - if ( $endpoint === '' ) { |
|
119 | + ConstraintsServices::SPARQL_HELPER => function(MediaWikiServices $services) { |
|
120 | + $endpoint = $services->getMainConfig()->get('WBQualityConstraintsSparqlEndpoint'); |
|
121 | + if ($endpoint === '') { |
|
122 | 122 | return new DummySparqlHelper(); |
123 | 123 | } |
124 | 124 | |
@@ -134,115 +134,115 @@ discard block |
||
134 | 134 | $entityIdParser, |
135 | 135 | $propertyDataTypeLookup, |
136 | 136 | $services->getMainWANObjectCache(), |
137 | - ConstraintsServices::getViolationMessageSerializer( $services ), |
|
138 | - ConstraintsServices::getViolationMessageDeserializer( $services ), |
|
137 | + ConstraintsServices::getViolationMessageSerializer($services), |
|
138 | + ConstraintsServices::getViolationMessageDeserializer($services), |
|
139 | 139 | $services->getStatsdDataFactory(), |
140 | - wfWikiID() . ' WikibaseQualityConstraints ' . Http::userAgent(), |
|
140 | + wfWikiID().' WikibaseQualityConstraints '.Http::userAgent(), |
|
141 | 141 | $services->getHttpRequestFactory() |
142 | 142 | ); |
143 | 143 | }, |
144 | 144 | |
145 | - ConstraintsServices::TYPE_CHECKER_HELPER => function( MediaWikiServices $services ) { |
|
145 | + ConstraintsServices::TYPE_CHECKER_HELPER => function(MediaWikiServices $services) { |
|
146 | 146 | return new TypeCheckerHelper( |
147 | - WikibaseServices::getEntityLookup( $services ), |
|
147 | + WikibaseServices::getEntityLookup($services), |
|
148 | 148 | $services->getMainConfig(), |
149 | - ConstraintsServices::getSparqlHelper( $services ), |
|
149 | + ConstraintsServices::getSparqlHelper($services), |
|
150 | 150 | $services->getStatsdDataFactory() |
151 | 151 | ); |
152 | 152 | }, |
153 | 153 | |
154 | - ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => function( MediaWikiServices $services ) { |
|
154 | + ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => function(MediaWikiServices $services) { |
|
155 | 155 | // TODO in the future, get StatementGuidParser from $services? |
156 | 156 | $repo = WikibaseRepo::getDefaultInstance(); |
157 | 157 | $statementGuidParser = $repo->getStatementGuidParser(); |
158 | 158 | |
159 | 159 | $config = $services->getMainConfig(); |
160 | 160 | $checkerMap = [ |
161 | - $config->get( 'WBQualityConstraintsConflictsWithConstraintId' ) |
|
162 | - => ConstraintCheckerServices::getConflictsWithChecker( $services ), |
|
163 | - $config->get( 'WBQualityConstraintsItemRequiresClaimConstraintId' ) |
|
164 | - => ConstraintCheckerServices::getItemChecker( $services ), |
|
165 | - $config->get( 'WBQualityConstraintsValueRequiresClaimConstraintId' ) |
|
166 | - => ConstraintCheckerServices::getTargetRequiredClaimChecker( $services ), |
|
167 | - $config->get( 'WBQualityConstraintsSymmetricConstraintId' ) |
|
168 | - => ConstraintCheckerServices::getSymmetricChecker( $services ), |
|
169 | - $config->get( 'WBQualityConstraintsInverseConstraintId' ) |
|
170 | - => ConstraintCheckerServices::getInverseChecker( $services ), |
|
171 | - $config->get( 'WBQualityConstraintsUsedAsQualifierConstraintId' ) |
|
172 | - => ConstraintCheckerServices::getQualifierChecker( $services ), |
|
173 | - $config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' ) |
|
174 | - => ConstraintCheckerServices::getQualifiersChecker( $services ), |
|
175 | - $config->get( 'WBQualityConstraintsMandatoryQualifierConstraintId' ) |
|
176 | - => ConstraintCheckerServices::getMandatoryQualifiersChecker( $services ), |
|
177 | - $config->get( 'WBQualityConstraintsRangeConstraintId' ) |
|
178 | - => ConstraintCheckerServices::getRangeChecker( $services ), |
|
179 | - $config->get( 'WBQualityConstraintsDifferenceWithinRangeConstraintId' ) |
|
180 | - => ConstraintCheckerServices::getDiffWithinRangeChecker( $services ), |
|
181 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ) |
|
182 | - => ConstraintCheckerServices::getTypeChecker( $services ), |
|
183 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ) |
|
184 | - => ConstraintCheckerServices::getValueTypeChecker( $services ), |
|
185 | - $config->get( 'WBQualityConstraintsSingleValueConstraintId' ) |
|
186 | - => ConstraintCheckerServices::getSingleValueChecker( $services ), |
|
187 | - $config->get( 'WBQualityConstraintsMultiValueConstraintId' ) |
|
188 | - => ConstraintCheckerServices::getMultiValueChecker( $services ), |
|
189 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ) |
|
190 | - => ConstraintCheckerServices::getUniqueValueChecker( $services ), |
|
191 | - $config->get( 'WBQualityConstraintsFormatConstraintId' ) |
|
192 | - => ConstraintCheckerServices::getFormatChecker( $services ), |
|
193 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ) |
|
194 | - => ConstraintCheckerServices::getCommonsLinkChecker( $services ), |
|
195 | - $config->get( 'WBQualityConstraintsOneOfConstraintId' ) |
|
196 | - => ConstraintCheckerServices::getOneOfChecker( $services ), |
|
197 | - $config->get( 'WBQualityConstraintsUsedForValuesOnlyConstraintId' ) |
|
198 | - => ConstraintCheckerServices::getValueOnlyChecker( $services ), |
|
199 | - $config->get( 'WBQualityConstraintsUsedAsReferenceConstraintId' ) |
|
200 | - => ConstraintCheckerServices::getReferenceChecker( $services ), |
|
201 | - $config->get( 'WBQualityConstraintsNoBoundsConstraintId' ) |
|
202 | - => ConstraintCheckerServices::getNoBoundsChecker( $services ), |
|
203 | - $config->get( 'WBQualityConstraintsAllowedUnitsConstraintId' ) |
|
204 | - => ConstraintCheckerServices::getAllowedUnitsChecker( $services ), |
|
205 | - $config->get( 'WBQualityConstraintsSingleBestValueConstraintId' ) |
|
206 | - => ConstraintCheckerServices::getSingleBestValueChecker( $services ), |
|
207 | - $config->get( 'WBQualityConstraintsAllowedEntityTypesConstraintId' ) |
|
208 | - => ConstraintCheckerServices::getEntityTypeChecker( $services ), |
|
209 | - $config->get( 'WBQualityConstraintsNoneOfConstraintId' ) |
|
210 | - => ConstraintCheckerServices::getNoneOfChecker( $services ), |
|
211 | - $config->get( 'WBQualityConstraintsIntegerConstraintId' ) |
|
212 | - => ConstraintCheckerServices::getIntegerChecker( $services ), |
|
213 | - $config->get( 'WBQualityConstraintsCitationNeededConstraintId' ) |
|
214 | - => ConstraintCheckerServices::getCitationNeededChecker( $services ), |
|
215 | - $config->get( 'WBQualityConstraintsPropertyScopeConstraintId' ) |
|
216 | - => ConstraintCheckerServices::getPropertyScopeChecker( $services ), |
|
217 | - $config->get( 'WBQualityConstraintsContemporaryConstraintId' ) |
|
218 | - => ConstraintCheckerServices::getContemporaryChecker( $services ), |
|
161 | + $config->get('WBQualityConstraintsConflictsWithConstraintId') |
|
162 | + => ConstraintCheckerServices::getConflictsWithChecker($services), |
|
163 | + $config->get('WBQualityConstraintsItemRequiresClaimConstraintId') |
|
164 | + => ConstraintCheckerServices::getItemChecker($services), |
|
165 | + $config->get('WBQualityConstraintsValueRequiresClaimConstraintId') |
|
166 | + => ConstraintCheckerServices::getTargetRequiredClaimChecker($services), |
|
167 | + $config->get('WBQualityConstraintsSymmetricConstraintId') |
|
168 | + => ConstraintCheckerServices::getSymmetricChecker($services), |
|
169 | + $config->get('WBQualityConstraintsInverseConstraintId') |
|
170 | + => ConstraintCheckerServices::getInverseChecker($services), |
|
171 | + $config->get('WBQualityConstraintsUsedAsQualifierConstraintId') |
|
172 | + => ConstraintCheckerServices::getQualifierChecker($services), |
|
173 | + $config->get('WBQualityConstraintsAllowedQualifiersConstraintId') |
|
174 | + => ConstraintCheckerServices::getQualifiersChecker($services), |
|
175 | + $config->get('WBQualityConstraintsMandatoryQualifierConstraintId') |
|
176 | + => ConstraintCheckerServices::getMandatoryQualifiersChecker($services), |
|
177 | + $config->get('WBQualityConstraintsRangeConstraintId') |
|
178 | + => ConstraintCheckerServices::getRangeChecker($services), |
|
179 | + $config->get('WBQualityConstraintsDifferenceWithinRangeConstraintId') |
|
180 | + => ConstraintCheckerServices::getDiffWithinRangeChecker($services), |
|
181 | + $config->get('WBQualityConstraintsTypeConstraintId') |
|
182 | + => ConstraintCheckerServices::getTypeChecker($services), |
|
183 | + $config->get('WBQualityConstraintsValueTypeConstraintId') |
|
184 | + => ConstraintCheckerServices::getValueTypeChecker($services), |
|
185 | + $config->get('WBQualityConstraintsSingleValueConstraintId') |
|
186 | + => ConstraintCheckerServices::getSingleValueChecker($services), |
|
187 | + $config->get('WBQualityConstraintsMultiValueConstraintId') |
|
188 | + => ConstraintCheckerServices::getMultiValueChecker($services), |
|
189 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId') |
|
190 | + => ConstraintCheckerServices::getUniqueValueChecker($services), |
|
191 | + $config->get('WBQualityConstraintsFormatConstraintId') |
|
192 | + => ConstraintCheckerServices::getFormatChecker($services), |
|
193 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId') |
|
194 | + => ConstraintCheckerServices::getCommonsLinkChecker($services), |
|
195 | + $config->get('WBQualityConstraintsOneOfConstraintId') |
|
196 | + => ConstraintCheckerServices::getOneOfChecker($services), |
|
197 | + $config->get('WBQualityConstraintsUsedForValuesOnlyConstraintId') |
|
198 | + => ConstraintCheckerServices::getValueOnlyChecker($services), |
|
199 | + $config->get('WBQualityConstraintsUsedAsReferenceConstraintId') |
|
200 | + => ConstraintCheckerServices::getReferenceChecker($services), |
|
201 | + $config->get('WBQualityConstraintsNoBoundsConstraintId') |
|
202 | + => ConstraintCheckerServices::getNoBoundsChecker($services), |
|
203 | + $config->get('WBQualityConstraintsAllowedUnitsConstraintId') |
|
204 | + => ConstraintCheckerServices::getAllowedUnitsChecker($services), |
|
205 | + $config->get('WBQualityConstraintsSingleBestValueConstraintId') |
|
206 | + => ConstraintCheckerServices::getSingleBestValueChecker($services), |
|
207 | + $config->get('WBQualityConstraintsAllowedEntityTypesConstraintId') |
|
208 | + => ConstraintCheckerServices::getEntityTypeChecker($services), |
|
209 | + $config->get('WBQualityConstraintsNoneOfConstraintId') |
|
210 | + => ConstraintCheckerServices::getNoneOfChecker($services), |
|
211 | + $config->get('WBQualityConstraintsIntegerConstraintId') |
|
212 | + => ConstraintCheckerServices::getIntegerChecker($services), |
|
213 | + $config->get('WBQualityConstraintsCitationNeededConstraintId') |
|
214 | + => ConstraintCheckerServices::getCitationNeededChecker($services), |
|
215 | + $config->get('WBQualityConstraintsPropertyScopeConstraintId') |
|
216 | + => ConstraintCheckerServices::getPropertyScopeChecker($services), |
|
217 | + $config->get('WBQualityConstraintsContemporaryConstraintId') |
|
218 | + => ConstraintCheckerServices::getContemporaryChecker($services), |
|
219 | 219 | ]; |
220 | 220 | |
221 | 221 | return new DelegatingConstraintChecker( |
222 | - WikibaseServices::getEntityLookup( $services ), |
|
222 | + WikibaseServices::getEntityLookup($services), |
|
223 | 223 | $checkerMap, |
224 | - ConstraintsServices::getConstraintLookup( $services ), |
|
225 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
224 | + ConstraintsServices::getConstraintLookup($services), |
|
225 | + ConstraintsServices::getConstraintParameterParser($services), |
|
226 | 226 | $statementGuidParser, |
227 | - ConstraintsServices::getLoggingHelper( $services ), |
|
228 | - $config->get( 'WBQualityConstraintsCheckQualifiers' ), |
|
229 | - $config->get( 'WBQualityConstraintsCheckReferences' ), |
|
230 | - $config->get( 'WBQualityConstraintsPropertiesWithViolatingQualifiers' ) |
|
227 | + ConstraintsServices::getLoggingHelper($services), |
|
228 | + $config->get('WBQualityConstraintsCheckQualifiers'), |
|
229 | + $config->get('WBQualityConstraintsCheckReferences'), |
|
230 | + $config->get('WBQualityConstraintsPropertiesWithViolatingQualifiers') |
|
231 | 231 | ); |
232 | 232 | }, |
233 | 233 | |
234 | - ConstraintsServices::RESULTS_SOURCE => function( MediaWikiServices $services ) { |
|
234 | + ConstraintsServices::RESULTS_SOURCE => function(MediaWikiServices $services) { |
|
235 | 235 | $config = $services->getMainConfig(); |
236 | 236 | $resultsSource = new CheckingResultsSource( |
237 | - ConstraintsServices::getDelegatingConstraintChecker( $services ) |
|
237 | + ConstraintsServices::getDelegatingConstraintChecker($services) |
|
238 | 238 | ); |
239 | 239 | |
240 | - if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) { |
|
240 | + if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) { |
|
241 | 241 | $possiblyStaleConstraintTypes = [ |
242 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ), |
|
243 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ), |
|
244 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ), |
|
245 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ), |
|
242 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId'), |
|
243 | + $config->get('WBQualityConstraintsTypeConstraintId'), |
|
244 | + $config->get('WBQualityConstraintsValueTypeConstraintId'), |
|
245 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId'), |
|
246 | 246 | ]; |
247 | 247 | // TODO in the future, get EntityIdParser and WikiPageEntityMetaDataAccessor from $services? |
248 | 248 | $repo = WikibaseRepo::getDefaultInstance(); |
@@ -254,21 +254,21 @@ discard block |
||
254 | 254 | $entityNamespaceLookup, |
255 | 255 | $services->getSlotRoleStore() |
256 | 256 | ), |
257 | - $repo->getSettings()->getSetting( 'changesDatabase' ), |
|
257 | + $repo->getSettings()->getSetting('changesDatabase'), |
|
258 | 258 | '' // Empty string here means this only works for the local repo |
259 | 259 | ); |
260 | 260 | |
261 | 261 | $resultsSource = new CachingResultsSource( |
262 | 262 | $resultsSource, |
263 | 263 | ResultsCache::getDefaultInstance(), |
264 | - ConstraintsServices::getCheckResultSerializer( $services ), |
|
265 | - ConstraintsServices::getCheckResultDeserializer( $services ), |
|
264 | + ConstraintsServices::getCheckResultSerializer($services), |
|
265 | + ConstraintsServices::getCheckResultDeserializer($services), |
|
266 | 266 | $wikiPageEntityMetaDataAccessor, |
267 | 267 | $entityIdParser, |
268 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ), |
|
268 | + $config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'), |
|
269 | 269 | $possiblyStaleConstraintTypes, |
270 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds' ), |
|
271 | - ConstraintsServices::getLoggingHelper( $services ) |
|
270 | + $config->get('WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds'), |
|
271 | + ConstraintsServices::getLoggingHelper($services) |
|
272 | 272 | ); |
273 | 273 | } |
274 | 274 |
@@ -120,18 +120,18 @@ discard block |
||
120 | 120 | $this->dataFactory = $dataFactory; |
121 | 121 | $this->defaultUserAgent = $defaultUserAgent; |
122 | 122 | $this->requestFactory = $requestFactory; |
123 | - $this->entityPrefix = $rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY ); |
|
123 | + $this->entityPrefix = $rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY); |
|
124 | 124 | $this->prefixes = <<<EOT |
125 | -PREFIX wd: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY )}> |
|
126 | -PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}> |
|
127 | -PREFIX wdt: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_DIRECT_CLAIM )}> |
|
128 | -PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}> |
|
129 | -PREFIX p: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM )}> |
|
130 | -PREFIX ps: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM_STATEMENT )}> |
|
131 | -PREFIX pq: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER )}> |
|
132 | -PREFIX pqv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER_VALUE )}> |
|
133 | -PREFIX pr: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE )}> |
|
134 | -PREFIX prv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE_VALUE )}> |
|
125 | +PREFIX wd: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY)}> |
|
126 | +PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}> |
|
127 | +PREFIX wdt: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_DIRECT_CLAIM)}> |
|
128 | +PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}> |
|
129 | +PREFIX p: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM)}> |
|
130 | +PREFIX ps: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM_STATEMENT)}> |
|
131 | +PREFIX pq: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER)}> |
|
132 | +PREFIX pqv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER_VALUE)}> |
|
133 | +PREFIX pr: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE)}> |
|
134 | +PREFIX prv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE_VALUE)}> |
|
135 | 135 | PREFIX wikibase: <http://wikiba.se/ontology#> |
136 | 136 | PREFIX wikibase-beta: <http://wikiba.se/ontology-beta#> |
137 | 137 | EOT; |
@@ -146,21 +146,21 @@ discard block |
||
146 | 146 | * @return CachedBool |
147 | 147 | * @throws SparqlHelperException if the query times out or some other error occurs |
148 | 148 | */ |
149 | - public function hasType( $id, array $classes, $withInstance ) { |
|
150 | - $instanceOfId = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
151 | - $subclassOfId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
149 | + public function hasType($id, array $classes, $withInstance) { |
|
150 | + $instanceOfId = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
151 | + $subclassOfId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
152 | 152 | |
153 | - $path = ( $withInstance ? "wdt:$instanceOfId/" : "" ) . "wdt:$subclassOfId*"; |
|
153 | + $path = ($withInstance ? "wdt:$instanceOfId/" : "")."wdt:$subclassOfId*"; |
|
154 | 154 | |
155 | 155 | $metadatas = []; |
156 | 156 | |
157 | - foreach ( array_chunk( $classes, 20 ) as $classesChunk ) { |
|
158 | - $classesValues = implode( ' ', array_map( |
|
159 | - function( $class ) { |
|
160 | - return 'wd:' . $class; |
|
157 | + foreach (array_chunk($classes, 20) as $classesChunk) { |
|
158 | + $classesValues = implode(' ', array_map( |
|
159 | + function($class) { |
|
160 | + return 'wd:'.$class; |
|
161 | 161 | }, |
162 | 162 | $classesChunk |
163 | - ) ); |
|
163 | + )); |
|
164 | 164 | |
165 | 165 | $query = <<<EOF |
166 | 166 | ASK { |
@@ -171,19 +171,19 @@ discard block |
||
171 | 171 | EOF; |
172 | 172 | // TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually |
173 | 173 | |
174 | - $result = $this->runQuery( $query ); |
|
174 | + $result = $this->runQuery($query); |
|
175 | 175 | $metadatas[] = $result->getMetadata(); |
176 | - if ( $result->getArray()['boolean'] ) { |
|
176 | + if ($result->getArray()['boolean']) { |
|
177 | 177 | return new CachedBool( |
178 | 178 | true, |
179 | - Metadata::merge( $metadatas ) |
|
179 | + Metadata::merge($metadatas) |
|
180 | 180 | ); |
181 | 181 | } |
182 | 182 | } |
183 | 183 | |
184 | 184 | return new CachedBool( |
185 | 185 | false, |
186 | - Metadata::merge( $metadatas ) |
|
186 | + Metadata::merge($metadatas) |
|
187 | 187 | ); |
188 | 188 | } |
189 | 189 | |
@@ -199,10 +199,10 @@ discard block |
||
199 | 199 | $ignoreDeprecatedStatements |
200 | 200 | ) { |
201 | 201 | $pid = $statement->getPropertyId()->serialize(); |
202 | - $guid = str_replace( '$', '-', $statement->getGuid() ); |
|
202 | + $guid = str_replace('$', '-', $statement->getGuid()); |
|
203 | 203 | |
204 | 204 | $deprecatedFilter = ''; |
205 | - if ( $ignoreDeprecatedStatements ) { |
|
205 | + if ($ignoreDeprecatedStatements) { |
|
206 | 206 | $deprecatedFilter .= 'MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }'; |
207 | 207 | $deprecatedFilter .= 'MINUS { ?otherStatement wikibase-beta:rank wikibase-beta:DeprecatedRank. }'; |
208 | 208 | } |
@@ -222,9 +222,9 @@ discard block |
||
222 | 222 | LIMIT 10 |
223 | 223 | EOF; |
224 | 224 | |
225 | - $result = $this->runQuery( $query ); |
|
225 | + $result = $this->runQuery($query); |
|
226 | 226 | |
227 | - return $this->getOtherEntities( $result ); |
|
227 | + return $this->getOtherEntities($result); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -249,16 +249,15 @@ discard block |
||
249 | 249 | $dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty( |
250 | 250 | $snak->getPropertyId() |
251 | 251 | ); |
252 | - list( $value, $isFullValue ) = $this->getRdfLiteral( $dataType, $dataValue ); |
|
253 | - if ( $isFullValue ) { |
|
252 | + list($value, $isFullValue) = $this->getRdfLiteral($dataType, $dataValue); |
|
253 | + if ($isFullValue) { |
|
254 | 254 | $prefix .= 'v'; |
255 | 255 | } |
256 | 256 | $path = $type === Context::TYPE_QUALIFIER ? |
257 | - "$prefix:$pid" : |
|
258 | - "prov:wasDerivedFrom/$prefix:$pid"; |
|
257 | + "$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid"; |
|
259 | 258 | |
260 | 259 | $deprecatedFilter = ''; |
261 | - if ( $ignoreDeprecatedStatements ) { |
|
260 | + if ($ignoreDeprecatedStatements) { |
|
262 | 261 | $deprecatedFilter = <<< EOF |
263 | 262 | MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. } |
264 | 263 | MINUS { ?otherStatement wikibase-beta:rank wikibase-beta:DeprecatedRank. } |
@@ -279,9 +278,9 @@ discard block |
||
279 | 278 | LIMIT 10 |
280 | 279 | EOF; |
281 | 280 | |
282 | - $result = $this->runQuery( $query ); |
|
281 | + $result = $this->runQuery($query); |
|
283 | 282 | |
284 | - return $this->getOtherEntities( $result ); |
|
283 | + return $this->getOtherEntities($result); |
|
285 | 284 | } |
286 | 285 | |
287 | 286 | /** |
@@ -291,8 +290,8 @@ discard block |
||
291 | 290 | * |
292 | 291 | * @return string |
293 | 292 | */ |
294 | - private function stringLiteral( $text ) { |
|
295 | - return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"'; |
|
293 | + private function stringLiteral($text) { |
|
294 | + return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"'; |
|
296 | 295 | } |
297 | 296 | |
298 | 297 | /** |
@@ -302,17 +301,17 @@ discard block |
||
302 | 301 | * |
303 | 302 | * @return CachedEntityIds |
304 | 303 | */ |
305 | - private function getOtherEntities( CachedQueryResults $results ) { |
|
306 | - return new CachedEntityIds( array_map( |
|
307 | - function ( $resultBindings ) { |
|
304 | + private function getOtherEntities(CachedQueryResults $results) { |
|
305 | + return new CachedEntityIds(array_map( |
|
306 | + function($resultBindings) { |
|
308 | 307 | $entityIRI = $resultBindings['otherEntity']['value']; |
309 | - $entityPrefixLength = strlen( $this->entityPrefix ); |
|
310 | - if ( substr( $entityIRI, 0, $entityPrefixLength ) === $this->entityPrefix ) { |
|
308 | + $entityPrefixLength = strlen($this->entityPrefix); |
|
309 | + if (substr($entityIRI, 0, $entityPrefixLength) === $this->entityPrefix) { |
|
311 | 310 | try { |
312 | 311 | return $this->entityIdParser->parse( |
313 | - substr( $entityIRI, $entityPrefixLength ) |
|
312 | + substr($entityIRI, $entityPrefixLength) |
|
314 | 313 | ); |
315 | - } catch ( EntityIdParsingException $e ) { |
|
314 | + } catch (EntityIdParsingException $e) { |
|
316 | 315 | // fall through |
317 | 316 | } |
318 | 317 | } |
@@ -320,7 +319,7 @@ discard block |
||
320 | 319 | return null; |
321 | 320 | }, |
322 | 321 | $results->getArray()['results']['bindings'] |
323 | - ), $results->getMetadata() ); |
|
322 | + ), $results->getMetadata()); |
|
324 | 323 | } |
325 | 324 | |
326 | 325 | // @codingStandardsIgnoreStart cyclomatic complexity of this function is too high |
@@ -333,47 +332,47 @@ discard block |
||
333 | 332 | * @return array the literal or IRI as a string in SPARQL syntax, |
334 | 333 | * and a boolean indicating whether it refers to a full value node or not |
335 | 334 | */ |
336 | - private function getRdfLiteral( $dataType, DataValue $dataValue ) { |
|
337 | - switch ( $dataType ) { |
|
335 | + private function getRdfLiteral($dataType, DataValue $dataValue) { |
|
336 | + switch ($dataType) { |
|
338 | 337 | case 'string': |
339 | 338 | case 'external-id': |
340 | - return [ $this->stringLiteral( $dataValue->getValue() ), false ]; |
|
339 | + return [$this->stringLiteral($dataValue->getValue()), false]; |
|
341 | 340 | case 'commonsMedia': |
342 | - $url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() ); |
|
343 | - return [ '<' . $url . '>', false ]; |
|
341 | + $url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue()); |
|
342 | + return ['<'.$url.'>', false]; |
|
344 | 343 | case 'geo-shape': |
345 | - $url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() ); |
|
346 | - return [ '<' . $url . '>', false ]; |
|
344 | + $url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue()); |
|
345 | + return ['<'.$url.'>', false]; |
|
347 | 346 | case 'tabular-data': |
348 | - $url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() ); |
|
349 | - return [ '<' . $url . '>', false ]; |
|
347 | + $url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue()); |
|
348 | + return ['<'.$url.'>', false]; |
|
350 | 349 | case 'url': |
351 | 350 | $url = $dataValue->getValue(); |
352 | - if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) { |
|
351 | + if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) { |
|
353 | 352 | // not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF) |
354 | 353 | // such an URL should never reach us, so just throw |
355 | - throw new InvalidArgumentException( 'invalid URL: ' . $url ); |
|
354 | + throw new InvalidArgumentException('invalid URL: '.$url); |
|
356 | 355 | } |
357 | - return [ '<' . $url . '>', false ]; |
|
356 | + return ['<'.$url.'>', false]; |
|
358 | 357 | case 'wikibase-item': |
359 | 358 | case 'wikibase-property': |
360 | 359 | /** @var EntityIdValue $dataValue */ |
361 | - return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ]; |
|
360 | + return ['wd:'.$dataValue->getEntityId()->getSerialization(), false]; |
|
362 | 361 | case 'monolingualtext': |
363 | 362 | /** @var MonolingualTextValue $dataValue */ |
364 | 363 | $lang = $dataValue->getLanguageCode(); |
365 | - if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) { |
|
364 | + if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) { |
|
366 | 365 | // not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG) |
367 | 366 | // such a language tag should never reach us, so just throw |
368 | - throw new InvalidArgumentException( 'invalid language tag: ' . $lang ); |
|
367 | + throw new InvalidArgumentException('invalid language tag: '.$lang); |
|
369 | 368 | } |
370 | - return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ]; |
|
369 | + return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false]; |
|
371 | 370 | case 'globe-coordinate': |
372 | 371 | case 'quantity': |
373 | 372 | case 'time': |
374 | - return [ 'wdv:' . $dataValue->getHash(), true ]; |
|
373 | + return ['wdv:'.$dataValue->getHash(), true]; |
|
375 | 374 | default: |
376 | - throw new InvalidArgumentException( 'unknown data type: ' . $dataType ); |
|
375 | + throw new InvalidArgumentException('unknown data type: '.$dataType); |
|
377 | 376 | } |
378 | 377 | } |
379 | 378 | // @codingStandardsIgnoreEnd |
@@ -386,44 +385,44 @@ discard block |
||
386 | 385 | * @throws SparqlHelperException if the query times out or some other error occurs |
387 | 386 | * @throws ConstraintParameterException if the $regex is invalid |
388 | 387 | */ |
389 | - public function matchesRegularExpression( $text, $regex ) { |
|
388 | + public function matchesRegularExpression($text, $regex) { |
|
390 | 389 | // caching wrapper around matchesRegularExpressionWithSparql |
391 | 390 | |
392 | - $textHash = hash( 'sha256', $text ); |
|
391 | + $textHash = hash('sha256', $text); |
|
393 | 392 | $cacheKey = $this->cache->makeKey( |
394 | 393 | 'WikibaseQualityConstraints', // extension |
395 | 394 | 'regex', // action |
396 | 395 | 'WDQS-Java', // regex flavor |
397 | - hash( 'sha256', $regex ) |
|
396 | + hash('sha256', $regex) |
|
398 | 397 | ); |
399 | - $cacheMapSize = $this->config->get( 'WBQualityConstraintsFormatCacheMapSize' ); |
|
398 | + $cacheMapSize = $this->config->get('WBQualityConstraintsFormatCacheMapSize'); |
|
400 | 399 | |
401 | 400 | $cacheMapArray = $this->cache->getWithSetCallback( |
402 | 401 | $cacheKey, |
403 | 402 | WANObjectCache::TTL_DAY, |
404 | - function( $cacheMapArray ) use ( $text, $regex, $textHash, $cacheMapSize ) { |
|
403 | + function($cacheMapArray) use ($text, $regex, $textHash, $cacheMapSize) { |
|
405 | 404 | // Initialize the cache map if not set |
406 | - if ( $cacheMapArray === false ) { |
|
405 | + if ($cacheMapArray === false) { |
|
407 | 406 | $key = 'wikibase.quality.constraints.regex.cache.refresh.init'; |
408 | - $this->dataFactory->increment( $key ); |
|
407 | + $this->dataFactory->increment($key); |
|
409 | 408 | return []; |
410 | 409 | } |
411 | 410 | |
412 | 411 | $key = 'wikibase.quality.constraints.regex.cache.refresh'; |
413 | - $this->dataFactory->increment( $key ); |
|
414 | - $cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $cacheMapSize ); |
|
415 | - if ( $cacheMap->has( $textHash ) ) { |
|
412 | + $this->dataFactory->increment($key); |
|
413 | + $cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $cacheMapSize); |
|
414 | + if ($cacheMap->has($textHash)) { |
|
416 | 415 | $key = 'wikibase.quality.constraints.regex.cache.refresh.hit'; |
417 | - $this->dataFactory->increment( $key ); |
|
418 | - $cacheMap->get( $textHash ); // ping cache |
|
416 | + $this->dataFactory->increment($key); |
|
417 | + $cacheMap->get($textHash); // ping cache |
|
419 | 418 | } else { |
420 | 419 | $key = 'wikibase.quality.constraints.regex.cache.refresh.miss'; |
421 | - $this->dataFactory->increment( $key ); |
|
420 | + $this->dataFactory->increment($key); |
|
422 | 421 | try { |
423 | - $matches = $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
424 | - } catch ( ConstraintParameterException $e ) { |
|
425 | - $matches = $this->serializeConstraintParameterException( $e ); |
|
426 | - } catch ( SparqlHelperException $e ) { |
|
422 | + $matches = $this->matchesRegularExpressionWithSparql($text, $regex); |
|
423 | + } catch (ConstraintParameterException $e) { |
|
424 | + $matches = $this->serializeConstraintParameterException($e); |
|
425 | + } catch (SparqlHelperException $e) { |
|
427 | 426 | // don’t cache this |
428 | 427 | return $cacheMap->toArray(); |
429 | 428 | } |
@@ -447,42 +446,42 @@ discard block |
||
447 | 446 | ] |
448 | 447 | ); |
449 | 448 | |
450 | - if ( isset( $cacheMapArray[$textHash] ) ) { |
|
449 | + if (isset($cacheMapArray[$textHash])) { |
|
451 | 450 | $key = 'wikibase.quality.constraints.regex.cache.hit'; |
452 | - $this->dataFactory->increment( $key ); |
|
451 | + $this->dataFactory->increment($key); |
|
453 | 452 | $matches = $cacheMapArray[$textHash]; |
454 | - if ( is_bool( $matches ) ) { |
|
453 | + if (is_bool($matches)) { |
|
455 | 454 | return $matches; |
456 | - } elseif ( is_array( $matches ) && |
|
457 | - $matches['type'] == ConstraintParameterException::class ) { |
|
458 | - throw $this->deserializeConstraintParameterException( $matches ); |
|
455 | + } elseif (is_array($matches) && |
|
456 | + $matches['type'] == ConstraintParameterException::class) { |
|
457 | + throw $this->deserializeConstraintParameterException($matches); |
|
459 | 458 | } else { |
460 | 459 | throw new MWException( |
461 | - 'Value of unknown type in object cache (' . |
|
462 | - 'cache key: ' . $cacheKey . ', ' . |
|
463 | - 'cache map key: ' . $textHash . ', ' . |
|
464 | - 'value type: ' . gettype( $matches ) . ')' |
|
460 | + 'Value of unknown type in object cache ('. |
|
461 | + 'cache key: '.$cacheKey.', '. |
|
462 | + 'cache map key: '.$textHash.', '. |
|
463 | + 'value type: '.gettype($matches).')' |
|
465 | 464 | ); |
466 | 465 | } |
467 | 466 | } else { |
468 | 467 | $key = 'wikibase.quality.constraints.regex.cache.miss'; |
469 | - $this->dataFactory->increment( $key ); |
|
470 | - return $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
468 | + $this->dataFactory->increment($key); |
|
469 | + return $this->matchesRegularExpressionWithSparql($text, $regex); |
|
471 | 470 | } |
472 | 471 | } |
473 | 472 | |
474 | - private function serializeConstraintParameterException( ConstraintParameterException $cpe ) { |
|
473 | + private function serializeConstraintParameterException(ConstraintParameterException $cpe) { |
|
475 | 474 | return [ |
476 | 475 | 'type' => ConstraintParameterException::class, |
477 | - 'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ), |
|
476 | + 'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()), |
|
478 | 477 | ]; |
479 | 478 | } |
480 | 479 | |
481 | - private function deserializeConstraintParameterException( array $serialization ) { |
|
480 | + private function deserializeConstraintParameterException(array $serialization) { |
|
482 | 481 | $message = $this->violationMessageDeserializer->deserialize( |
483 | 482 | $serialization['violationMessage'] |
484 | 483 | ); |
485 | - return new ConstraintParameterException( $message ); |
|
484 | + return new ConstraintParameterException($message); |
|
486 | 485 | } |
487 | 486 | |
488 | 487 | /** |
@@ -496,25 +495,25 @@ discard block |
||
496 | 495 | * @throws SparqlHelperException if the query times out or some other error occurs |
497 | 496 | * @throws ConstraintParameterException if the $regex is invalid |
498 | 497 | */ |
499 | - public function matchesRegularExpressionWithSparql( $text, $regex ) { |
|
500 | - $textStringLiteral = $this->stringLiteral( $text ); |
|
501 | - $regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' ); |
|
498 | + public function matchesRegularExpressionWithSparql($text, $regex) { |
|
499 | + $textStringLiteral = $this->stringLiteral($text); |
|
500 | + $regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$'); |
|
502 | 501 | |
503 | 502 | $query = <<<EOF |
504 | 503 | SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {} |
505 | 504 | EOF; |
506 | 505 | |
507 | - $result = $this->runQuery( $query ); |
|
506 | + $result = $this->runQuery($query); |
|
508 | 507 | |
509 | 508 | $vars = $result->getArray()['results']['bindings'][0]; |
510 | - if ( array_key_exists( 'matches', $vars ) ) { |
|
509 | + if (array_key_exists('matches', $vars)) { |
|
511 | 510 | // true or false ⇒ regex okay, text matches or not |
512 | 511 | return $vars['matches']['value'] === 'true'; |
513 | 512 | } else { |
514 | 513 | // empty result: regex broken |
515 | 514 | throw new ConstraintParameterException( |
516 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
517 | - ->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
515 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
516 | + ->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE) |
|
518 | 517 | ); |
519 | 518 | } |
520 | 519 | } |
@@ -526,14 +525,14 @@ discard block |
||
526 | 525 | * |
527 | 526 | * @return boolean |
528 | 527 | */ |
529 | - public function isTimeout( $responseContent ) { |
|
530 | - $timeoutRegex = implode( '|', array_map( |
|
531 | - function ( $fqn ) { |
|
532 | - return preg_quote( $fqn, '/' ); |
|
528 | + public function isTimeout($responseContent) { |
|
529 | + $timeoutRegex = implode('|', array_map( |
|
530 | + function($fqn) { |
|
531 | + return preg_quote($fqn, '/'); |
|
533 | 532 | }, |
534 | - $this->config->get( 'WBQualityConstraintsSparqlTimeoutExceptionClasses' ) |
|
535 | - ) ); |
|
536 | - return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent ); |
|
533 | + $this->config->get('WBQualityConstraintsSparqlTimeoutExceptionClasses') |
|
534 | + )); |
|
535 | + return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent); |
|
537 | 536 | } |
538 | 537 | |
539 | 538 | /** |
@@ -545,17 +544,17 @@ discard block |
||
545 | 544 | * @return integer|boolean the max-age (in seconds) |
546 | 545 | * or a plain boolean if no max-age can be determined |
547 | 546 | */ |
548 | - public function getCacheMaxAge( $responseHeaders ) { |
|
547 | + public function getCacheMaxAge($responseHeaders) { |
|
549 | 548 | if ( |
550 | - array_key_exists( 'x-cache-status', $responseHeaders ) && |
|
551 | - preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] ) |
|
549 | + array_key_exists('x-cache-status', $responseHeaders) && |
|
550 | + preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0]) |
|
552 | 551 | ) { |
553 | 552 | $maxage = []; |
554 | 553 | if ( |
555 | - array_key_exists( 'cache-control', $responseHeaders ) && |
|
556 | - preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage ) |
|
554 | + array_key_exists('cache-control', $responseHeaders) && |
|
555 | + preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage) |
|
557 | 556 | ) { |
558 | - return intval( $maxage[1] ); |
|
557 | + return intval($maxage[1]); |
|
559 | 558 | } else { |
560 | 559 | return true; |
561 | 560 | } |
@@ -573,59 +572,58 @@ discard block |
||
573 | 572 | * |
574 | 573 | * @throws SparqlHelperException if the query times out or some other error occurs |
575 | 574 | */ |
576 | - public function runQuery( $query ) { |
|
577 | - $endpoint = $this->config->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
578 | - $maxQueryTimeMillis = $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' ); |
|
579 | - $url = $endpoint . '?' . http_build_query( |
|
575 | + public function runQuery($query) { |
|
576 | + $endpoint = $this->config->get('WBQualityConstraintsSparqlEndpoint'); |
|
577 | + $maxQueryTimeMillis = $this->config->get('WBQualityConstraintsSparqlMaxMillis'); |
|
578 | + $url = $endpoint.'?'.http_build_query( |
|
580 | 579 | [ |
581 | - 'query' => "#wbqc\n" . $this->prefixes . $query, |
|
580 | + 'query' => "#wbqc\n".$this->prefixes.$query, |
|
582 | 581 | 'format' => 'json', |
583 | 582 | 'maxQueryTimeMillis' => $maxQueryTimeMillis, |
584 | 583 | ], |
585 | - null, ini_get( 'arg_separator.output' ), |
|
584 | + null, ini_get('arg_separator.output'), |
|
586 | 585 | // encode spaces with %20, not + |
587 | 586 | PHP_QUERY_RFC3986 |
588 | 587 | ); |
589 | 588 | |
590 | 589 | $options = [ |
591 | 590 | 'method' => 'GET', |
592 | - 'timeout' => (int)round( ( $maxQueryTimeMillis + 1000 ) / 1000 ), |
|
591 | + 'timeout' => (int) round(($maxQueryTimeMillis + 1000) / 1000), |
|
593 | 592 | 'connectTimeout' => 'default', |
594 | 593 | 'userAgent' => $this->defaultUserAgent, |
595 | 594 | ]; |
596 | - $request = $this->requestFactory->create( $url, $options ); |
|
597 | - $startTime = microtime( true ); |
|
595 | + $request = $this->requestFactory->create($url, $options); |
|
596 | + $startTime = microtime(true); |
|
598 | 597 | $status = $request->execute(); |
599 | - $endTime = microtime( true ); |
|
598 | + $endTime = microtime(true); |
|
600 | 599 | $this->dataFactory->timing( |
601 | 600 | 'wikibase.quality.constraints.sparql.timing', |
602 | - ( $endTime - $startTime ) * 1000 |
|
601 | + ($endTime - $startTime) * 1000 |
|
603 | 602 | ); |
604 | 603 | |
605 | - $maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() ); |
|
606 | - if ( $maxAge ) { |
|
607 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' ); |
|
604 | + $maxAge = $this->getCacheMaxAge($request->getResponseHeaders()); |
|
605 | + if ($maxAge) { |
|
606 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.cached'); |
|
608 | 607 | } |
609 | 608 | |
610 | - if ( $status->isOK() ) { |
|
609 | + if ($status->isOK()) { |
|
611 | 610 | $json = $request->getContent(); |
612 | - $arr = json_decode( $json, true ); |
|
611 | + $arr = json_decode($json, true); |
|
613 | 612 | return new CachedQueryResults( |
614 | 613 | $arr, |
615 | 614 | Metadata::ofCachingMetadata( |
616 | 615 | $maxAge ? |
617 | - CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) : |
|
618 | - CachingMetadata::fresh() |
|
616 | + CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh() |
|
619 | 617 | ) |
620 | 618 | ); |
621 | 619 | } else { |
622 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' ); |
|
620 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.error'); |
|
623 | 621 | |
624 | 622 | $this->dataFactory->increment( |
625 | 623 | "wikibase.quality.constraints.sparql.error.http.{$request->getStatus()}" |
626 | 624 | ); |
627 | 625 | |
628 | - if ( $this->isTimeout( $request->getContent() ) ) { |
|
626 | + if ($this->isTimeout($request->getContent())) { |
|
629 | 627 | $this->dataFactory->increment( |
630 | 628 | 'wikibase.quality.constraints.sparql.error.timeout' |
631 | 629 | ); |