@@ -8,20 +8,20 @@ |
||
8 | 8 | use Wikibase\Repo\WikibaseRepo; |
9 | 9 | |
10 | 10 | return [ |
11 | - WikibaseServices::ENTITY_LOOKUP => static function ( MediaWikiServices $services ) { |
|
11 | + WikibaseServices::ENTITY_LOOKUP => static function(MediaWikiServices $services) { |
|
12 | 12 | return new ExceptionIgnoringEntityLookup( |
13 | - WikibaseRepo::getEntityLookup( $services ) |
|
13 | + WikibaseRepo::getEntityLookup($services) |
|
14 | 14 | ); |
15 | 15 | }, |
16 | 16 | |
17 | - WikibaseServices::ENTITY_LOOKUP_WITHOUT_CACHE => static function ( MediaWikiServices $services ) { |
|
17 | + WikibaseServices::ENTITY_LOOKUP_WITHOUT_CACHE => static function(MediaWikiServices $services) { |
|
18 | 18 | return new ExceptionIgnoringEntityLookup( |
19 | - WikibaseRepo::getStore( $services ) |
|
20 | - ->getEntityLookup( Store::LOOKUP_CACHING_RETRIEVE_ONLY ) |
|
19 | + WikibaseRepo::getStore($services) |
|
20 | + ->getEntityLookup(Store::LOOKUP_CACHING_RETRIEVE_ONLY) |
|
21 | 21 | ); |
22 | 22 | }, |
23 | 23 | |
24 | - WikibaseServices::PROPERTY_DATA_TYPE_LOOKUP => static function ( MediaWikiServices $services ) { |
|
25 | - return WikibaseRepo::getPropertyDataTypeLookup( $services ); |
|
24 | + WikibaseServices::PROPERTY_DATA_TYPE_LOOKUP => static function(MediaWikiServices $services) { |
|
25 | + return WikibaseRepo::getPropertyDataTypeLookup($services); |
|
26 | 26 | }, |
27 | 27 | ]; |
@@ -28,46 +28,46 @@ discard block |
||
28 | 28 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResultSerializer; |
29 | 29 | |
30 | 30 | return [ |
31 | - ConstraintsServices::EXPIRY_LOCK => static function ( MediaWikiServices $services ) { |
|
32 | - return new ExpiryLock( ObjectCache::getInstance( CACHE_ANYTHING ) ); |
|
31 | + ConstraintsServices::EXPIRY_LOCK => static function(MediaWikiServices $services) { |
|
32 | + return new ExpiryLock(ObjectCache::getInstance(CACHE_ANYTHING)); |
|
33 | 33 | }, |
34 | 34 | |
35 | - ConstraintsServices::LOGGING_HELPER => static function ( MediaWikiServices $services ) { |
|
35 | + ConstraintsServices::LOGGING_HELPER => static 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 => static function ( MediaWikiServices $services ) { |
|
44 | - $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
45 | - $propertySource = $sourceDefinitions->getSourceForEntityType( Property::ENTITY_TYPE ); |
|
43 | + ConstraintsServices::CONSTRAINT_STORE => static function(MediaWikiServices $services) { |
|
44 | + $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
45 | + $propertySource = $sourceDefinitions->getSourceForEntityType(Property::ENTITY_TYPE); |
|
46 | 46 | $dbName = $propertySource->getDatabaseName(); |
47 | - $localEntitySourceName = WikibaseRepo::getLocalEntitySource( $services )->getSourceName(); |
|
47 | + $localEntitySourceName = WikibaseRepo::getLocalEntitySource($services)->getSourceName(); |
|
48 | 48 | |
49 | - if ( $propertySource->getSourceName() !== $localEntitySourceName ) { |
|
50 | - throw new \RuntimeException( 'Can\'t get a ConstraintStore for a non local entity source.' ); |
|
49 | + if ($propertySource->getSourceName() !== $localEntitySourceName) { |
|
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 => static function ( MediaWikiServices $services ) { |
|
60 | - $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
61 | - $propertySource = $sourceDefinitions->getSourceForEntityType( Property::ENTITY_TYPE ); |
|
59 | + ConstraintsServices::CONSTRAINT_LOOKUP => static function(MediaWikiServices $services) { |
|
60 | + $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
61 | + $propertySource = $sourceDefinitions->getSourceForEntityType(Property::ENTITY_TYPE); |
|
62 | 62 | $dbName = $propertySource->getDatabaseName(); |
63 | 63 | $rawLookup = new ConstraintRepositoryLookup( |
64 | - $services->getDBLoadBalancerFactory()->getMainLB( $dbName ), |
|
64 | + $services->getDBLoadBalancerFactory()->getMainLB($dbName), |
|
65 | 65 | $dbName |
66 | 66 | ); |
67 | - return new CachingConstraintLookup( $rawLookup ); |
|
67 | + return new CachingConstraintLookup($rawLookup); |
|
68 | 68 | }, |
69 | 69 | |
70 | - ConstraintsServices::CHECK_RESULT_SERIALIZER => static function ( MediaWikiServices $services ) { |
|
70 | + ConstraintsServices::CHECK_RESULT_SERIALIZER => static function(MediaWikiServices $services) { |
|
71 | 71 | return new CheckResultSerializer( |
72 | 72 | new ConstraintSerializer( |
73 | 73 | false // constraint parameters are not exposed |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | ); |
79 | 79 | }, |
80 | 80 | |
81 | - ConstraintsServices::CHECK_RESULT_DESERIALIZER => static function ( MediaWikiServices $services ) { |
|
82 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
83 | - $dataValueFactory = WikibaseRepo::getDataValueFactory( $services ); |
|
81 | + ConstraintsServices::CHECK_RESULT_DESERIALIZER => static function(MediaWikiServices $services) { |
|
82 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
83 | + $dataValueFactory = WikibaseRepo::getDataValueFactory($services); |
|
84 | 84 | |
85 | 85 | return new CheckResultDeserializer( |
86 | 86 | new ConstraintDeserializer(), |
@@ -93,13 +93,13 @@ discard block |
||
93 | 93 | ); |
94 | 94 | }, |
95 | 95 | |
96 | - ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => static function ( MediaWikiServices $services ) { |
|
96 | + ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => static function(MediaWikiServices $services) { |
|
97 | 97 | return new ViolationMessageSerializer(); |
98 | 98 | }, |
99 | 99 | |
100 | - ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => static function ( MediaWikiServices $services ) { |
|
101 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
102 | - $dataValueFactory = WikibaseRepo::getDataValueFactory( $services ); |
|
100 | + ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => static function(MediaWikiServices $services) { |
|
101 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
102 | + $dataValueFactory = WikibaseRepo::getDataValueFactory($services); |
|
103 | 103 | |
104 | 104 | return new ViolationMessageDeserializer( |
105 | 105 | $entityIdParser, |
@@ -107,37 +107,37 @@ discard block |
||
107 | 107 | ); |
108 | 108 | }, |
109 | 109 | |
110 | - ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => static function ( MediaWikiServices $services ) { |
|
111 | - $deserializerFactory = WikibaseRepo::getBaseDataModelDeserializerFactory( $services ); |
|
112 | - $entitySourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
110 | + ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => static function(MediaWikiServices $services) { |
|
111 | + $deserializerFactory = WikibaseRepo::getBaseDataModelDeserializerFactory($services); |
|
112 | + $entitySourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
113 | 113 | |
114 | 114 | return new ConstraintParameterParser( |
115 | 115 | $services->getMainConfig(), |
116 | 116 | $deserializerFactory, |
117 | - $entitySourceDefinitions->getSourceForEntityType( 'item' )->getConceptBaseUri() |
|
117 | + $entitySourceDefinitions->getSourceForEntityType('item')->getConceptBaseUri() |
|
118 | 118 | ); |
119 | 119 | }, |
120 | 120 | |
121 | - ConstraintsServices::CONNECTION_CHECKER_HELPER => static function ( MediaWikiServices $services ) { |
|
121 | + ConstraintsServices::CONNECTION_CHECKER_HELPER => static function(MediaWikiServices $services) { |
|
122 | 122 | return new ConnectionCheckerHelper(); |
123 | 123 | }, |
124 | 124 | |
125 | - ConstraintsServices::RANGE_CHECKER_HELPER => static function ( MediaWikiServices $services ) { |
|
125 | + ConstraintsServices::RANGE_CHECKER_HELPER => static function(MediaWikiServices $services) { |
|
126 | 126 | return new RangeCheckerHelper( |
127 | 127 | $services->getMainConfig(), |
128 | - WikibaseRepo::getUnitConverter( $services ) |
|
128 | + WikibaseRepo::getUnitConverter($services) |
|
129 | 129 | ); |
130 | 130 | }, |
131 | 131 | |
132 | - ConstraintsServices::SPARQL_HELPER => static function ( MediaWikiServices $services ) { |
|
133 | - $endpoint = $services->getMainConfig()->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
134 | - if ( $endpoint === '' ) { |
|
132 | + ConstraintsServices::SPARQL_HELPER => static function(MediaWikiServices $services) { |
|
133 | + $endpoint = $services->getMainConfig()->get('WBQualityConstraintsSparqlEndpoint'); |
|
134 | + if ($endpoint === '') { |
|
135 | 135 | return new DummySparqlHelper(); |
136 | 136 | } |
137 | 137 | |
138 | - $rdfVocabulary = WikibaseRepo::getRdfVocabulary( $services ); |
|
139 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
140 | - $propertyDataTypeLookup = WikibaseRepo::getPropertyDataTypeLookup( $services ); |
|
138 | + $rdfVocabulary = WikibaseRepo::getRdfVocabulary($services); |
|
139 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
140 | + $propertyDataTypeLookup = WikibaseRepo::getPropertyDataTypeLookup($services); |
|
141 | 141 | |
142 | 142 | return new SparqlHelper( |
143 | 143 | $services->getMainConfig(), |
@@ -145,124 +145,124 @@ discard block |
||
145 | 145 | $entityIdParser, |
146 | 146 | $propertyDataTypeLookup, |
147 | 147 | $services->getMainWANObjectCache(), |
148 | - ConstraintsServices::getViolationMessageSerializer( $services ), |
|
149 | - ConstraintsServices::getViolationMessageDeserializer( $services ), |
|
148 | + ConstraintsServices::getViolationMessageSerializer($services), |
|
149 | + ConstraintsServices::getViolationMessageDeserializer($services), |
|
150 | 150 | $services->getStatsdDataFactory(), |
151 | - ConstraintsServices::getExpiryLock( $services ), |
|
152 | - ConstraintsServices::getLoggingHelper( $services ), |
|
153 | - wfWikiID() . ' WikibaseQualityConstraints ' . Http::userAgent(), |
|
151 | + ConstraintsServices::getExpiryLock($services), |
|
152 | + ConstraintsServices::getLoggingHelper($services), |
|
153 | + wfWikiID().' WikibaseQualityConstraints '.Http::userAgent(), |
|
154 | 154 | $services->getHttpRequestFactory() |
155 | 155 | ); |
156 | 156 | }, |
157 | 157 | |
158 | - ConstraintsServices::TYPE_CHECKER_HELPER => static function ( MediaWikiServices $services ) { |
|
158 | + ConstraintsServices::TYPE_CHECKER_HELPER => static function(MediaWikiServices $services) { |
|
159 | 159 | return new TypeCheckerHelper( |
160 | - WikibaseServices::getEntityLookup( $services ), |
|
160 | + WikibaseServices::getEntityLookup($services), |
|
161 | 161 | $services->getMainConfig(), |
162 | - ConstraintsServices::getSparqlHelper( $services ), |
|
162 | + ConstraintsServices::getSparqlHelper($services), |
|
163 | 163 | $services->getStatsdDataFactory() |
164 | 164 | ); |
165 | 165 | }, |
166 | 166 | |
167 | - ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => static function ( MediaWikiServices $services ) { |
|
168 | - $statementGuidParser = WikibaseRepo::getStatementGuidParser( $services ); |
|
167 | + ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => static function(MediaWikiServices $services) { |
|
168 | + $statementGuidParser = WikibaseRepo::getStatementGuidParser($services); |
|
169 | 169 | |
170 | 170 | $config = $services->getMainConfig(); |
171 | 171 | $checkerMap = [ |
172 | - $config->get( 'WBQualityConstraintsConflictsWithConstraintId' ) |
|
173 | - => ConstraintCheckerServices::getConflictsWithChecker( $services ), |
|
174 | - $config->get( 'WBQualityConstraintsItemRequiresClaimConstraintId' ) |
|
175 | - => ConstraintCheckerServices::getItemChecker( $services ), |
|
176 | - $config->get( 'WBQualityConstraintsValueRequiresClaimConstraintId' ) |
|
177 | - => ConstraintCheckerServices::getTargetRequiredClaimChecker( $services ), |
|
178 | - $config->get( 'WBQualityConstraintsSymmetricConstraintId' ) |
|
179 | - => ConstraintCheckerServices::getSymmetricChecker( $services ), |
|
180 | - $config->get( 'WBQualityConstraintsInverseConstraintId' ) |
|
181 | - => ConstraintCheckerServices::getInverseChecker( $services ), |
|
182 | - $config->get( 'WBQualityConstraintsUsedAsQualifierConstraintId' ) |
|
183 | - => ConstraintCheckerServices::getQualifierChecker( $services ), |
|
184 | - $config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' ) |
|
185 | - => ConstraintCheckerServices::getQualifiersChecker( $services ), |
|
186 | - $config->get( 'WBQualityConstraintsMandatoryQualifierConstraintId' ) |
|
187 | - => ConstraintCheckerServices::getMandatoryQualifiersChecker( $services ), |
|
188 | - $config->get( 'WBQualityConstraintsRangeConstraintId' ) |
|
189 | - => ConstraintCheckerServices::getRangeChecker( $services ), |
|
190 | - $config->get( 'WBQualityConstraintsDifferenceWithinRangeConstraintId' ) |
|
191 | - => ConstraintCheckerServices::getDiffWithinRangeChecker( $services ), |
|
192 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ) |
|
193 | - => ConstraintCheckerServices::getTypeChecker( $services ), |
|
194 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ) |
|
195 | - => ConstraintCheckerServices::getValueTypeChecker( $services ), |
|
196 | - $config->get( 'WBQualityConstraintsSingleValueConstraintId' ) |
|
197 | - => ConstraintCheckerServices::getSingleValueChecker( $services ), |
|
198 | - $config->get( 'WBQualityConstraintsMultiValueConstraintId' ) |
|
199 | - => ConstraintCheckerServices::getMultiValueChecker( $services ), |
|
200 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ) |
|
201 | - => ConstraintCheckerServices::getUniqueValueChecker( $services ), |
|
202 | - $config->get( 'WBQualityConstraintsFormatConstraintId' ) |
|
203 | - => ConstraintCheckerServices::getFormatChecker( $services ), |
|
204 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ) |
|
205 | - => ConstraintCheckerServices::getCommonsLinkChecker( $services ), |
|
206 | - $config->get( 'WBQualityConstraintsOneOfConstraintId' ) |
|
207 | - => ConstraintCheckerServices::getOneOfChecker( $services ), |
|
208 | - $config->get( 'WBQualityConstraintsUsedForValuesOnlyConstraintId' ) |
|
209 | - => ConstraintCheckerServices::getValueOnlyChecker( $services ), |
|
210 | - $config->get( 'WBQualityConstraintsUsedAsReferenceConstraintId' ) |
|
211 | - => ConstraintCheckerServices::getReferenceChecker( $services ), |
|
212 | - $config->get( 'WBQualityConstraintsNoBoundsConstraintId' ) |
|
213 | - => ConstraintCheckerServices::getNoBoundsChecker( $services ), |
|
214 | - $config->get( 'WBQualityConstraintsAllowedUnitsConstraintId' ) |
|
215 | - => ConstraintCheckerServices::getAllowedUnitsChecker( $services ), |
|
216 | - $config->get( 'WBQualityConstraintsSingleBestValueConstraintId' ) |
|
217 | - => ConstraintCheckerServices::getSingleBestValueChecker( $services ), |
|
218 | - $config->get( 'WBQualityConstraintsAllowedEntityTypesConstraintId' ) |
|
219 | - => ConstraintCheckerServices::getEntityTypeChecker( $services ), |
|
220 | - $config->get( 'WBQualityConstraintsNoneOfConstraintId' ) |
|
221 | - => ConstraintCheckerServices::getNoneOfChecker( $services ), |
|
222 | - $config->get( 'WBQualityConstraintsIntegerConstraintId' ) |
|
223 | - => ConstraintCheckerServices::getIntegerChecker( $services ), |
|
224 | - $config->get( 'WBQualityConstraintsCitationNeededConstraintId' ) |
|
225 | - => ConstraintCheckerServices::getCitationNeededChecker( $services ), |
|
226 | - $config->get( 'WBQualityConstraintsPropertyScopeConstraintId' ) |
|
227 | - => ConstraintCheckerServices::getPropertyScopeChecker( $services ), |
|
228 | - $config->get( 'WBQualityConstraintsContemporaryConstraintId' ) |
|
229 | - => ConstraintCheckerServices::getContemporaryChecker( $services ), |
|
230 | - $config->get( 'WBQualityConstraintsLexemeLanguageConstraintId' ) |
|
231 | - => ConstraintCheckerServices::getLexemeLanguageChecker( $services ), |
|
172 | + $config->get('WBQualityConstraintsConflictsWithConstraintId') |
|
173 | + => ConstraintCheckerServices::getConflictsWithChecker($services), |
|
174 | + $config->get('WBQualityConstraintsItemRequiresClaimConstraintId') |
|
175 | + => ConstraintCheckerServices::getItemChecker($services), |
|
176 | + $config->get('WBQualityConstraintsValueRequiresClaimConstraintId') |
|
177 | + => ConstraintCheckerServices::getTargetRequiredClaimChecker($services), |
|
178 | + $config->get('WBQualityConstraintsSymmetricConstraintId') |
|
179 | + => ConstraintCheckerServices::getSymmetricChecker($services), |
|
180 | + $config->get('WBQualityConstraintsInverseConstraintId') |
|
181 | + => ConstraintCheckerServices::getInverseChecker($services), |
|
182 | + $config->get('WBQualityConstraintsUsedAsQualifierConstraintId') |
|
183 | + => ConstraintCheckerServices::getQualifierChecker($services), |
|
184 | + $config->get('WBQualityConstraintsAllowedQualifiersConstraintId') |
|
185 | + => ConstraintCheckerServices::getQualifiersChecker($services), |
|
186 | + $config->get('WBQualityConstraintsMandatoryQualifierConstraintId') |
|
187 | + => ConstraintCheckerServices::getMandatoryQualifiersChecker($services), |
|
188 | + $config->get('WBQualityConstraintsRangeConstraintId') |
|
189 | + => ConstraintCheckerServices::getRangeChecker($services), |
|
190 | + $config->get('WBQualityConstraintsDifferenceWithinRangeConstraintId') |
|
191 | + => ConstraintCheckerServices::getDiffWithinRangeChecker($services), |
|
192 | + $config->get('WBQualityConstraintsTypeConstraintId') |
|
193 | + => ConstraintCheckerServices::getTypeChecker($services), |
|
194 | + $config->get('WBQualityConstraintsValueTypeConstraintId') |
|
195 | + => ConstraintCheckerServices::getValueTypeChecker($services), |
|
196 | + $config->get('WBQualityConstraintsSingleValueConstraintId') |
|
197 | + => ConstraintCheckerServices::getSingleValueChecker($services), |
|
198 | + $config->get('WBQualityConstraintsMultiValueConstraintId') |
|
199 | + => ConstraintCheckerServices::getMultiValueChecker($services), |
|
200 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId') |
|
201 | + => ConstraintCheckerServices::getUniqueValueChecker($services), |
|
202 | + $config->get('WBQualityConstraintsFormatConstraintId') |
|
203 | + => ConstraintCheckerServices::getFormatChecker($services), |
|
204 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId') |
|
205 | + => ConstraintCheckerServices::getCommonsLinkChecker($services), |
|
206 | + $config->get('WBQualityConstraintsOneOfConstraintId') |
|
207 | + => ConstraintCheckerServices::getOneOfChecker($services), |
|
208 | + $config->get('WBQualityConstraintsUsedForValuesOnlyConstraintId') |
|
209 | + => ConstraintCheckerServices::getValueOnlyChecker($services), |
|
210 | + $config->get('WBQualityConstraintsUsedAsReferenceConstraintId') |
|
211 | + => ConstraintCheckerServices::getReferenceChecker($services), |
|
212 | + $config->get('WBQualityConstraintsNoBoundsConstraintId') |
|
213 | + => ConstraintCheckerServices::getNoBoundsChecker($services), |
|
214 | + $config->get('WBQualityConstraintsAllowedUnitsConstraintId') |
|
215 | + => ConstraintCheckerServices::getAllowedUnitsChecker($services), |
|
216 | + $config->get('WBQualityConstraintsSingleBestValueConstraintId') |
|
217 | + => ConstraintCheckerServices::getSingleBestValueChecker($services), |
|
218 | + $config->get('WBQualityConstraintsAllowedEntityTypesConstraintId') |
|
219 | + => ConstraintCheckerServices::getEntityTypeChecker($services), |
|
220 | + $config->get('WBQualityConstraintsNoneOfConstraintId') |
|
221 | + => ConstraintCheckerServices::getNoneOfChecker($services), |
|
222 | + $config->get('WBQualityConstraintsIntegerConstraintId') |
|
223 | + => ConstraintCheckerServices::getIntegerChecker($services), |
|
224 | + $config->get('WBQualityConstraintsCitationNeededConstraintId') |
|
225 | + => ConstraintCheckerServices::getCitationNeededChecker($services), |
|
226 | + $config->get('WBQualityConstraintsPropertyScopeConstraintId') |
|
227 | + => ConstraintCheckerServices::getPropertyScopeChecker($services), |
|
228 | + $config->get('WBQualityConstraintsContemporaryConstraintId') |
|
229 | + => ConstraintCheckerServices::getContemporaryChecker($services), |
|
230 | + $config->get('WBQualityConstraintsLexemeLanguageConstraintId') |
|
231 | + => ConstraintCheckerServices::getLexemeLanguageChecker($services), |
|
232 | 232 | ]; |
233 | 233 | |
234 | 234 | return new DelegatingConstraintChecker( |
235 | - WikibaseServices::getEntityLookup( $services ), |
|
235 | + WikibaseServices::getEntityLookup($services), |
|
236 | 236 | $checkerMap, |
237 | - ConstraintsServices::getConstraintLookup( $services ), |
|
238 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
237 | + ConstraintsServices::getConstraintLookup($services), |
|
238 | + ConstraintsServices::getConstraintParameterParser($services), |
|
239 | 239 | $statementGuidParser, |
240 | - ConstraintsServices::getLoggingHelper( $services ), |
|
241 | - $config->get( 'WBQualityConstraintsCheckQualifiers' ), |
|
242 | - $config->get( 'WBQualityConstraintsCheckReferences' ), |
|
243 | - $config->get( 'WBQualityConstraintsPropertiesWithViolatingQualifiers' ) |
|
240 | + ConstraintsServices::getLoggingHelper($services), |
|
241 | + $config->get('WBQualityConstraintsCheckQualifiers'), |
|
242 | + $config->get('WBQualityConstraintsCheckReferences'), |
|
243 | + $config->get('WBQualityConstraintsPropertiesWithViolatingQualifiers') |
|
244 | 244 | ); |
245 | 245 | }, |
246 | 246 | |
247 | - ConstraintsServices::RESULTS_SOURCE => static function ( MediaWikiServices $services ) { |
|
247 | + ConstraintsServices::RESULTS_SOURCE => static function(MediaWikiServices $services) { |
|
248 | 248 | $config = $services->getMainConfig(); |
249 | 249 | $resultsSource = new CheckingResultsSource( |
250 | - ConstraintsServices::getDelegatingConstraintChecker( $services ) |
|
250 | + ConstraintsServices::getDelegatingConstraintChecker($services) |
|
251 | 251 | ); |
252 | 252 | |
253 | 253 | $cacheCheckConstraintsResults = false; |
254 | 254 | |
255 | - if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) { |
|
255 | + if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) { |
|
256 | 256 | $cacheCheckConstraintsResults = true; |
257 | 257 | // check that we can use getLocalRepoWikiPageMetaDataAccessor() |
258 | 258 | // TODO we should always be able to cache constraint check results (T244726) |
259 | - $entitySources = WikibaseRepo::getEntitySourceDefinitions( $services )->getSources(); |
|
260 | - $localEntitySourceName = WikibaseRepo::getLocalEntitySource( $services )->getSourceName(); |
|
259 | + $entitySources = WikibaseRepo::getEntitySourceDefinitions($services)->getSources(); |
|
260 | + $localEntitySourceName = WikibaseRepo::getLocalEntitySource($services)->getSourceName(); |
|
261 | 261 | |
262 | - foreach ( $entitySources as $entitySource ) { |
|
263 | - if ( $entitySource->getSourceName() !== $localEntitySourceName ) { |
|
264 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' )->warning( |
|
265 | - 'Cannot cache constraint check results for non-local source: ' . |
|
262 | + foreach ($entitySources as $entitySource) { |
|
263 | + if ($entitySource->getSourceName() !== $localEntitySourceName) { |
|
264 | + LoggerFactory::getInstance('WikibaseQualityConstraints')->warning( |
|
265 | + 'Cannot cache constraint check results for non-local source: '. |
|
266 | 266 | $entitySource->getSourceName() |
267 | 267 | ); |
268 | 268 | $cacheCheckConstraintsResults = false; |
@@ -271,28 +271,28 @@ discard block |
||
271 | 271 | } |
272 | 272 | } |
273 | 273 | |
274 | - if ( $cacheCheckConstraintsResults ) { |
|
274 | + if ($cacheCheckConstraintsResults) { |
|
275 | 275 | $possiblyStaleConstraintTypes = [ |
276 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ), |
|
277 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ), |
|
278 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ), |
|
279 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ), |
|
276 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId'), |
|
277 | + $config->get('WBQualityConstraintsTypeConstraintId'), |
|
278 | + $config->get('WBQualityConstraintsValueTypeConstraintId'), |
|
279 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId'), |
|
280 | 280 | ]; |
281 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
281 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
282 | 282 | $wikiPageEntityMetaDataAccessor = WikibaseRepo::getLocalRepoWikiPageMetaDataAccessor( |
283 | 283 | $services ); |
284 | 284 | |
285 | 285 | $resultsSource = new CachingResultsSource( |
286 | 286 | $resultsSource, |
287 | 287 | ResultsCache::getDefaultInstance(), |
288 | - ConstraintsServices::getCheckResultSerializer( $services ), |
|
289 | - ConstraintsServices::getCheckResultDeserializer( $services ), |
|
288 | + ConstraintsServices::getCheckResultSerializer($services), |
|
289 | + ConstraintsServices::getCheckResultDeserializer($services), |
|
290 | 290 | $wikiPageEntityMetaDataAccessor, |
291 | 291 | $entityIdParser, |
292 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ), |
|
292 | + $config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'), |
|
293 | 293 | $possiblyStaleConstraintTypes, |
294 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds' ), |
|
295 | - ConstraintsServices::getLoggingHelper( $services ) |
|
294 | + $config->get('WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds'), |
|
295 | + ConstraintsServices::getLoggingHelper($services) |
|
296 | 296 | ); |
297 | 297 | } |
298 | 298 |
@@ -42,251 +42,251 @@ |
||
42 | 42 | public const CONTEMPORARY_CHECKER = 'WBQC_ContemporaryChecker'; |
43 | 43 | public const LEXEME_LANGUAGE_CHECKER = 'WBQC_Lexeme_LanguageChecker'; |
44 | 44 | |
45 | - private static function getService( ?MediaWikiServices $services, $name ) { |
|
46 | - if ( $services === null ) { |
|
45 | + private static function getService(?MediaWikiServices $services, $name) { |
|
46 | + if ($services === null) { |
|
47 | 47 | $services = MediaWikiServices::getInstance(); |
48 | 48 | } |
49 | - return $services->getService( $name ); |
|
49 | + return $services->getService($name); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | 53 | * @param MediaWikiServices|null $services |
54 | 54 | * @return ConstraintChecker |
55 | 55 | */ |
56 | - public static function getConflictsWithChecker( MediaWikiServices $services = null ) { |
|
57 | - return self::getService( $services, self::CONFLICTS_WITH_CHECKER ); |
|
56 | + public static function getConflictsWithChecker(MediaWikiServices $services = null) { |
|
57 | + return self::getService($services, self::CONFLICTS_WITH_CHECKER); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
61 | 61 | * @param MediaWikiServices|null $services |
62 | 62 | * @return ConstraintChecker |
63 | 63 | */ |
64 | - public static function getItemChecker( MediaWikiServices $services = null ) { |
|
65 | - return self::getService( $services, self::ITEM_CHECKER ); |
|
64 | + public static function getItemChecker(MediaWikiServices $services = null) { |
|
65 | + return self::getService($services, self::ITEM_CHECKER); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * @param MediaWikiServices|null $services |
70 | 70 | * @return ConstraintChecker |
71 | 71 | */ |
72 | - public static function getTargetRequiredClaimChecker( MediaWikiServices $services = null ) { |
|
73 | - return self::getService( $services, self::TARGET_REQUIRED_CLAIM_CHECKER ); |
|
72 | + public static function getTargetRequiredClaimChecker(MediaWikiServices $services = null) { |
|
73 | + return self::getService($services, self::TARGET_REQUIRED_CLAIM_CHECKER); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
77 | 77 | * @param MediaWikiServices|null $services |
78 | 78 | * @return ConstraintChecker |
79 | 79 | */ |
80 | - public static function getSymmetricChecker( MediaWikiServices $services = null ) { |
|
81 | - return self::getService( $services, self::SYMMETRIC_CHECKER ); |
|
80 | + public static function getSymmetricChecker(MediaWikiServices $services = null) { |
|
81 | + return self::getService($services, self::SYMMETRIC_CHECKER); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | 85 | * @param MediaWikiServices|null $services |
86 | 86 | * @return ConstraintChecker |
87 | 87 | */ |
88 | - public static function getInverseChecker( MediaWikiServices $services = null ) { |
|
89 | - return self::getService( $services, self::INVERSE_CHECKER ); |
|
88 | + public static function getInverseChecker(MediaWikiServices $services = null) { |
|
89 | + return self::getService($services, self::INVERSE_CHECKER); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
93 | 93 | * @param MediaWikiServices|null $services |
94 | 94 | * @return ConstraintChecker |
95 | 95 | */ |
96 | - public static function getQualifierChecker( MediaWikiServices $services = null ) { |
|
97 | - return self::getService( $services, self::QUALIFIER_CHECKER ); |
|
96 | + public static function getQualifierChecker(MediaWikiServices $services = null) { |
|
97 | + return self::getService($services, self::QUALIFIER_CHECKER); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * @param MediaWikiServices|null $services |
102 | 102 | * @return ConstraintChecker |
103 | 103 | */ |
104 | - public static function getQualifiersChecker( MediaWikiServices $services = null ) { |
|
105 | - return self::getService( $services, self::QUALIFIERS_CHECKER ); |
|
104 | + public static function getQualifiersChecker(MediaWikiServices $services = null) { |
|
105 | + return self::getService($services, self::QUALIFIERS_CHECKER); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
109 | 109 | * @param MediaWikiServices|null $services |
110 | 110 | * @return ConstraintChecker |
111 | 111 | */ |
112 | - public static function getMandatoryQualifiersChecker( MediaWikiServices $services = null ) { |
|
113 | - return self::getService( $services, self::MANDATORY_QUALIFIERS_CHECKER ); |
|
112 | + public static function getMandatoryQualifiersChecker(MediaWikiServices $services = null) { |
|
113 | + return self::getService($services, self::MANDATORY_QUALIFIERS_CHECKER); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
117 | 117 | * @param MediaWikiServices|null $services |
118 | 118 | * @return ConstraintChecker |
119 | 119 | */ |
120 | - public static function getRangeChecker( MediaWikiServices $services = null ) { |
|
121 | - return self::getService( $services, self::RANGE_CHECKER ); |
|
120 | + public static function getRangeChecker(MediaWikiServices $services = null) { |
|
121 | + return self::getService($services, self::RANGE_CHECKER); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
125 | 125 | * @param MediaWikiServices|null $services |
126 | 126 | * @return ConstraintChecker |
127 | 127 | */ |
128 | - public static function getDiffWithinRangeChecker( MediaWikiServices $services = null ) { |
|
129 | - return self::getService( $services, self::DIFF_WITHIN_RANGE_CHECKER ); |
|
128 | + public static function getDiffWithinRangeChecker(MediaWikiServices $services = null) { |
|
129 | + return self::getService($services, self::DIFF_WITHIN_RANGE_CHECKER); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
133 | 133 | * @param MediaWikiServices|null $services |
134 | 134 | * @return ConstraintChecker |
135 | 135 | */ |
136 | - public static function getTypeChecker( MediaWikiServices $services = null ) { |
|
137 | - return self::getService( $services, self::TYPE_CHECKER ); |
|
136 | + public static function getTypeChecker(MediaWikiServices $services = null) { |
|
137 | + return self::getService($services, self::TYPE_CHECKER); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
141 | 141 | * @param MediaWikiServices|null $services |
142 | 142 | * @return ConstraintChecker |
143 | 143 | */ |
144 | - public static function getValueTypeChecker( MediaWikiServices $services = null ) { |
|
145 | - return self::getService( $services, self::VALUE_TYPE_CHECKER ); |
|
144 | + public static function getValueTypeChecker(MediaWikiServices $services = null) { |
|
145 | + return self::getService($services, self::VALUE_TYPE_CHECKER); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
149 | 149 | * @param MediaWikiServices|null $services |
150 | 150 | * @return ConstraintChecker |
151 | 151 | */ |
152 | - public static function getSingleValueChecker( MediaWikiServices $services = null ) { |
|
153 | - return self::getService( $services, self::SINGLE_VALUE_CHECKER ); |
|
152 | + public static function getSingleValueChecker(MediaWikiServices $services = null) { |
|
153 | + return self::getService($services, self::SINGLE_VALUE_CHECKER); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
157 | 157 | * @param MediaWikiServices|null $services |
158 | 158 | * @return ConstraintChecker |
159 | 159 | */ |
160 | - public static function getMultiValueChecker( MediaWikiServices $services = null ) { |
|
161 | - return self::getService( $services, self::MULTI_VALUE_CHECKER ); |
|
160 | + public static function getMultiValueChecker(MediaWikiServices $services = null) { |
|
161 | + return self::getService($services, self::MULTI_VALUE_CHECKER); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
165 | 165 | * @param MediaWikiServices|null $services |
166 | 166 | * @return ConstraintChecker |
167 | 167 | */ |
168 | - public static function getUniqueValueChecker( MediaWikiServices $services = null ) { |
|
169 | - return self::getService( $services, self::UNIQUE_VALUE_CHECKER ); |
|
168 | + public static function getUniqueValueChecker(MediaWikiServices $services = null) { |
|
169 | + return self::getService($services, self::UNIQUE_VALUE_CHECKER); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
173 | 173 | * @param MediaWikiServices|null $services |
174 | 174 | * @return ConstraintChecker |
175 | 175 | */ |
176 | - public static function getFormatChecker( MediaWikiServices $services = null ) { |
|
177 | - return self::getService( $services, self::FORMAT_CHECKER ); |
|
176 | + public static function getFormatChecker(MediaWikiServices $services = null) { |
|
177 | + return self::getService($services, self::FORMAT_CHECKER); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
181 | 181 | * @param MediaWikiServices|null $services |
182 | 182 | * @return ConstraintChecker |
183 | 183 | */ |
184 | - public static function getCommonsLinkChecker( MediaWikiServices $services = null ) { |
|
185 | - return self::getService( $services, self::COMMONS_LINK_CHECKER ); |
|
184 | + public static function getCommonsLinkChecker(MediaWikiServices $services = null) { |
|
185 | + return self::getService($services, self::COMMONS_LINK_CHECKER); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
189 | 189 | * @param MediaWikiServices|null $services |
190 | 190 | * @return ConstraintChecker |
191 | 191 | */ |
192 | - public static function getOneOfChecker( MediaWikiServices $services = null ) { |
|
193 | - return self::getService( $services, self::ONE_OF_CHECKER ); |
|
192 | + public static function getOneOfChecker(MediaWikiServices $services = null) { |
|
193 | + return self::getService($services, self::ONE_OF_CHECKER); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
197 | 197 | * @param MediaWikiServices|null $services |
198 | 198 | * @return ConstraintChecker |
199 | 199 | */ |
200 | - public static function getValueOnlyChecker( MediaWikiServices $services = null ) { |
|
201 | - return self::getService( $services, self::VALUE_ONLY_CHECKER ); |
|
200 | + public static function getValueOnlyChecker(MediaWikiServices $services = null) { |
|
201 | + return self::getService($services, self::VALUE_ONLY_CHECKER); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
205 | 205 | * @param MediaWikiServices|null $services |
206 | 206 | * @return ConstraintChecker |
207 | 207 | */ |
208 | - public static function getReferenceChecker( MediaWikiServices $services = null ) { |
|
209 | - return self::getService( $services, self::REFERENCE_CHECKER ); |
|
208 | + public static function getReferenceChecker(MediaWikiServices $services = null) { |
|
209 | + return self::getService($services, self::REFERENCE_CHECKER); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
213 | 213 | * @param MediaWikiServices|null $services |
214 | 214 | * @return ConstraintChecker |
215 | 215 | */ |
216 | - public static function getNoBoundsChecker( MediaWikiServices $services = null ) { |
|
217 | - return self::getService( $services, self::NO_BOUNDS_CHECKER ); |
|
216 | + public static function getNoBoundsChecker(MediaWikiServices $services = null) { |
|
217 | + return self::getService($services, self::NO_BOUNDS_CHECKER); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
221 | 221 | * @param MediaWikiServices|null $services |
222 | 222 | * @return ConstraintChecker |
223 | 223 | */ |
224 | - public static function getAllowedUnitsChecker( MediaWikiServices $services = null ) { |
|
225 | - return self::getService( $services, self::ALLOWED_UNITS_CHECKER ); |
|
224 | + public static function getAllowedUnitsChecker(MediaWikiServices $services = null) { |
|
225 | + return self::getService($services, self::ALLOWED_UNITS_CHECKER); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
229 | 229 | * @param MediaWikiServices|null $services |
230 | 230 | * @return ConstraintChecker |
231 | 231 | */ |
232 | - public static function getSingleBestValueChecker( MediaWikiServices $services = null ) { |
|
233 | - return self::getService( $services, self::SINGLE_BEST_VALUE_CHECKER ); |
|
232 | + public static function getSingleBestValueChecker(MediaWikiServices $services = null) { |
|
233 | + return self::getService($services, self::SINGLE_BEST_VALUE_CHECKER); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
237 | 237 | * @param MediaWikiServices|null $services |
238 | 238 | * @return ConstraintChecker |
239 | 239 | */ |
240 | - public static function getEntityTypeChecker( MediaWikiServices $services = null ) { |
|
241 | - return self::getService( $services, self::ENTITY_TYPE_CHECKER ); |
|
240 | + public static function getEntityTypeChecker(MediaWikiServices $services = null) { |
|
241 | + return self::getService($services, self::ENTITY_TYPE_CHECKER); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
245 | 245 | * @param MediaWikiServices|null $services |
246 | 246 | * @return ConstraintChecker |
247 | 247 | */ |
248 | - public static function getNoneOfChecker( MediaWikiServices $services = null ) { |
|
249 | - return self::getService( $services, self::NONE_OF_CHECKER ); |
|
248 | + public static function getNoneOfChecker(MediaWikiServices $services = null) { |
|
249 | + return self::getService($services, self::NONE_OF_CHECKER); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
253 | 253 | * @param MediaWikiServices|null $services |
254 | 254 | * @return ConstraintChecker |
255 | 255 | */ |
256 | - public static function getIntegerChecker( MediaWikiServices $services = null ) { |
|
257 | - return self::getService( $services, self::INTEGER_CHECKER ); |
|
256 | + public static function getIntegerChecker(MediaWikiServices $services = null) { |
|
257 | + return self::getService($services, self::INTEGER_CHECKER); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
261 | 261 | * @param MediaWikiServices|null $services |
262 | 262 | * @return ConstraintChecker |
263 | 263 | */ |
264 | - public static function getCitationNeededChecker( MediaWikiServices $services = null ) { |
|
265 | - return self::getService( $services, self::CITATION_NEEDED_CHECKER ); |
|
264 | + public static function getCitationNeededChecker(MediaWikiServices $services = null) { |
|
265 | + return self::getService($services, self::CITATION_NEEDED_CHECKER); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
269 | 269 | * @param MediaWikiServices|null $services |
270 | 270 | * @return ConstraintChecker |
271 | 271 | */ |
272 | - public static function getPropertyScopeChecker( MediaWikiServices $services = null ) { |
|
273 | - return self::getService( $services, self::PROPERTY_SCOPE_CHECKER ); |
|
272 | + public static function getPropertyScopeChecker(MediaWikiServices $services = null) { |
|
273 | + return self::getService($services, self::PROPERTY_SCOPE_CHECKER); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
277 | 277 | * @param MediaWikiServices|null $services |
278 | 278 | * @return ConstraintChecker |
279 | 279 | */ |
280 | - public static function getContemporaryChecker( MediaWikiServices $services = null ) { |
|
281 | - return self::getService( $services, self::CONTEMPORARY_CHECKER ); |
|
280 | + public static function getContemporaryChecker(MediaWikiServices $services = null) { |
|
281 | + return self::getService($services, self::CONTEMPORARY_CHECKER); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
285 | 285 | * @param MediaWikiServices|null $services |
286 | 286 | * @return LanguageChecker |
287 | 287 | */ |
288 | - public static function getLexemeLanguageChecker( MediaWikiServices $services = null ) { |
|
289 | - return self::getService( $services, self::LEXEME_LANGUAGE_CHECKER ); |
|
288 | + public static function getLexemeLanguageChecker(MediaWikiServices $services = null) { |
|
289 | + return self::getService($services, self::LEXEME_LANGUAGE_CHECKER); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | } |
@@ -73,16 +73,16 @@ discard block |
||
73 | 73 | * @throws ConstraintParameterException |
74 | 74 | * @return CheckResult |
75 | 75 | */ |
76 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
77 | - if ( !ExtensionRegistry::getInstance()->isLoaded( 'WikibaseLexeme' ) ) { |
|
78 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE ); |
|
76 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
77 | + if (!ExtensionRegistry::getInstance()->isLoaded('WikibaseLexeme')) { |
|
78 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE); |
|
79 | 79 | } |
80 | 80 | $entityType = $context->getEntity()->getType(); |
81 | - if ( !in_array( $entityType, [ Lexeme::ENTITY_TYPE, Sense::ENTITY_TYPE, Form::ENTITY_TYPE ] ) ) { |
|
82 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE ); |
|
81 | + if (!in_array($entityType, [Lexeme::ENTITY_TYPE, Sense::ENTITY_TYPE, Form::ENTITY_TYPE])) { |
|
82 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE); |
|
83 | 83 | } |
84 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
85 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
84 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
85 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | $parameters = []; |
@@ -96,50 +96,50 @@ discard block |
||
96 | 96 | ); |
97 | 97 | $parameters['languages'] = $languages; |
98 | 98 | |
99 | - $message = ( new ViolationMessage( 'wbqc-violation-message-language' ) ) |
|
100 | - ->withEntityId( $context->getSnak()->getPropertyId(), Role::PREDICATE ) |
|
101 | - ->withItemIdSnakValueList( $languages, Role::OBJECT ); |
|
99 | + $message = (new ViolationMessage('wbqc-violation-message-language')) |
|
100 | + ->withEntityId($context->getSnak()->getPropertyId(), Role::PREDICATE) |
|
101 | + ->withItemIdSnakValueList($languages, Role::OBJECT); |
|
102 | 102 | $status = CheckResult::STATUS_VIOLATION; |
103 | 103 | |
104 | - $lexeme = $this->getLexeme( $context ); |
|
105 | - if ( !$lexeme ) { |
|
104 | + $lexeme = $this->getLexeme($context); |
|
105 | + if (!$lexeme) { |
|
106 | 106 | // Lexeme doesn't exist, let's not bother |
107 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE ); |
|
107 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_NOT_IN_SCOPE); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** @var Lexeme $lexeme */ |
111 | 111 | '@phan-var Lexeme $lexeme'; |
112 | 112 | |
113 | - foreach ( $languages as $language ) { |
|
114 | - if ( $language->isNoValue() || $language->isSomeValue() ) { |
|
113 | + foreach ($languages as $language) { |
|
114 | + if ($language->isNoValue() || $language->isSomeValue()) { |
|
115 | 115 | continue; |
116 | 116 | } |
117 | - if ( $lexeme->getLanguage()->equals( $language->getItemId() ) ) { |
|
117 | + if ($lexeme->getLanguage()->equals($language->getItemId())) { |
|
118 | 118 | $message = null; |
119 | 119 | $status = CheckResult::STATUS_COMPLIANCE; |
120 | 120 | break; |
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
124 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
125 | 125 | } |
126 | 126 | |
127 | - private function getLexeme( Context $context ): ?EntityDocument { |
|
127 | + private function getLexeme(Context $context): ?EntityDocument { |
|
128 | 128 | $entityType = $context->getEntity()->getType(); |
129 | 129 | |
130 | - if ( $entityType === Lexeme::ENTITY_TYPE ) { |
|
130 | + if ($entityType === Lexeme::ENTITY_TYPE) { |
|
131 | 131 | return $context->getEntity(); |
132 | 132 | } |
133 | 133 | |
134 | - if ( in_array( $entityType, [ Form::ENTITY_TYPE, Sense::ENTITY_TYPE ] ) ) { |
|
134 | + if (in_array($entityType, [Form::ENTITY_TYPE, Sense::ENTITY_TYPE])) { |
|
135 | 135 | /** @var LexemeSubEntityId $id */ |
136 | 136 | $id = $context->getEntity()->getId(); |
137 | 137 | '@phan-var LexemeSubEntityId $id'; |
138 | - return $this->entityLookup->getEntity( $id->getLexemeId() ); |
|
138 | + return $this->entityLookup->getEntity($id->getLexemeId()); |
|
139 | 139 | } |
140 | 140 | } |
141 | 141 | |
142 | - public function checkConstraintParameters( Constraint $constraint ): array { |
|
142 | + public function checkConstraintParameters(Constraint $constraint): array { |
|
143 | 143 | $constraintParameters = $constraint->getConstraintParameters(); |
144 | 144 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
145 | 145 | $exceptions = []; |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | $constraintTypeItemId, |
150 | 150 | true |
151 | 151 | ); |
152 | - } catch ( ConstraintParameterException $e ) { |
|
152 | + } catch (ConstraintParameterException $e) { |
|
153 | 153 | $exceptions[] = $e; |
154 | 154 | } |
155 | 155 | return $exceptions; |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * @throws ConstraintParameterException |
98 | 98 | * @return CheckResult |
99 | 99 | */ |
100 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
100 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
101 | 101 | $parameters = []; |
102 | 102 | $constraintParameters = $constraint->getConstraintParameters(); |
103 | 103 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | $constraintParameters, |
107 | 107 | $constraintTypeItemId |
108 | 108 | ); |
109 | - $parameters['pattern'] = [ $format ]; |
|
109 | + $parameters['pattern'] = [$format]; |
|
110 | 110 | |
111 | 111 | $syntaxClarifications = $this->constraintParameterParser->parseSyntaxClarificationParameter( |
112 | 112 | $constraintParameters |
@@ -114,9 +114,9 @@ discard block |
||
114 | 114 | |
115 | 115 | $snak = $context->getSnak(); |
116 | 116 | |
117 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
117 | + if (!$snak instanceof PropertyValueSnak) { |
|
118 | 118 | // nothing to check |
119 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
119 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | $dataValue = $snak->getDataValue(); |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * error handling: |
126 | 126 | * type of $dataValue for properties with 'Format' constraint has to be 'string' or 'monolingualtext' |
127 | 127 | */ |
128 | - switch ( $dataValue->getType() ) { |
|
128 | + switch ($dataValue->getType()) { |
|
129 | 129 | case 'string': |
130 | 130 | $text = $dataValue->getValue(); |
131 | 131 | break; |
@@ -135,13 +135,13 @@ discard block |
||
135 | 135 | $text = $dataValue->getText(); |
136 | 136 | break; |
137 | 137 | default: |
138 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-types-2' ) ) |
|
139 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
140 | - ->withDataValueType( 'string' ) |
|
141 | - ->withDataValueType( 'monolingualtext' ); |
|
142 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
138 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-types-2')) |
|
139 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
140 | + ->withDataValueType('string') |
|
141 | + ->withDataValueType('monolingualtext'); |
|
142 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
143 | 143 | } |
144 | - $status = $this->runRegexCheck( $text, $format ); |
|
144 | + $status = $this->runRegexCheck($text, $format); |
|
145 | 145 | $message = $this->formatMessage( |
146 | 146 | $status, |
147 | 147 | $text, |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | $syntaxClarifications, |
151 | 151 | $constraintTypeItemId |
152 | 152 | ); |
153 | - return new CheckResult( $context, $constraint, $parameters, $status, $message ); |
|
153 | + return new CheckResult($context, $constraint, $parameters, $status, $message); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | private function formatMessage( |
@@ -162,73 +162,73 @@ discard block |
||
162 | 162 | string $constraintTypeItemId |
163 | 163 | ): ?ViolationMessage { |
164 | 164 | $message = null; |
165 | - if ( $status === CheckResult::STATUS_VIOLATION ) { |
|
166 | - $message = ( new ViolationMessage( 'wbqc-violation-message-format-clarification' ) ) |
|
167 | - ->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ) |
|
168 | - ->withDataValue( new StringValue( $text ), Role::OBJECT ) |
|
169 | - ->withInlineCode( $format, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
170 | - ->withMultilingualText( $syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE ); |
|
171 | - } elseif ( $status === CheckResult::STATUS_TODO ) { |
|
172 | - $message = ( new ViolationMessage( 'wbqc-violation-message-security-reason' ) ) |
|
173 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ); |
|
165 | + if ($status === CheckResult::STATUS_VIOLATION) { |
|
166 | + $message = (new ViolationMessage('wbqc-violation-message-format-clarification')) |
|
167 | + ->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY) |
|
168 | + ->withDataValue(new StringValue($text), Role::OBJECT) |
|
169 | + ->withInlineCode($format, Role::CONSTRAINT_PARAMETER_VALUE) |
|
170 | + ->withMultilingualText($syntaxClarifications, Role::CONSTRAINT_PARAMETER_VALUE); |
|
171 | + } elseif ($status === CheckResult::STATUS_TODO) { |
|
172 | + $message = (new ViolationMessage('wbqc-violation-message-security-reason')) |
|
173 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | return $message; |
177 | 177 | } |
178 | 178 | |
179 | - private function runRegexCheck( string $text, string $format ): string { |
|
180 | - if ( !$this->config->get( 'WBQualityConstraintsCheckFormatConstraint' ) ) { |
|
179 | + private function runRegexCheck(string $text, string $format): string { |
|
180 | + if (!$this->config->get('WBQualityConstraintsCheckFormatConstraint')) { |
|
181 | 181 | return CheckResult::STATUS_TODO; |
182 | 182 | } |
183 | 183 | if ( |
184 | - $this->config->get( 'WBQualityConstraintsFormatCheckerShellboxRatio' ) > (float)wfRandom() |
|
184 | + $this->config->get('WBQualityConstraintsFormatCheckerShellboxRatio') > (float) wfRandom() |
|
185 | 185 | ) { |
186 | - return $this->runRegexCheckUsingShellbox( $text, $format ); |
|
186 | + return $this->runRegexCheckUsingShellbox($text, $format); |
|
187 | 187 | } |
188 | 188 | |
189 | - return $this->runRegexCheckUsingSparql( $text, $format ); |
|
189 | + return $this->runRegexCheckUsingSparql($text, $format); |
|
190 | 190 | } |
191 | 191 | |
192 | - private function runRegexCheckUsingShellbox( string $text, string $format ): string { |
|
193 | - if ( !$this->shellboxClientFactory->isEnabled() ) { |
|
192 | + private function runRegexCheckUsingShellbox(string $text, string $format): string { |
|
193 | + if (!$this->shellboxClientFactory->isEnabled()) { |
|
194 | 194 | return CheckResult::STATUS_TODO; |
195 | 195 | } |
196 | 196 | try { |
197 | - $pattern = '/^' . str_replace( '/', '\/', $format ) . '$/'; |
|
197 | + $pattern = '/^'.str_replace('/', '\/', $format).'$/'; |
|
198 | 198 | $shellboxResponse = $this->shellboxClientFactory->getClient( |
199 | - [ 'timeout' => $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' ) / 1000 ] |
|
199 | + ['timeout' => $this->config->get('WBQualityConstraintsSparqlMaxMillis') / 1000] |
|
200 | 200 | )->call( |
201 | 201 | 'constraint-regex-checker', |
202 | 202 | 'preg_match', |
203 | - [ $pattern, $text ] |
|
203 | + [$pattern, $text] |
|
204 | 204 | ); |
205 | - } catch ( ShellboxError $exception ) { |
|
205 | + } catch (ShellboxError $exception) { |
|
206 | 206 | throw new ConstraintParameterException( |
207 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
208 | - ->withInlineCode( $pattern, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
207 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
208 | + ->withInlineCode($pattern, Role::CONSTRAINT_PARAMETER_VALUE) |
|
209 | 209 | ); |
210 | 210 | } |
211 | 211 | |
212 | - if ( $shellboxResponse ) { |
|
212 | + if ($shellboxResponse) { |
|
213 | 213 | return CheckResult::STATUS_COMPLIANCE; |
214 | 214 | } else { |
215 | 215 | return CheckResult::STATUS_VIOLATION; |
216 | 216 | } |
217 | 217 | } |
218 | 218 | |
219 | - private function runRegexCheckUsingSparql( string $text, string $format ): string { |
|
220 | - if ( $this->sparqlHelper instanceof DummySparqlHelper ) { |
|
219 | + private function runRegexCheckUsingSparql(string $text, string $format): string { |
|
220 | + if ($this->sparqlHelper instanceof DummySparqlHelper) { |
|
221 | 221 | return CheckResult::STATUS_TODO; |
222 | 222 | } |
223 | 223 | |
224 | - if ( $this->sparqlHelper->matchesRegularExpression( $text, $format ) ) { |
|
224 | + if ($this->sparqlHelper->matchesRegularExpression($text, $format)) { |
|
225 | 225 | return CheckResult::STATUS_COMPLIANCE; |
226 | 226 | } else { |
227 | 227 | return CheckResult::STATUS_VIOLATION; |
228 | 228 | } |
229 | 229 | } |
230 | 230 | |
231 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
231 | + public function checkConstraintParameters(Constraint $constraint) { |
|
232 | 232 | $constraintParameters = $constraint->getConstraintParameters(); |
233 | 233 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
234 | 234 | $exceptions = []; |
@@ -237,14 +237,14 @@ discard block |
||
237 | 237 | $constraintParameters, |
238 | 238 | $constraintTypeItemId |
239 | 239 | ); |
240 | - } catch ( ConstraintParameterException $e ) { |
|
240 | + } catch (ConstraintParameterException $e) { |
|
241 | 241 | $exceptions[] = $e; |
242 | 242 | } |
243 | 243 | try { |
244 | 244 | $this->constraintParameterParser->parseSyntaxClarificationParameter( |
245 | 245 | $constraintParameters |
246 | 246 | ); |
247 | - } catch ( ConstraintParameterException $e ) { |
|
247 | + } catch (ConstraintParameterException $e) { |
|
248 | 248 | $exceptions[] = $e; |
249 | 249 | } |
250 | 250 | return $exceptions; |
@@ -37,199 +37,199 @@ |
||
37 | 37 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\ValueTypeChecker; |
38 | 38 | |
39 | 39 | return [ |
40 | - ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => static function ( MediaWikiServices $services ) { |
|
40 | + ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => static function(MediaWikiServices $services) { |
|
41 | 41 | return new ConflictsWithChecker( |
42 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
43 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
42 | + ConstraintsServices::getConstraintParameterParser($services), |
|
43 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
44 | 44 | ); |
45 | 45 | }, |
46 | 46 | |
47 | - ConstraintCheckerServices::ITEM_CHECKER => static function ( MediaWikiServices $services ) { |
|
47 | + ConstraintCheckerServices::ITEM_CHECKER => static function(MediaWikiServices $services) { |
|
48 | 48 | return new ItemChecker( |
49 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
50 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
49 | + ConstraintsServices::getConstraintParameterParser($services), |
|
50 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
51 | 51 | ); |
52 | 52 | }, |
53 | 53 | |
54 | - ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => static function ( MediaWikiServices $services ) { |
|
54 | + ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => static function(MediaWikiServices $services) { |
|
55 | 55 | return new TargetRequiredClaimChecker( |
56 | - WikibaseServices::getEntityLookup( $services ), |
|
57 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
58 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
56 | + WikibaseServices::getEntityLookup($services), |
|
57 | + ConstraintsServices::getConstraintParameterParser($services), |
|
58 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
59 | 59 | ); |
60 | 60 | }, |
61 | 61 | |
62 | - ConstraintCheckerServices::SYMMETRIC_CHECKER => static function ( MediaWikiServices $services ) { |
|
62 | + ConstraintCheckerServices::SYMMETRIC_CHECKER => static function(MediaWikiServices $services) { |
|
63 | 63 | return new SymmetricChecker( |
64 | - WikibaseServices::getEntityLookupWithoutCache( $services ), |
|
65 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
64 | + WikibaseServices::getEntityLookupWithoutCache($services), |
|
65 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
66 | 66 | ); |
67 | 67 | }, |
68 | 68 | |
69 | - ConstraintCheckerServices::INVERSE_CHECKER => static function ( MediaWikiServices $services ) { |
|
69 | + ConstraintCheckerServices::INVERSE_CHECKER => static function(MediaWikiServices $services) { |
|
70 | 70 | return new InverseChecker( |
71 | - WikibaseServices::getEntityLookup( $services ), |
|
72 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
73 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
71 | + WikibaseServices::getEntityLookup($services), |
|
72 | + ConstraintsServices::getConstraintParameterParser($services), |
|
73 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
74 | 74 | ); |
75 | 75 | }, |
76 | 76 | |
77 | - ConstraintCheckerServices::QUALIFIER_CHECKER => static function ( MediaWikiServices $services ) { |
|
77 | + ConstraintCheckerServices::QUALIFIER_CHECKER => static function(MediaWikiServices $services) { |
|
78 | 78 | return new QualifierChecker(); |
79 | 79 | }, |
80 | 80 | |
81 | - ConstraintCheckerServices::QUALIFIERS_CHECKER => static function ( MediaWikiServices $services ) { |
|
81 | + ConstraintCheckerServices::QUALIFIERS_CHECKER => static function(MediaWikiServices $services) { |
|
82 | 82 | return new QualifiersChecker( |
83 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
83 | + ConstraintsServices::getConstraintParameterParser($services) |
|
84 | 84 | ); |
85 | 85 | }, |
86 | 86 | |
87 | - ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => static function ( MediaWikiServices $services ) { |
|
87 | + ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => static function(MediaWikiServices $services) { |
|
88 | 88 | return new MandatoryQualifiersChecker( |
89 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
89 | + ConstraintsServices::getConstraintParameterParser($services) |
|
90 | 90 | ); |
91 | 91 | }, |
92 | 92 | |
93 | - ConstraintCheckerServices::RANGE_CHECKER => static function ( MediaWikiServices $services ) { |
|
93 | + ConstraintCheckerServices::RANGE_CHECKER => static function(MediaWikiServices $services) { |
|
94 | 94 | return new RangeChecker( |
95 | - WikibaseServices::getPropertyDataTypeLookup( $services ), |
|
96 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
97 | - ConstraintsServices::getRangeCheckerHelper( $services ) |
|
95 | + WikibaseServices::getPropertyDataTypeLookup($services), |
|
96 | + ConstraintsServices::getConstraintParameterParser($services), |
|
97 | + ConstraintsServices::getRangeCheckerHelper($services) |
|
98 | 98 | ); |
99 | 99 | }, |
100 | 100 | |
101 | - ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => static function ( MediaWikiServices $services ) { |
|
101 | + ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => static function(MediaWikiServices $services) { |
|
102 | 102 | return new DiffWithinRangeChecker( |
103 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
104 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
103 | + ConstraintsServices::getConstraintParameterParser($services), |
|
104 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
105 | 105 | $services->getMainConfig() |
106 | 106 | ); |
107 | 107 | }, |
108 | 108 | |
109 | - ConstraintCheckerServices::TYPE_CHECKER => static function ( MediaWikiServices $services ) { |
|
109 | + ConstraintCheckerServices::TYPE_CHECKER => static function(MediaWikiServices $services) { |
|
110 | 110 | return new TypeChecker( |
111 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
112 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
111 | + ConstraintsServices::getConstraintParameterParser($services), |
|
112 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
113 | 113 | $services->getMainConfig() |
114 | 114 | ); |
115 | 115 | }, |
116 | 116 | |
117 | - ConstraintCheckerServices::VALUE_TYPE_CHECKER => static function ( MediaWikiServices $services ) { |
|
117 | + ConstraintCheckerServices::VALUE_TYPE_CHECKER => static function(MediaWikiServices $services) { |
|
118 | 118 | return new ValueTypeChecker( |
119 | - WikibaseServices::getEntityLookup( $services ), |
|
120 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
121 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
119 | + WikibaseServices::getEntityLookup($services), |
|
120 | + ConstraintsServices::getConstraintParameterParser($services), |
|
121 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
122 | 122 | $services->getMainConfig() |
123 | 123 | ); |
124 | 124 | }, |
125 | 125 | |
126 | - ConstraintCheckerServices::SINGLE_VALUE_CHECKER => static function ( MediaWikiServices $services ) { |
|
126 | + ConstraintCheckerServices::SINGLE_VALUE_CHECKER => static function(MediaWikiServices $services) { |
|
127 | 127 | return new SingleValueChecker( |
128 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
128 | + ConstraintsServices::getConstraintParameterParser($services) |
|
129 | 129 | ); |
130 | 130 | }, |
131 | 131 | |
132 | - ConstraintCheckerServices::MULTI_VALUE_CHECKER => static function ( MediaWikiServices $services ) { |
|
132 | + ConstraintCheckerServices::MULTI_VALUE_CHECKER => static function(MediaWikiServices $services) { |
|
133 | 133 | return new MultiValueChecker( |
134 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
134 | + ConstraintsServices::getConstraintParameterParser($services) |
|
135 | 135 | ); |
136 | 136 | }, |
137 | 137 | |
138 | - ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => static function ( MediaWikiServices $services ) { |
|
138 | + ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => static function(MediaWikiServices $services) { |
|
139 | 139 | // TODO return a different, dummy implementation if SPARQL is not available |
140 | 140 | return new UniqueValueChecker( |
141 | - ConstraintsServices::getSparqlHelper( $services ) |
|
141 | + ConstraintsServices::getSparqlHelper($services) |
|
142 | 142 | ); |
143 | 143 | }, |
144 | 144 | |
145 | - ConstraintCheckerServices::FORMAT_CHECKER => static function ( MediaWikiServices $services ) { |
|
145 | + ConstraintCheckerServices::FORMAT_CHECKER => static function(MediaWikiServices $services) { |
|
146 | 146 | // TODO return a different, dummy implementation if SPARQL is not available |
147 | 147 | return new FormatChecker( |
148 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
148 | + ConstraintsServices::getConstraintParameterParser($services), |
|
149 | 149 | $services->getMainConfig(), |
150 | - ConstraintsServices::getSparqlHelper( $services ), |
|
150 | + ConstraintsServices::getSparqlHelper($services), |
|
151 | 151 | $services->getShellboxClientFactory() |
152 | 152 | ); |
153 | 153 | }, |
154 | 154 | |
155 | - ConstraintCheckerServices::COMMONS_LINK_CHECKER => static function ( MediaWikiServices $services ) { |
|
155 | + ConstraintCheckerServices::COMMONS_LINK_CHECKER => static function(MediaWikiServices $services) { |
|
156 | 156 | $pageNameNormalizer = new MediaWikiPageNameNormalizer(); |
157 | 157 | return new CommonsLinkChecker( |
158 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
158 | + ConstraintsServices::getConstraintParameterParser($services), |
|
159 | 159 | $pageNameNormalizer, |
160 | - WikibaseRepo::getPropertyDataTypeLookup( $services ) |
|
160 | + WikibaseRepo::getPropertyDataTypeLookup($services) |
|
161 | 161 | ); |
162 | 162 | }, |
163 | 163 | |
164 | - ConstraintCheckerServices::ONE_OF_CHECKER => static function ( MediaWikiServices $services ) { |
|
164 | + ConstraintCheckerServices::ONE_OF_CHECKER => static function(MediaWikiServices $services) { |
|
165 | 165 | return new OneOfChecker( |
166 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
166 | + ConstraintsServices::getConstraintParameterParser($services) |
|
167 | 167 | ); |
168 | 168 | }, |
169 | 169 | |
170 | - ConstraintCheckerServices::VALUE_ONLY_CHECKER => static function ( MediaWikiServices $services ) { |
|
170 | + ConstraintCheckerServices::VALUE_ONLY_CHECKER => static function(MediaWikiServices $services) { |
|
171 | 171 | return new ValueOnlyChecker(); |
172 | 172 | }, |
173 | 173 | |
174 | - ConstraintCheckerServices::REFERENCE_CHECKER => static function ( MediaWikiServices $services ) { |
|
174 | + ConstraintCheckerServices::REFERENCE_CHECKER => static function(MediaWikiServices $services) { |
|
175 | 175 | return new ReferenceChecker(); |
176 | 176 | }, |
177 | 177 | |
178 | - ConstraintCheckerServices::NO_BOUNDS_CHECKER => static function ( MediaWikiServices $services ) { |
|
178 | + ConstraintCheckerServices::NO_BOUNDS_CHECKER => static function(MediaWikiServices $services) { |
|
179 | 179 | return new NoBoundsChecker(); |
180 | 180 | }, |
181 | 181 | |
182 | - ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => static function ( MediaWikiServices $services ) { |
|
182 | + ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => static function(MediaWikiServices $services) { |
|
183 | 183 | return new AllowedUnitsChecker( |
184 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
185 | - WikibaseRepo::getUnitConverter( $services ) |
|
184 | + ConstraintsServices::getConstraintParameterParser($services), |
|
185 | + WikibaseRepo::getUnitConverter($services) |
|
186 | 186 | ); |
187 | 187 | }, |
188 | 188 | |
189 | - ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => static function ( MediaWikiServices $services ) { |
|
189 | + ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => static function(MediaWikiServices $services) { |
|
190 | 190 | return new SingleBestValueChecker( |
191 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
191 | + ConstraintsServices::getConstraintParameterParser($services) |
|
192 | 192 | ); |
193 | 193 | }, |
194 | 194 | |
195 | - ConstraintCheckerServices::ENTITY_TYPE_CHECKER => static function ( MediaWikiServices $services ) { |
|
195 | + ConstraintCheckerServices::ENTITY_TYPE_CHECKER => static function(MediaWikiServices $services) { |
|
196 | 196 | return new EntityTypeChecker( |
197 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
197 | + ConstraintsServices::getConstraintParameterParser($services) |
|
198 | 198 | ); |
199 | 199 | }, |
200 | 200 | |
201 | - ConstraintCheckerServices::NONE_OF_CHECKER => static function ( MediaWikiServices $services ) { |
|
201 | + ConstraintCheckerServices::NONE_OF_CHECKER => static function(MediaWikiServices $services) { |
|
202 | 202 | return new NoneOfChecker( |
203 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
203 | + ConstraintsServices::getConstraintParameterParser($services) |
|
204 | 204 | ); |
205 | 205 | }, |
206 | 206 | |
207 | - ConstraintCheckerServices::INTEGER_CHECKER => static function ( MediaWikiServices $services ) { |
|
207 | + ConstraintCheckerServices::INTEGER_CHECKER => static function(MediaWikiServices $services) { |
|
208 | 208 | return new IntegerChecker(); |
209 | 209 | }, |
210 | 210 | |
211 | - ConstraintCheckerServices::CITATION_NEEDED_CHECKER => static function ( MediaWikiServices $services ) { |
|
211 | + ConstraintCheckerServices::CITATION_NEEDED_CHECKER => static function(MediaWikiServices $services) { |
|
212 | 212 | return new CitationNeededChecker(); |
213 | 213 | }, |
214 | 214 | |
215 | - ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => static function ( MediaWikiServices $services ) { |
|
215 | + ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => static function(MediaWikiServices $services) { |
|
216 | 216 | return new PropertyScopeChecker( |
217 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
217 | + ConstraintsServices::getConstraintParameterParser($services) |
|
218 | 218 | ); |
219 | 219 | }, |
220 | 220 | |
221 | - ConstraintCheckerServices::CONTEMPORARY_CHECKER => static function ( MediaWikiServices $services ) { |
|
221 | + ConstraintCheckerServices::CONTEMPORARY_CHECKER => static function(MediaWikiServices $services) { |
|
222 | 222 | return new ContemporaryChecker( |
223 | - WikibaseServices::getEntityLookup( $services ), |
|
224 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
223 | + WikibaseServices::getEntityLookup($services), |
|
224 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
225 | 225 | $services->getMainConfig() |
226 | 226 | ); |
227 | 227 | }, |
228 | 228 | |
229 | - ConstraintCheckerServices::LEXEME_LANGUAGE_CHECKER => static function ( MediaWikiServices $services ) { |
|
229 | + ConstraintCheckerServices::LEXEME_LANGUAGE_CHECKER => static function(MediaWikiServices $services) { |
|
230 | 230 | return new LanguageChecker( |
231 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
232 | - WikibaseServices::getEntityLookup( $services ) |
|
231 | + ConstraintsServices::getConstraintParameterParser($services), |
|
232 | + WikibaseServices::getEntityLookup($services) |
|
233 | 233 | ); |
234 | 234 | }, |
235 | 235 | ]; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Checker; |
6 | 6 | |
@@ -77,26 +77,26 @@ discard block |
||
77 | 77 | * @return array first element is the namespace number (default namespace for TitleParser), |
78 | 78 | * second element is a string to prepend to the title before giving it to the TitleParser |
79 | 79 | */ |
80 | - private function getCommonsNamespace( string $namespace ): array { |
|
81 | - switch ( $namespace ) { |
|
80 | + private function getCommonsNamespace(string $namespace): array { |
|
81 | + switch ($namespace) { |
|
82 | 82 | case '': |
83 | - return [ NS_MAIN, '' ]; |
|
83 | + return [NS_MAIN, '']; |
|
84 | 84 | // extra namespaces, see operations/mediawiki-config.git, |
85 | 85 | // wmf-config/InitialiseSettings.php, 'wgExtraNamespaces' key, 'commonswiki' subkey |
86 | 86 | case 'Creator': |
87 | - return [ 100, '' ]; |
|
87 | + return [100, '']; |
|
88 | 88 | case 'TimedText': |
89 | - return [ 102, '' ]; |
|
89 | + return [102, '']; |
|
90 | 90 | case 'Sequence': |
91 | - return [ 104, '' ]; |
|
91 | + return [104, '']; |
|
92 | 92 | case 'Institution': |
93 | - return [ 106, '' ]; |
|
93 | + return [106, '']; |
|
94 | 94 | // extension namespace, see mediawiki/extensions/JsonConfig.git, |
95 | 95 | // extension.json, 'namespaces' key, third element |
96 | 96 | case 'Data': |
97 | - return [ 486, '' ]; |
|
97 | + return [486, '']; |
|
98 | 98 | default: |
99 | - return [ NS_MAIN, $namespace . ':' ]; |
|
99 | + return [NS_MAIN, $namespace.':']; |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @throws ConstraintParameterException |
107 | 107 | */ |
108 | - public function checkConstraint( Context $context, Constraint $constraint ): CheckResult { |
|
108 | + public function checkConstraint(Context $context, Constraint $constraint): CheckResult { |
|
109 | 109 | $parameters = []; |
110 | 110 | $constraintParameters = $constraint->getConstraintParameters(); |
111 | 111 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
@@ -114,13 +114,13 @@ discard block |
||
114 | 114 | $constraintParameters, |
115 | 115 | $constraintTypeItemId |
116 | 116 | ); |
117 | - $parameters['namespace'] = [ $namespace ]; |
|
117 | + $parameters['namespace'] = [$namespace]; |
|
118 | 118 | |
119 | 119 | $snak = $context->getSnak(); |
120 | 120 | |
121 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
121 | + if (!$snak instanceof PropertyValueSnak) { |
|
122 | 122 | // nothing to check |
123 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE ); |
|
123 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | $dataValue = $snak->getDataValue(); |
@@ -130,52 +130,52 @@ discard block |
||
130 | 130 | * type of $dataValue for properties with 'Commons link' constraint has to be 'string' |
131 | 131 | * parameter $namespace can be null, works for commons galleries |
132 | 132 | */ |
133 | - if ( $dataValue->getType() !== 'string' ) { |
|
134 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
135 | - ->withEntityId( new ItemId( $constraintTypeItemId ), Role::CONSTRAINT_TYPE_ITEM ) |
|
136 | - ->withDataValueType( 'string' ); |
|
137 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message ); |
|
133 | + if ($dataValue->getType() !== 'string') { |
|
134 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
135 | + ->withEntityId(new ItemId($constraintTypeItemId), Role::CONSTRAINT_TYPE_ITEM) |
|
136 | + ->withDataValueType('string'); |
|
137 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | $commonsLink = $dataValue->getValue(); |
141 | - if ( !$this->commonsLinkIsWellFormed( $commonsLink ) ) { |
|
142 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
143 | - new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ) ); |
|
141 | + if (!$this->commonsLinkIsWellFormed($commonsLink)) { |
|
142 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
143 | + new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed')); |
|
144 | 144 | } |
145 | 145 | |
146 | - $dataType = $this->propertyDatatypeLookup->getDataTypeIdForProperty( $snak->getPropertyId() ); |
|
147 | - switch ( $dataType ) { |
|
146 | + $dataType = $this->propertyDatatypeLookup->getDataTypeIdForProperty($snak->getPropertyId()); |
|
147 | + switch ($dataType) { |
|
148 | 148 | case 'geo-shape': |
149 | 149 | case 'tabular-data': |
150 | - if ( strpos( $commonsLink, $namespace . ':' ) !== 0 ) { |
|
151 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
152 | - new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ) ); |
|
150 | + if (strpos($commonsLink, $namespace.':') !== 0) { |
|
151 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
152 | + new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed')); |
|
153 | 153 | } |
154 | 154 | $pageName = $commonsLink; |
155 | 155 | break; |
156 | 156 | default: |
157 | - $pageName = $namespace ? $namespace . ':' . $commonsLink : $commonsLink; |
|
157 | + $pageName = $namespace ? $namespace.':'.$commonsLink : $commonsLink; |
|
158 | 158 | break; |
159 | 159 | } |
160 | 160 | |
161 | - $prefix = $this->getCommonsNamespace( $namespace )[1]; |
|
161 | + $prefix = $this->getCommonsNamespace($namespace)[1]; |
|
162 | 162 | $normalizedTitle = $this->pageNameNormalizer->normalizePageName( |
163 | 163 | $pageName, |
164 | 164 | 'https://commons.wikimedia.org/w/api.php' |
165 | 165 | ); |
166 | - if ( $normalizedTitle === false ) { |
|
167 | - if ( $this->valueIncludesNamespace( $commonsLink, $namespace ) ) { |
|
168 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
169 | - new ViolationMessage( 'wbqc-violation-message-commons-link-not-well-formed' ) ); |
|
166 | + if ($normalizedTitle === false) { |
|
167 | + if ($this->valueIncludesNamespace($commonsLink, $namespace)) { |
|
168 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
169 | + new ViolationMessage('wbqc-violation-message-commons-link-not-well-formed')); |
|
170 | 170 | } |
171 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
172 | - new ViolationMessage( 'wbqc-violation-message-commons-link-no-existent' ) ); |
|
171 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_VIOLATION, |
|
172 | + new ViolationMessage('wbqc-violation-message-commons-link-no-existent')); |
|
173 | 173 | } |
174 | 174 | |
175 | - return new CheckResult( $context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, null ); |
|
175 | + return new CheckResult($context, $constraint, $parameters, CheckResult::STATUS_COMPLIANCE, null); |
|
176 | 176 | } |
177 | 177 | |
178 | - public function checkConstraintParameters( Constraint $constraint ): array { |
|
178 | + public function checkConstraintParameters(Constraint $constraint): array { |
|
179 | 179 | $constraintParameters = $constraint->getConstraintParameters(); |
180 | 180 | $constraintTypeItemId = $constraint->getConstraintTypeItemId(); |
181 | 181 | $exceptions = []; |
@@ -184,15 +184,15 @@ discard block |
||
184 | 184 | $constraintParameters, |
185 | 185 | $constraintTypeItemId |
186 | 186 | ); |
187 | - } catch ( ConstraintParameterException $e ) { |
|
187 | + } catch (ConstraintParameterException $e) { |
|
188 | 188 | $exceptions[] = $e; |
189 | 189 | } |
190 | 190 | return $exceptions; |
191 | 191 | } |
192 | 192 | |
193 | - private function commonsLinkIsWellFormed( string $commonsLink ): bool { |
|
194 | - $toReplace = [ "_", "%20" ]; |
|
195 | - $compareString = trim( str_replace( $toReplace, '', $commonsLink ) ); |
|
193 | + private function commonsLinkIsWellFormed(string $commonsLink): bool { |
|
194 | + $toReplace = ["_", "%20"]; |
|
195 | + $compareString = trim(str_replace($toReplace, '', $commonsLink)); |
|
196 | 196 | |
197 | 197 | return $commonsLink === $compareString; |
198 | 198 | } |
@@ -201,9 +201,9 @@ discard block |
||
201 | 201 | * Checks whether the value of the statement already includes the namespace. |
202 | 202 | * This special case should be reported as “malformed title” instead of “title does not exist”. |
203 | 203 | */ |
204 | - private function valueIncludesNamespace( string $value, string $namespace ): bool { |
|
204 | + private function valueIncludesNamespace(string $value, string $namespace): bool { |
|
205 | 205 | return $namespace !== '' && |
206 | - strncasecmp( $value, $namespace . ':', strlen( $namespace ) + 1 ) === 0; |
|
206 | + strncasecmp($value, $namespace.':', strlen($namespace) + 1) === 0; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | } |
@@ -80,26 +80,26 @@ discard block |
||
80 | 80 | * @return bool |
81 | 81 | * @throws OverflowException if $entitiesChecked exceeds the configured limit |
82 | 82 | */ |
83 | - private function isSubclassOf( EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0 ) { |
|
84 | - $maxEntities = $this->config->get( 'WBQualityConstraintsTypeCheckMaxEntities' ); |
|
83 | + private function isSubclassOf(EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0) { |
|
84 | + $maxEntities = $this->config->get('WBQualityConstraintsTypeCheckMaxEntities'); |
|
85 | 85 | if ( ++$entitiesChecked > $maxEntities ) { |
86 | - throw new OverflowException( 'Too many entities to check' ); |
|
86 | + throw new OverflowException('Too many entities to check'); |
|
87 | 87 | } |
88 | 88 | |
89 | - $item = $this->entityLookup->getEntity( $comparativeClass ); |
|
90 | - if ( !( $item instanceof StatementListProvider ) ) { |
|
89 | + $item = $this->entityLookup->getEntity($comparativeClass); |
|
90 | + if (!($item instanceof StatementListProvider)) { |
|
91 | 91 | return false; // lookup failed, probably because item doesn't exist |
92 | 92 | } |
93 | 93 | |
94 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
94 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
95 | 95 | $statements = $item->getStatements() |
96 | - ->getByPropertyId( new PropertyId( $subclassId ) ) |
|
96 | + ->getByPropertyId(new PropertyId($subclassId)) |
|
97 | 97 | ->getBestStatements(); |
98 | 98 | /** @var Statement $statement */ |
99 | - foreach ( $statements as $statement ) { |
|
99 | + foreach ($statements as $statement) { |
|
100 | 100 | $mainSnak = $statement->getMainSnak(); |
101 | 101 | |
102 | - if ( !$this->hasCorrectType( $mainSnak ) ) { |
|
102 | + if (!$this->hasCorrectType($mainSnak)) { |
|
103 | 103 | continue; |
104 | 104 | } |
105 | 105 | /** @var PropertyValueSnak $mainSnak */ |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | '@phan-var EntityIdValue $dataValue'; |
110 | 110 | $comparativeClass = $dataValue->getEntityId(); |
111 | 111 | |
112 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
112 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
113 | 113 | return true; |
114 | 114 | } |
115 | 115 | |
116 | - if ( $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ) ) { |
|
116 | + if ($this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked)) { |
|
117 | 117 | return true; |
118 | 118 | } |
119 | 119 | } |
@@ -134,48 +134,48 @@ discard block |
||
134 | 134 | * @return CachedBool |
135 | 135 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
136 | 136 | */ |
137 | - public function isSubclassOfWithSparqlFallback( EntityId $comparativeClass, array $classesToCheck ) { |
|
137 | + public function isSubclassOfWithSparqlFallback(EntityId $comparativeClass, array $classesToCheck) { |
|
138 | 138 | try { |
139 | 139 | $entitiesChecked = 0; |
140 | - $start1 = microtime( true ); |
|
141 | - $isSubclass = $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ); |
|
142 | - $end1 = microtime( true ); |
|
140 | + $start1 = microtime(true); |
|
141 | + $isSubclass = $this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked); |
|
142 | + $end1 = microtime(true); |
|
143 | 143 | $this->dataFactory->timing( |
144 | 144 | 'wikibase.quality.constraints.type.php.success.timing', |
145 | - ( $end1 - $start1 ) * 1000 |
|
145 | + ($end1 - $start1) * 1000 |
|
146 | 146 | ); |
147 | 147 | $this->dataFactory->timing( // not really a timing, but works like one (we want percentiles etc.) |
148 | 148 | 'wikibase.quality.constraints.type.php.success.entities', |
149 | 149 | $entitiesChecked |
150 | 150 | ); |
151 | 151 | |
152 | - return new CachedBool( $isSubclass, Metadata::blank() ); |
|
153 | - } catch ( OverflowException $e ) { |
|
154 | - $end1 = microtime( true ); |
|
152 | + return new CachedBool($isSubclass, Metadata::blank()); |
|
153 | + } catch (OverflowException $e) { |
|
154 | + $end1 = microtime(true); |
|
155 | 155 | $this->dataFactory->timing( |
156 | 156 | 'wikibase.quality.constraints.type.php.overflow.timing', |
157 | - ( $end1 - $start1 ) * 1000 |
|
157 | + ($end1 - $start1) * 1000 |
|
158 | 158 | ); |
159 | 159 | |
160 | - if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) { |
|
160 | + if (!($this->sparqlHelper instanceof DummySparqlHelper)) { |
|
161 | 161 | $this->dataFactory->increment( |
162 | 162 | 'wikibase.quality.constraints.sparql.typeFallback' |
163 | 163 | ); |
164 | 164 | |
165 | - $start2 = microtime( true ); |
|
165 | + $start2 = microtime(true); |
|
166 | 166 | $hasType = $this->sparqlHelper->hasType( |
167 | 167 | $comparativeClass->getSerialization(), |
168 | 168 | $classesToCheck |
169 | 169 | ); |
170 | - $end2 = microtime( true ); |
|
170 | + $end2 = microtime(true); |
|
171 | 171 | $this->dataFactory->timing( |
172 | 172 | 'wikibase.quality.constraints.type.sparql.success.timing', |
173 | - ( $end2 - $start2 ) * 1000 |
|
173 | + ($end2 - $start2) * 1000 |
|
174 | 174 | ); |
175 | 175 | |
176 | 176 | return $hasType; |
177 | 177 | } else { |
178 | - return new CachedBool( false, Metadata::blank() ); |
|
178 | + return new CachedBool(false, Metadata::blank()); |
|
179 | 179 | } |
180 | 180 | } |
181 | 181 | } |
@@ -193,13 +193,13 @@ discard block |
||
193 | 193 | * @return CachedBool |
194 | 194 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
195 | 195 | */ |
196 | - public function hasClassInRelation( StatementList $statements, array $relationIds, array $classesToCheck ) { |
|
196 | + public function hasClassInRelation(StatementList $statements, array $relationIds, array $classesToCheck) { |
|
197 | 197 | $metadatas = []; |
198 | 198 | |
199 | - foreach ( $this->getBestStatementsByPropertyIds( $statements, $relationIds ) as $statement ) { |
|
199 | + foreach ($this->getBestStatementsByPropertyIds($statements, $relationIds) as $statement) { |
|
200 | 200 | $mainSnak = $statement->getMainSnak(); |
201 | 201 | |
202 | - if ( !$this->hasCorrectType( $mainSnak ) ) { |
|
202 | + if (!$this->hasCorrectType($mainSnak)) { |
|
203 | 203 | continue; |
204 | 204 | } |
205 | 205 | /** @var PropertyValueSnak $mainSnak */ |
@@ -209,24 +209,24 @@ discard block |
||
209 | 209 | '@phan-var EntityIdValue $dataValue'; |
210 | 210 | $comparativeClass = $dataValue->getEntityId(); |
211 | 211 | |
212 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
212 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
213 | 213 | // discard $metadatas, we know this is fresh |
214 | - return new CachedBool( true, Metadata::blank() ); |
|
214 | + return new CachedBool(true, Metadata::blank()); |
|
215 | 215 | } |
216 | 216 | |
217 | - $result = $this->isSubclassOfWithSparqlFallback( $comparativeClass, $classesToCheck ); |
|
217 | + $result = $this->isSubclassOfWithSparqlFallback($comparativeClass, $classesToCheck); |
|
218 | 218 | $metadatas[] = $result->getMetadata(); |
219 | - if ( $result->getBool() ) { |
|
219 | + if ($result->getBool()) { |
|
220 | 220 | return new CachedBool( |
221 | 221 | true, |
222 | - Metadata::merge( $metadatas ) |
|
222 | + Metadata::merge($metadatas) |
|
223 | 223 | ); |
224 | 224 | } |
225 | 225 | } |
226 | 226 | |
227 | 227 | return new CachedBool( |
228 | 228 | false, |
229 | - Metadata::merge( $metadatas ) |
|
229 | + Metadata::merge($metadatas) |
|
230 | 230 | ); |
231 | 231 | } |
232 | 232 | |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | * @return bool |
236 | 236 | * @phan-assert PropertyValueSnak $mainSnak |
237 | 237 | */ |
238 | - private function hasCorrectType( Snak $mainSnak ) { |
|
238 | + private function hasCorrectType(Snak $mainSnak) { |
|
239 | 239 | return $mainSnak instanceof PropertyValueSnak |
240 | 240 | && $mainSnak->getDataValue()->getType() === 'wikibase-entityid'; |
241 | 241 | } |
@@ -252,15 +252,15 @@ discard block |
||
252 | 252 | ) { |
253 | 253 | $statementArrays = []; |
254 | 254 | |
255 | - foreach ( $propertyIdSerializations as $propertyIdSerialization ) { |
|
256 | - $propertyId = new PropertyId( $propertyIdSerialization ); |
|
255 | + foreach ($propertyIdSerializations as $propertyIdSerialization) { |
|
256 | + $propertyId = new PropertyId($propertyIdSerialization); |
|
257 | 257 | $statementArrays[] = $statements |
258 | - ->getByPropertyId( $propertyId ) |
|
258 | + ->getByPropertyId($propertyId) |
|
259 | 259 | ->getBestStatements() |
260 | 260 | ->toArray(); |
261 | 261 | } |
262 | 262 | |
263 | - return call_user_func_array( 'array_merge', $statementArrays ); |
|
263 | + return call_user_func_array('array_merge', $statementArrays); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
@@ -272,10 +272,10 @@ discard block |
||
272 | 272 | * |
273 | 273 | * @return ViolationMessage |
274 | 274 | */ |
275 | - public function getViolationMessage( PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation ) { |
|
275 | + public function getViolationMessage(PropertyId $propertyId, EntityId $entityId, array $classes, $checker, $relation) { |
|
276 | 276 | $classes = array_map( |
277 | - static function ( $itemIdSerialization ) { |
|
278 | - return new ItemId( $itemIdSerialization ); |
|
277 | + static function($itemIdSerialization) { |
|
278 | + return new ItemId($itemIdSerialization); |
|
279 | 279 | }, |
280 | 280 | $classes |
281 | 281 | ); |
@@ -287,10 +287,10 @@ discard block |
||
287 | 287 | // wbqc-violation-message-valueType-instance |
288 | 288 | // wbqc-violation-message-valueType-subclass |
289 | 289 | // wbqc-violation-message-valueType-instanceOrSubclass |
290 | - return ( new ViolationMessage( 'wbqc-violation-message-' . $checker . '-' . $relation ) ) |
|
291 | - ->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ) |
|
292 | - ->withEntityId( $entityId, Role::SUBJECT ) |
|
293 | - ->withEntityIdList( $classes, Role::OBJECT ); |
|
290 | + return (new ViolationMessage('wbqc-violation-message-'.$checker.'-'.$relation)) |
|
291 | + ->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY) |
|
292 | + ->withEntityId($entityId, Role::SUBJECT) |
|
293 | + ->withEntityIdList($classes, Role::OBJECT); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | } |