@@ -30,53 +30,53 @@ discard block |
||
| 30 | 30 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResultSerializer; |
| 31 | 31 | |
| 32 | 32 | return [ |
| 33 | - ConstraintsServices::EXPIRY_LOCK => static function ( MediaWikiServices $services ): ExpiryLock { |
|
| 34 | - return new ExpiryLock( $services->getObjectCacheFactory()->getInstance( CACHE_ANYTHING ) ); |
|
| 33 | + ConstraintsServices::EXPIRY_LOCK => static function(MediaWikiServices $services): ExpiryLock { |
|
| 34 | + return new ExpiryLock($services->getObjectCacheFactory()->getInstance(CACHE_ANYTHING)); |
|
| 35 | 35 | }, |
| 36 | 36 | |
| 37 | - ConstraintsServices::LOGGING_HELPER => static function ( MediaWikiServices $services ): LoggingHelper { |
|
| 37 | + ConstraintsServices::LOGGING_HELPER => static function(MediaWikiServices $services): LoggingHelper { |
|
| 38 | 38 | return new LoggingHelper( |
| 39 | 39 | $services->getStatsdDataFactory(), |
| 40 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ), |
|
| 40 | + LoggerFactory::getInstance('WikibaseQualityConstraints'), |
|
| 41 | 41 | $services->getMainConfig() |
| 42 | 42 | ); |
| 43 | 43 | }, |
| 44 | 44 | |
| 45 | - ConstraintsServices::CONSTRAINT_STORE => static function ( MediaWikiServices $services ): ConstraintRepositoryStore { |
|
| 46 | - $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
| 47 | - $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType( Property::ENTITY_TYPE ); |
|
| 48 | - if ( $propertySource === null ) { |
|
| 49 | - throw new RuntimeException( 'Can\'t get a ConstraintStore for properties not stored in a database.' ); |
|
| 45 | + ConstraintsServices::CONSTRAINT_STORE => static function(MediaWikiServices $services): ConstraintRepositoryStore { |
|
| 46 | + $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
| 47 | + $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType(Property::ENTITY_TYPE); |
|
| 48 | + if ($propertySource === null) { |
|
| 49 | + throw new RuntimeException('Can\'t get a ConstraintStore for properties not stored in a database.'); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - $localEntitySourceName = WikibaseRepo::getLocalEntitySource( $services )->getSourceName(); |
|
| 53 | - if ( $propertySource->getSourceName() !== $localEntitySourceName ) { |
|
| 54 | - throw new RuntimeException( 'Can\'t get a ConstraintStore for a non local entity source.' ); |
|
| 52 | + $localEntitySourceName = WikibaseRepo::getLocalEntitySource($services)->getSourceName(); |
|
| 53 | + if ($propertySource->getSourceName() !== $localEntitySourceName) { |
|
| 54 | + throw new RuntimeException('Can\'t get a ConstraintStore for a non local entity source.'); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | $dbName = $propertySource->getDatabaseName(); |
| 58 | 58 | return new ConstraintRepositoryStore( |
| 59 | - $services->getDBLoadBalancerFactory()->getMainLB( $dbName ), |
|
| 59 | + $services->getDBLoadBalancerFactory()->getMainLB($dbName), |
|
| 60 | 60 | $dbName |
| 61 | 61 | ); |
| 62 | 62 | }, |
| 63 | 63 | |
| 64 | - ConstraintsServices::CONSTRAINT_LOOKUP => static function ( MediaWikiServices $services ): ConstraintLookup { |
|
| 65 | - $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
| 66 | - $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType( Property::ENTITY_TYPE ); |
|
| 67 | - if ( $propertySource === null ) { |
|
| 68 | - throw new RuntimeException( 'Can\'t get a ConstraintStore for properties not stored in a database.' ); |
|
| 64 | + ConstraintsServices::CONSTRAINT_LOOKUP => static function(MediaWikiServices $services): ConstraintLookup { |
|
| 65 | + $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
| 66 | + $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType(Property::ENTITY_TYPE); |
|
| 67 | + if ($propertySource === null) { |
|
| 68 | + throw new RuntimeException('Can\'t get a ConstraintStore for properties not stored in a database.'); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | $dbName = $propertySource->getDatabaseName(); |
| 72 | 72 | $rawLookup = new ConstraintRepositoryLookup( |
| 73 | - $services->getDBLoadBalancerFactory()->getMainLB( $dbName ), |
|
| 73 | + $services->getDBLoadBalancerFactory()->getMainLB($dbName), |
|
| 74 | 74 | $dbName |
| 75 | 75 | ); |
| 76 | - return new CachingConstraintLookup( $rawLookup ); |
|
| 76 | + return new CachingConstraintLookup($rawLookup); |
|
| 77 | 77 | }, |
| 78 | 78 | |
| 79 | - ConstraintsServices::CHECK_RESULT_SERIALIZER => static function ( MediaWikiServices $services ): CheckResultSerializer { |
|
| 79 | + ConstraintsServices::CHECK_RESULT_SERIALIZER => static function(MediaWikiServices $services): CheckResultSerializer { |
|
| 80 | 80 | return new CheckResultSerializer( |
| 81 | 81 | new ConstraintSerializer( |
| 82 | 82 | false // constraint parameters are not exposed |
@@ -87,9 +87,9 @@ discard block |
||
| 87 | 87 | ); |
| 88 | 88 | }, |
| 89 | 89 | |
| 90 | - ConstraintsServices::CHECK_RESULT_DESERIALIZER => static function ( MediaWikiServices $services ): CheckResultDeserializer { |
|
| 91 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
| 92 | - $dataValueFactory = WikibaseRepo::getDataValueFactory( $services ); |
|
| 90 | + ConstraintsServices::CHECK_RESULT_DESERIALIZER => static function(MediaWikiServices $services): CheckResultDeserializer { |
|
| 91 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
| 92 | + $dataValueFactory = WikibaseRepo::getDataValueFactory($services); |
|
| 93 | 93 | |
| 94 | 94 | return new CheckResultDeserializer( |
| 95 | 95 | new ConstraintDeserializer(), |
@@ -102,17 +102,17 @@ discard block |
||
| 102 | 102 | ); |
| 103 | 103 | }, |
| 104 | 104 | |
| 105 | - ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => static function ( |
|
| 105 | + ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => static function( |
|
| 106 | 106 | MediaWikiServices $services |
| 107 | 107 | ): ViolationMessageSerializer { |
| 108 | 108 | return new ViolationMessageSerializer(); |
| 109 | 109 | }, |
| 110 | 110 | |
| 111 | - ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => static function ( |
|
| 111 | + ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => static function( |
|
| 112 | 112 | MediaWikiServices $services |
| 113 | 113 | ): ViolationMessageDeserializer { |
| 114 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
| 115 | - $dataValueFactory = WikibaseRepo::getDataValueFactory( $services ); |
|
| 114 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
| 115 | + $dataValueFactory = WikibaseRepo::getDataValueFactory($services); |
|
| 116 | 116 | |
| 117 | 117 | return new ViolationMessageDeserializer( |
| 118 | 118 | $entityIdParser, |
@@ -120,40 +120,40 @@ discard block |
||
| 120 | 120 | ); |
| 121 | 121 | }, |
| 122 | 122 | |
| 123 | - ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => static function ( |
|
| 123 | + ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => static function( |
|
| 124 | 124 | MediaWikiServices $services |
| 125 | 125 | ): ConstraintParameterParser { |
| 126 | - $deserializerFactory = WikibaseRepo::getBaseDataModelDeserializerFactory( $services ); |
|
| 127 | - $entitySourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
| 126 | + $deserializerFactory = WikibaseRepo::getBaseDataModelDeserializerFactory($services); |
|
| 127 | + $entitySourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
| 128 | 128 | |
| 129 | 129 | return new ConstraintParameterParser( |
| 130 | 130 | $services->getMainConfig(), |
| 131 | 131 | $deserializerFactory, |
| 132 | - $entitySourceDefinitions->getDatabaseSourceForEntityType( 'item' )->getConceptBaseUri() |
|
| 132 | + $entitySourceDefinitions->getDatabaseSourceForEntityType('item')->getConceptBaseUri() |
|
| 133 | 133 | ); |
| 134 | 134 | }, |
| 135 | 135 | |
| 136 | - ConstraintsServices::CONNECTION_CHECKER_HELPER => static function ( MediaWikiServices $services ): ConnectionCheckerHelper { |
|
| 136 | + ConstraintsServices::CONNECTION_CHECKER_HELPER => static function(MediaWikiServices $services): ConnectionCheckerHelper { |
|
| 137 | 137 | return new ConnectionCheckerHelper(); |
| 138 | 138 | }, |
| 139 | 139 | |
| 140 | - ConstraintsServices::RANGE_CHECKER_HELPER => static function ( MediaWikiServices $services ): RangeCheckerHelper { |
|
| 140 | + ConstraintsServices::RANGE_CHECKER_HELPER => static function(MediaWikiServices $services): RangeCheckerHelper { |
|
| 141 | 141 | return new RangeCheckerHelper( |
| 142 | 142 | $services->getMainConfig(), |
| 143 | - WikibaseRepo::getUnitConverter( $services ) |
|
| 143 | + WikibaseRepo::getUnitConverter($services) |
|
| 144 | 144 | ); |
| 145 | 145 | }, |
| 146 | 146 | |
| 147 | - ConstraintsServices::SPARQL_HELPER => static function ( MediaWikiServices $services ): SparqlHelper { |
|
| 148 | - $endpoint = $services->getMainConfig()->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
| 149 | - if ( $endpoint === '' ) { |
|
| 147 | + ConstraintsServices::SPARQL_HELPER => static function(MediaWikiServices $services): SparqlHelper { |
|
| 148 | + $endpoint = $services->getMainConfig()->get('WBQualityConstraintsSparqlEndpoint'); |
|
| 149 | + if ($endpoint === '') { |
|
| 150 | 150 | return new DummySparqlHelper(); |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - $rdfVocabulary = WikibaseRepo::getRdfVocabulary( $services ); |
|
| 154 | - $valueSnakRdfBuilderFactory = WikibaseRepo::getValueSnakRdfBuilderFactory( $services ); |
|
| 155 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
| 156 | - $propertyDataTypeLookup = WikibaseRepo::getPropertyDataTypeLookup( $services ); |
|
| 153 | + $rdfVocabulary = WikibaseRepo::getRdfVocabulary($services); |
|
| 154 | + $valueSnakRdfBuilderFactory = WikibaseRepo::getValueSnakRdfBuilderFactory($services); |
|
| 155 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
| 156 | + $propertyDataTypeLookup = WikibaseRepo::getPropertyDataTypeLookup($services); |
|
| 157 | 157 | |
| 158 | 158 | return new SparqlHelper( |
| 159 | 159 | $services->getMainConfig(), |
@@ -162,128 +162,128 @@ discard block |
||
| 162 | 162 | $entityIdParser, |
| 163 | 163 | $propertyDataTypeLookup, |
| 164 | 164 | $services->getMainWANObjectCache(), |
| 165 | - ConstraintsServices::getViolationMessageSerializer( $services ), |
|
| 166 | - ConstraintsServices::getViolationMessageDeserializer( $services ), |
|
| 165 | + ConstraintsServices::getViolationMessageSerializer($services), |
|
| 166 | + ConstraintsServices::getViolationMessageDeserializer($services), |
|
| 167 | 167 | $services->getStatsdDataFactory(), |
| 168 | - ConstraintsServices::getExpiryLock( $services ), |
|
| 169 | - ConstraintsServices::getLoggingHelper( $services ), |
|
| 170 | - WikiMap::getCurrentWikiId() . ' WikibaseQualityConstraints ' . $services->getHttpRequestFactory()->getUserAgent(), |
|
| 168 | + ConstraintsServices::getExpiryLock($services), |
|
| 169 | + ConstraintsServices::getLoggingHelper($services), |
|
| 170 | + WikiMap::getCurrentWikiId().' WikibaseQualityConstraints '.$services->getHttpRequestFactory()->getUserAgent(), |
|
| 171 | 171 | $services->getHttpRequestFactory() |
| 172 | 172 | ); |
| 173 | 173 | }, |
| 174 | 174 | |
| 175 | - ConstraintsServices::TYPE_CHECKER_HELPER => static function ( MediaWikiServices $services ): TypeCheckerHelper { |
|
| 175 | + ConstraintsServices::TYPE_CHECKER_HELPER => static function(MediaWikiServices $services): TypeCheckerHelper { |
|
| 176 | 176 | return new TypeCheckerHelper( |
| 177 | - WikibaseServices::getEntityLookup( $services ), |
|
| 177 | + WikibaseServices::getEntityLookup($services), |
|
| 178 | 178 | $services->getMainConfig(), |
| 179 | - ConstraintsServices::getSparqlHelper( $services ), |
|
| 180 | - $services->getStatsFactory()->withComponent( 'WikibaseQualityConstraints' ) |
|
| 179 | + ConstraintsServices::getSparqlHelper($services), |
|
| 180 | + $services->getStatsFactory()->withComponent('WikibaseQualityConstraints') |
|
| 181 | 181 | ); |
| 182 | 182 | }, |
| 183 | 183 | |
| 184 | - ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => static function ( |
|
| 184 | + ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => static function( |
|
| 185 | 185 | MediaWikiServices $services |
| 186 | 186 | ): DelegatingConstraintChecker { |
| 187 | - $statementGuidParser = WikibaseRepo::getStatementGuidParser( $services ); |
|
| 187 | + $statementGuidParser = WikibaseRepo::getStatementGuidParser($services); |
|
| 188 | 188 | |
| 189 | 189 | $config = $services->getMainConfig(); |
| 190 | 190 | $checkerMap = [ |
| 191 | - $config->get( 'WBQualityConstraintsConflictsWithConstraintId' ) |
|
| 192 | - => ConstraintCheckerServices::getConflictsWithChecker( $services ), |
|
| 193 | - $config->get( 'WBQualityConstraintsItemRequiresClaimConstraintId' ) |
|
| 194 | - => ConstraintCheckerServices::getItemChecker( $services ), |
|
| 195 | - $config->get( 'WBQualityConstraintsValueRequiresClaimConstraintId' ) |
|
| 196 | - => ConstraintCheckerServices::getTargetRequiredClaimChecker( $services ), |
|
| 197 | - $config->get( 'WBQualityConstraintsSymmetricConstraintId' ) |
|
| 198 | - => ConstraintCheckerServices::getSymmetricChecker( $services ), |
|
| 199 | - $config->get( 'WBQualityConstraintsInverseConstraintId' ) |
|
| 200 | - => ConstraintCheckerServices::getInverseChecker( $services ), |
|
| 201 | - $config->get( 'WBQualityConstraintsUsedAsQualifierConstraintId' ) |
|
| 202 | - => ConstraintCheckerServices::getQualifierChecker( $services ), |
|
| 203 | - $config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' ) |
|
| 204 | - => ConstraintCheckerServices::getQualifiersChecker( $services ), |
|
| 205 | - $config->get( 'WBQualityConstraintsMandatoryQualifierConstraintId' ) |
|
| 206 | - => ConstraintCheckerServices::getMandatoryQualifiersChecker( $services ), |
|
| 207 | - $config->get( 'WBQualityConstraintsRangeConstraintId' ) |
|
| 208 | - => ConstraintCheckerServices::getRangeChecker( $services ), |
|
| 209 | - $config->get( 'WBQualityConstraintsDifferenceWithinRangeConstraintId' ) |
|
| 210 | - => ConstraintCheckerServices::getDiffWithinRangeChecker( $services ), |
|
| 211 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ) |
|
| 212 | - => ConstraintCheckerServices::getTypeChecker( $services ), |
|
| 213 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ) |
|
| 214 | - => ConstraintCheckerServices::getValueTypeChecker( $services ), |
|
| 215 | - $config->get( 'WBQualityConstraintsSingleValueConstraintId' ) |
|
| 216 | - => ConstraintCheckerServices::getSingleValueChecker( $services ), |
|
| 217 | - $config->get( 'WBQualityConstraintsMultiValueConstraintId' ) |
|
| 218 | - => ConstraintCheckerServices::getMultiValueChecker( $services ), |
|
| 219 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ) |
|
| 220 | - => ConstraintCheckerServices::getUniqueValueChecker( $services ), |
|
| 221 | - $config->get( 'WBQualityConstraintsFormatConstraintId' ) |
|
| 222 | - => ConstraintCheckerServices::getFormatChecker( $services ), |
|
| 223 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ) |
|
| 224 | - => ConstraintCheckerServices::getCommonsLinkChecker( $services ), |
|
| 225 | - $config->get( 'WBQualityConstraintsOneOfConstraintId' ) |
|
| 226 | - => ConstraintCheckerServices::getOneOfChecker( $services ), |
|
| 227 | - $config->get( 'WBQualityConstraintsUsedForValuesOnlyConstraintId' ) |
|
| 228 | - => ConstraintCheckerServices::getValueOnlyChecker( $services ), |
|
| 229 | - $config->get( 'WBQualityConstraintsUsedAsReferenceConstraintId' ) |
|
| 230 | - => ConstraintCheckerServices::getReferenceChecker( $services ), |
|
| 231 | - $config->get( 'WBQualityConstraintsNoBoundsConstraintId' ) |
|
| 232 | - => ConstraintCheckerServices::getNoBoundsChecker( $services ), |
|
| 233 | - $config->get( 'WBQualityConstraintsAllowedUnitsConstraintId' ) |
|
| 234 | - => ConstraintCheckerServices::getAllowedUnitsChecker( $services ), |
|
| 235 | - $config->get( 'WBQualityConstraintsSingleBestValueConstraintId' ) |
|
| 236 | - => ConstraintCheckerServices::getSingleBestValueChecker( $services ), |
|
| 237 | - $config->get( 'WBQualityConstraintsAllowedEntityTypesConstraintId' ) |
|
| 238 | - => ConstraintCheckerServices::getEntityTypeChecker( $services ), |
|
| 239 | - $config->get( 'WBQualityConstraintsNoneOfConstraintId' ) |
|
| 240 | - => ConstraintCheckerServices::getNoneOfChecker( $services ), |
|
| 241 | - $config->get( 'WBQualityConstraintsIntegerConstraintId' ) |
|
| 242 | - => ConstraintCheckerServices::getIntegerChecker( $services ), |
|
| 243 | - $config->get( 'WBQualityConstraintsCitationNeededConstraintId' ) |
|
| 244 | - => ConstraintCheckerServices::getCitationNeededChecker( $services ), |
|
| 245 | - $config->get( 'WBQualityConstraintsPropertyScopeConstraintId' ) |
|
| 246 | - => ConstraintCheckerServices::getPropertyScopeChecker( $services ), |
|
| 247 | - $config->get( 'WBQualityConstraintsContemporaryConstraintId' ) |
|
| 248 | - => ConstraintCheckerServices::getContemporaryChecker( $services ), |
|
| 249 | - $config->get( 'WBQualityConstraintsLexemeLanguageConstraintId' ) |
|
| 250 | - => ConstraintCheckerServices::getLexemeLanguageChecker( $services ), |
|
| 251 | - $config->get( 'WBQualityConstraintsLabelInLanguageConstraintId' ) |
|
| 252 | - => ConstraintCheckerServices::getLabelInLanguageChecker( $services ), |
|
| 191 | + $config->get('WBQualityConstraintsConflictsWithConstraintId') |
|
| 192 | + => ConstraintCheckerServices::getConflictsWithChecker($services), |
|
| 193 | + $config->get('WBQualityConstraintsItemRequiresClaimConstraintId') |
|
| 194 | + => ConstraintCheckerServices::getItemChecker($services), |
|
| 195 | + $config->get('WBQualityConstraintsValueRequiresClaimConstraintId') |
|
| 196 | + => ConstraintCheckerServices::getTargetRequiredClaimChecker($services), |
|
| 197 | + $config->get('WBQualityConstraintsSymmetricConstraintId') |
|
| 198 | + => ConstraintCheckerServices::getSymmetricChecker($services), |
|
| 199 | + $config->get('WBQualityConstraintsInverseConstraintId') |
|
| 200 | + => ConstraintCheckerServices::getInverseChecker($services), |
|
| 201 | + $config->get('WBQualityConstraintsUsedAsQualifierConstraintId') |
|
| 202 | + => ConstraintCheckerServices::getQualifierChecker($services), |
|
| 203 | + $config->get('WBQualityConstraintsAllowedQualifiersConstraintId') |
|
| 204 | + => ConstraintCheckerServices::getQualifiersChecker($services), |
|
| 205 | + $config->get('WBQualityConstraintsMandatoryQualifierConstraintId') |
|
| 206 | + => ConstraintCheckerServices::getMandatoryQualifiersChecker($services), |
|
| 207 | + $config->get('WBQualityConstraintsRangeConstraintId') |
|
| 208 | + => ConstraintCheckerServices::getRangeChecker($services), |
|
| 209 | + $config->get('WBQualityConstraintsDifferenceWithinRangeConstraintId') |
|
| 210 | + => ConstraintCheckerServices::getDiffWithinRangeChecker($services), |
|
| 211 | + $config->get('WBQualityConstraintsTypeConstraintId') |
|
| 212 | + => ConstraintCheckerServices::getTypeChecker($services), |
|
| 213 | + $config->get('WBQualityConstraintsValueTypeConstraintId') |
|
| 214 | + => ConstraintCheckerServices::getValueTypeChecker($services), |
|
| 215 | + $config->get('WBQualityConstraintsSingleValueConstraintId') |
|
| 216 | + => ConstraintCheckerServices::getSingleValueChecker($services), |
|
| 217 | + $config->get('WBQualityConstraintsMultiValueConstraintId') |
|
| 218 | + => ConstraintCheckerServices::getMultiValueChecker($services), |
|
| 219 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId') |
|
| 220 | + => ConstraintCheckerServices::getUniqueValueChecker($services), |
|
| 221 | + $config->get('WBQualityConstraintsFormatConstraintId') |
|
| 222 | + => ConstraintCheckerServices::getFormatChecker($services), |
|
| 223 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId') |
|
| 224 | + => ConstraintCheckerServices::getCommonsLinkChecker($services), |
|
| 225 | + $config->get('WBQualityConstraintsOneOfConstraintId') |
|
| 226 | + => ConstraintCheckerServices::getOneOfChecker($services), |
|
| 227 | + $config->get('WBQualityConstraintsUsedForValuesOnlyConstraintId') |
|
| 228 | + => ConstraintCheckerServices::getValueOnlyChecker($services), |
|
| 229 | + $config->get('WBQualityConstraintsUsedAsReferenceConstraintId') |
|
| 230 | + => ConstraintCheckerServices::getReferenceChecker($services), |
|
| 231 | + $config->get('WBQualityConstraintsNoBoundsConstraintId') |
|
| 232 | + => ConstraintCheckerServices::getNoBoundsChecker($services), |
|
| 233 | + $config->get('WBQualityConstraintsAllowedUnitsConstraintId') |
|
| 234 | + => ConstraintCheckerServices::getAllowedUnitsChecker($services), |
|
| 235 | + $config->get('WBQualityConstraintsSingleBestValueConstraintId') |
|
| 236 | + => ConstraintCheckerServices::getSingleBestValueChecker($services), |
|
| 237 | + $config->get('WBQualityConstraintsAllowedEntityTypesConstraintId') |
|
| 238 | + => ConstraintCheckerServices::getEntityTypeChecker($services), |
|
| 239 | + $config->get('WBQualityConstraintsNoneOfConstraintId') |
|
| 240 | + => ConstraintCheckerServices::getNoneOfChecker($services), |
|
| 241 | + $config->get('WBQualityConstraintsIntegerConstraintId') |
|
| 242 | + => ConstraintCheckerServices::getIntegerChecker($services), |
|
| 243 | + $config->get('WBQualityConstraintsCitationNeededConstraintId') |
|
| 244 | + => ConstraintCheckerServices::getCitationNeededChecker($services), |
|
| 245 | + $config->get('WBQualityConstraintsPropertyScopeConstraintId') |
|
| 246 | + => ConstraintCheckerServices::getPropertyScopeChecker($services), |
|
| 247 | + $config->get('WBQualityConstraintsContemporaryConstraintId') |
|
| 248 | + => ConstraintCheckerServices::getContemporaryChecker($services), |
|
| 249 | + $config->get('WBQualityConstraintsLexemeLanguageConstraintId') |
|
| 250 | + => ConstraintCheckerServices::getLexemeLanguageChecker($services), |
|
| 251 | + $config->get('WBQualityConstraintsLabelInLanguageConstraintId') |
|
| 252 | + => ConstraintCheckerServices::getLabelInLanguageChecker($services), |
|
| 253 | 253 | ]; |
| 254 | 254 | |
| 255 | 255 | return new DelegatingConstraintChecker( |
| 256 | - WikibaseServices::getEntityLookup( $services ), |
|
| 256 | + WikibaseServices::getEntityLookup($services), |
|
| 257 | 257 | $checkerMap, |
| 258 | - ConstraintsServices::getConstraintLookup( $services ), |
|
| 259 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
| 258 | + ConstraintsServices::getConstraintLookup($services), |
|
| 259 | + ConstraintsServices::getConstraintParameterParser($services), |
|
| 260 | 260 | $statementGuidParser, |
| 261 | - ConstraintsServices::getLoggingHelper( $services ), |
|
| 262 | - $config->get( 'WBQualityConstraintsCheckQualifiers' ), |
|
| 263 | - $config->get( 'WBQualityConstraintsCheckReferences' ), |
|
| 264 | - $config->get( 'WBQualityConstraintsPropertiesWithViolatingQualifiers' ) |
|
| 261 | + ConstraintsServices::getLoggingHelper($services), |
|
| 262 | + $config->get('WBQualityConstraintsCheckQualifiers'), |
|
| 263 | + $config->get('WBQualityConstraintsCheckReferences'), |
|
| 264 | + $config->get('WBQualityConstraintsPropertiesWithViolatingQualifiers') |
|
| 265 | 265 | ); |
| 266 | 266 | }, |
| 267 | 267 | |
| 268 | - ConstraintsServices::RESULTS_SOURCE => static function ( MediaWikiServices $services ): ResultsSource { |
|
| 268 | + ConstraintsServices::RESULTS_SOURCE => static function(MediaWikiServices $services): ResultsSource { |
|
| 269 | 269 | $config = $services->getMainConfig(); |
| 270 | 270 | $resultsSource = new CheckingResultsSource( |
| 271 | - ConstraintsServices::getDelegatingConstraintChecker( $services ) |
|
| 271 | + ConstraintsServices::getDelegatingConstraintChecker($services) |
|
| 272 | 272 | ); |
| 273 | 273 | |
| 274 | 274 | $cacheCheckConstraintsResults = false; |
| 275 | 275 | |
| 276 | - if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) { |
|
| 276 | + if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) { |
|
| 277 | 277 | $cacheCheckConstraintsResults = true; |
| 278 | 278 | // check that we can use getLocalRepoWikiPageMetaDataAccessor() |
| 279 | 279 | // TODO we should always be able to cache constraint check results (T244726) |
| 280 | - $entitySources = WikibaseRepo::getEntitySourceDefinitions( $services )->getSources(); |
|
| 281 | - $localEntitySourceName = WikibaseRepo::getLocalEntitySource( $services )->getSourceName(); |
|
| 280 | + $entitySources = WikibaseRepo::getEntitySourceDefinitions($services)->getSources(); |
|
| 281 | + $localEntitySourceName = WikibaseRepo::getLocalEntitySource($services)->getSourceName(); |
|
| 282 | 282 | |
| 283 | - foreach ( $entitySources as $entitySource ) { |
|
| 284 | - if ( $entitySource->getSourceName() !== $localEntitySourceName ) { |
|
| 285 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' )->warning( |
|
| 286 | - 'Cannot cache constraint check results for non-local source: ' . |
|
| 283 | + foreach ($entitySources as $entitySource) { |
|
| 284 | + if ($entitySource->getSourceName() !== $localEntitySourceName) { |
|
| 285 | + LoggerFactory::getInstance('WikibaseQualityConstraints')->warning( |
|
| 286 | + 'Cannot cache constraint check results for non-local source: '. |
|
| 287 | 287 | $entitySource->getSourceName() |
| 288 | 288 | ); |
| 289 | 289 | $cacheCheckConstraintsResults = false; |
@@ -292,42 +292,42 @@ discard block |
||
| 292 | 292 | } |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - if ( $cacheCheckConstraintsResults ) { |
|
| 295 | + if ($cacheCheckConstraintsResults) { |
|
| 296 | 296 | $possiblyStaleConstraintTypes = [ |
| 297 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ), |
|
| 298 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ), |
|
| 299 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ), |
|
| 300 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ), |
|
| 297 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId'), |
|
| 298 | + $config->get('WBQualityConstraintsTypeConstraintId'), |
|
| 299 | + $config->get('WBQualityConstraintsValueTypeConstraintId'), |
|
| 300 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId'), |
|
| 301 | 301 | ]; |
| 302 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
| 302 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
| 303 | 303 | $wikiPageEntityMetaDataAccessor = WikibaseRepo::getLocalRepoWikiPageMetaDataAccessor( |
| 304 | 304 | $services ); |
| 305 | 305 | |
| 306 | 306 | $resultsSource = new CachingResultsSource( |
| 307 | 307 | $resultsSource, |
| 308 | 308 | ResultsCache::getDefaultInstance(), |
| 309 | - ConstraintsServices::getCheckResultSerializer( $services ), |
|
| 310 | - ConstraintsServices::getCheckResultDeserializer( $services ), |
|
| 309 | + ConstraintsServices::getCheckResultSerializer($services), |
|
| 310 | + ConstraintsServices::getCheckResultDeserializer($services), |
|
| 311 | 311 | $wikiPageEntityMetaDataAccessor, |
| 312 | 312 | $entityIdParser, |
| 313 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ), |
|
| 313 | + $config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'), |
|
| 314 | 314 | $possiblyStaleConstraintTypes, |
| 315 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds' ), |
|
| 316 | - ConstraintsServices::getLoggingHelper( $services ) |
|
| 315 | + $config->get('WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds'), |
|
| 316 | + ConstraintsServices::getLoggingHelper($services) |
|
| 317 | 317 | ); |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | return $resultsSource; |
| 321 | 321 | }, |
| 322 | 322 | |
| 323 | - ConstraintsServices::VIOLATION_MESSAGE_RENDERER_FACTORY => static function ( |
|
| 323 | + ConstraintsServices::VIOLATION_MESSAGE_RENDERER_FACTORY => static function( |
|
| 324 | 324 | MediaWikiServices $services |
| 325 | 325 | ): ViolationMessageRendererFactory { |
| 326 | 326 | return new ViolationMessageRendererFactory( |
| 327 | 327 | $services->getMainConfig(), |
| 328 | 328 | $services->getLanguageNameUtils(), |
| 329 | - WikibaseRepo::getEntityIdHtmlLinkFormatterFactory( $services ), |
|
| 330 | - WikibaseRepo::getValueFormatterFactory( $services ) |
|
| 329 | + WikibaseRepo::getEntityIdHtmlLinkFormatterFactory($services), |
|
| 330 | + WikibaseRepo::getValueFormatterFactory($services) |
|
| 331 | 331 | ); |
| 332 | 332 | }, |
| 333 | 333 | ]; |
@@ -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\Helper; |
| 6 | 6 | |
@@ -166,143 +166,143 @@ discard block |
||
| 166 | 166 | $this->defaultUserAgent = $defaultUserAgent; |
| 167 | 167 | $this->requestFactory = $requestFactory; |
| 168 | 168 | $this->entityPrefixes = []; |
| 169 | - foreach ( $rdfVocabulary->entityNamespaceNames as $namespaceName ) { |
|
| 170 | - $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI( $namespaceName ); |
|
| 169 | + foreach ($rdfVocabulary->entityNamespaceNames as $namespaceName) { |
|
| 170 | + $this->entityPrefixes[] = $rdfVocabulary->getNamespaceURI($namespaceName); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - $this->primaryEndpoint = $config->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
| 174 | - $this->additionalEndpoints = $config->get( 'WBQualityConstraintsAdditionalSparqlEndpoints' ) ?: []; |
|
| 175 | - $this->maxQueryTimeMillis = $config->get( 'WBQualityConstraintsSparqlMaxMillis' ); |
|
| 176 | - $this->subclassOfId = new NumericPropertyId( $config->get( 'WBQualityConstraintsSubclassOfId' ) ); |
|
| 177 | - $this->cacheMapSize = $config->get( 'WBQualityConstraintsFormatCacheMapSize' ); |
|
| 173 | + $this->primaryEndpoint = $config->get('WBQualityConstraintsSparqlEndpoint'); |
|
| 174 | + $this->additionalEndpoints = $config->get('WBQualityConstraintsAdditionalSparqlEndpoints') ?: []; |
|
| 175 | + $this->maxQueryTimeMillis = $config->get('WBQualityConstraintsSparqlMaxMillis'); |
|
| 176 | + $this->subclassOfId = new NumericPropertyId($config->get('WBQualityConstraintsSubclassOfId')); |
|
| 177 | + $this->cacheMapSize = $config->get('WBQualityConstraintsFormatCacheMapSize'); |
|
| 178 | 178 | $this->timeoutExceptionClasses = $config->get( |
| 179 | 179 | 'WBQualityConstraintsSparqlTimeoutExceptionClasses' |
| 180 | 180 | ); |
| 181 | 181 | $this->sparqlHasWikibaseSupport = $config->get( |
| 182 | 182 | 'WBQualityConstraintsSparqlHasWikibaseSupport' |
| 183 | 183 | ); |
| 184 | - $this->sparqlThrottlingFallbackDuration = (int)$config->get( |
|
| 184 | + $this->sparqlThrottlingFallbackDuration = (int) $config->get( |
|
| 185 | 185 | 'WBQualityConstraintsSparqlThrottlingFallbackDuration' |
| 186 | 186 | ); |
| 187 | 187 | |
| 188 | - $this->prefixes = $this->getQueryPrefixes( $rdfVocabulary ); |
|
| 188 | + $this->prefixes = $this->getQueryPrefixes($rdfVocabulary); |
|
| 189 | 189 | |
| 190 | 190 | $this->rdfVocabularyWithoutNormalization = clone $rdfVocabulary; |
| 191 | 191 | // @phan-suppress-next-line PhanTypeMismatchProperty |
| 192 | 192 | $this->rdfVocabularyWithoutNormalization->normalizedPropertyValueNamespace = array_fill_keys( |
| 193 | - array_keys( $rdfVocabulary->normalizedPropertyValueNamespace ), |
|
| 193 | + array_keys($rdfVocabulary->normalizedPropertyValueNamespace), |
|
| 194 | 194 | null |
| 195 | 195 | ); |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | - private function getQueryPrefixes( RdfVocabulary $rdfVocabulary ): string { |
|
| 198 | + private function getQueryPrefixes(RdfVocabulary $rdfVocabulary): string { |
|
| 199 | 199 | // TODO: it would probably be smarter that RdfVocabulary exposed these prefixes somehow |
| 200 | 200 | $prefixes = ''; |
| 201 | - foreach ( $rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName ) { |
|
| 201 | + foreach ($rdfVocabulary->entityNamespaceNames as $sourceName => $namespaceName) { |
|
| 202 | 202 | $prefixes .= <<<END |
| 203 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
| 203 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
| 204 | 204 | END; |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - foreach ( $rdfVocabulary->statementNamespaceNames as $sourceName => $sourceNamespaces ) { |
|
| 207 | + foreach ($rdfVocabulary->statementNamespaceNames as $sourceName => $sourceNamespaces) { |
|
| 208 | 208 | $namespaceName = $sourceNamespaces[RdfVocabulary::NS_VALUE]; |
| 209 | 209 | $prefixes .= <<<END |
| 210 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
| 210 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
| 211 | 211 | END; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - foreach ( $rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces ) { |
|
| 214 | + foreach ($rdfVocabulary->propertyNamespaceNames as $sourceName => $sourceNamespaces) { |
|
| 215 | 215 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_DIRECT_CLAIM]; |
| 216 | 216 | $prefixes .= <<<END |
| 217 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
| 217 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
| 218 | 218 | END; |
| 219 | 219 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM]; |
| 220 | 220 | $prefixes .= <<<END |
| 221 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
| 221 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
| 222 | 222 | END; |
| 223 | 223 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM_STATEMENT]; |
| 224 | 224 | $prefixes .= <<<END |
| 225 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
| 225 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
| 226 | 226 | END; |
| 227 | 227 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_CLAIM_VALUE]; |
| 228 | 228 | $prefixes .= <<<END |
| 229 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
| 229 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
| 230 | 230 | END; |
| 231 | 231 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER]; |
| 232 | 232 | $prefixes .= <<<END |
| 233 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
| 233 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
| 234 | 234 | END; |
| 235 | 235 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_QUALIFIER_VALUE]; |
| 236 | 236 | $prefixes .= <<<END |
| 237 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
| 237 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
| 238 | 238 | END; |
| 239 | 239 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE]; |
| 240 | 240 | $prefixes .= <<<END |
| 241 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
| 241 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
| 242 | 242 | END; |
| 243 | 243 | $namespaceName = $sourceNamespaces[RdfVocabulary::NSP_REFERENCE_VALUE]; |
| 244 | 244 | $prefixes .= <<<END |
| 245 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
| 245 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
| 246 | 246 | END; |
| 247 | 247 | } |
| 248 | 248 | $namespaceName = RdfVocabulary::NS_ONTOLOGY; |
| 249 | 249 | $prefixes .= <<<END |
| 250 | -PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI( $namespaceName )}>\n |
|
| 250 | +PREFIX {$namespaceName}: <{$rdfVocabulary->getNamespaceURI($namespaceName)}>\n |
|
| 251 | 251 | END; |
| 252 | 252 | return $prefixes; |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** Return a SPARQL term like `wd:Q123` for the given ID. */ |
| 256 | - private function wd( EntityId $id ): string { |
|
| 257 | - $repository = $this->rdfVocabulary->getEntityRepositoryName( $id ); |
|
| 256 | + private function wd(EntityId $id): string { |
|
| 257 | + $repository = $this->rdfVocabulary->getEntityRepositoryName($id); |
|
| 258 | 258 | $prefix = $this->rdfVocabulary->entityNamespaceNames[$repository]; |
| 259 | 259 | return "$prefix:{$id->getSerialization()}"; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** Return a SPARQL term like `wdt:P123` for the given ID. */ |
| 263 | - private function wdt( PropertyId $id ): string { |
|
| 264 | - $repository = $this->rdfVocabulary->getEntityRepositoryName( $id ); |
|
| 263 | + private function wdt(PropertyId $id): string { |
|
| 264 | + $repository = $this->rdfVocabulary->getEntityRepositoryName($id); |
|
| 265 | 265 | $prefix = $this->rdfVocabulary->propertyNamespaceNames[$repository][RdfVocabulary::NSP_DIRECT_CLAIM]; |
| 266 | 266 | return "$prefix:{$id->getSerialization()}"; |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** Return a SPARQL term like `p:P123` for the given ID. */ |
| 270 | - private function p( PropertyId $id ): string { |
|
| 271 | - $repository = $this->rdfVocabulary->getEntityRepositoryName( $id ); |
|
| 270 | + private function p(PropertyId $id): string { |
|
| 271 | + $repository = $this->rdfVocabulary->getEntityRepositoryName($id); |
|
| 272 | 272 | $prefix = $this->rdfVocabulary->propertyNamespaceNames[$repository][RdfVocabulary::NSP_CLAIM]; |
| 273 | 273 | return "$prefix:{$id->getSerialization()}"; |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** Return a SPARQL term like `pq:P123` for the given ID. */ |
| 277 | - private function pq( PropertyId $id ): string { |
|
| 278 | - $repository = $this->rdfVocabulary->getEntityRepositoryName( $id ); |
|
| 277 | + private function pq(PropertyId $id): string { |
|
| 278 | + $repository = $this->rdfVocabulary->getEntityRepositoryName($id); |
|
| 279 | 279 | $prefix = $this->rdfVocabulary->propertyNamespaceNames[$repository][RdfVocabulary::NSP_QUALIFIER]; |
| 280 | 280 | return "$prefix:{$id->getSerialization()}"; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** Return a SPARQL term like `wdno:P123` for the given ID. */ |
| 284 | - private function wdno( PropertyId $id ): string { |
|
| 285 | - $repository = $this->rdfVocabulary->getEntityRepositoryName( $id ); |
|
| 284 | + private function wdno(PropertyId $id): string { |
|
| 285 | + $repository = $this->rdfVocabulary->getEntityRepositoryName($id); |
|
| 286 | 286 | $prefix = $this->rdfVocabulary->propertyNamespaceNames[$repository][RdfVocabulary::NSP_NOVALUE]; |
| 287 | 287 | return "$prefix:{$id->getSerialization()}"; |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** Return a SPARQL term like `prov:NAME` for the given name. */ |
| 291 | - private function prov( string $name ): string { |
|
| 291 | + private function prov(string $name): string { |
|
| 292 | 292 | $prefix = RdfVocabulary::NS_PROV; |
| 293 | 293 | return "$prefix:$name"; |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | /** Return a SPARQL term like `wikibase:NAME` for the given name. */ |
| 297 | - private function wikibase( string $name ): string { |
|
| 297 | + private function wikibase(string $name): string { |
|
| 298 | 298 | $prefix = RdfVocabulary::NS_ONTOLOGY; |
| 299 | 299 | return "$prefix:$name"; |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | /** Return a SPARQL snippet like `MINUS { ?var wikibase:rank wikibase:DeprecatedRank. }`. */ |
| 303 | - private function minusDeprecatedRank( string $varName ): string { |
|
| 303 | + private function minusDeprecatedRank(string $varName): string { |
|
| 304 | 304 | $deprecatedRank = RdfVocabulary::RANK_MAP[Statement::RANK_DEPRECATED]; |
| 305 | - return "MINUS { $varName {$this->wikibase( 'rank' )} {$this->wikibase( $deprecatedRank )}. }"; |
|
| 305 | + return "MINUS { $varName {$this->wikibase('rank')} {$this->wikibase($deprecatedRank)}. }"; |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -312,43 +312,42 @@ discard block |
||
| 312 | 312 | * @return CachedBool |
| 313 | 313 | * @throws SparqlHelperException if the query times out or some other error occurs |
| 314 | 314 | */ |
| 315 | - public function hasType( EntityId $id, array $classes ): CachedBool { |
|
| 315 | + public function hasType(EntityId $id, array $classes): CachedBool { |
|
| 316 | 316 | // TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually |
| 317 | 317 | $gearingHint = $this->sparqlHasWikibaseSupport ? |
| 318 | - ' hint:Prior hint:gearing "forward".' : |
|
| 319 | - ''; |
|
| 318 | + ' hint:Prior hint:gearing "forward".' : ''; |
|
| 320 | 319 | |
| 321 | 320 | $metadatas = []; |
| 322 | 321 | |
| 323 | - foreach ( array_chunk( $classes, 20 ) as $classesChunk ) { |
|
| 324 | - $classesValues = implode( ' ', array_map( |
|
| 325 | - function ( string $class ) { |
|
| 326 | - return $this->wd( new ItemId( $class ) ); |
|
| 322 | + foreach (array_chunk($classes, 20) as $classesChunk) { |
|
| 323 | + $classesValues = implode(' ', array_map( |
|
| 324 | + function(string $class) { |
|
| 325 | + return $this->wd(new ItemId($class)); |
|
| 327 | 326 | }, |
| 328 | 327 | $classesChunk |
| 329 | - ) ); |
|
| 328 | + )); |
|
| 330 | 329 | |
| 331 | 330 | $query = <<<EOF |
| 332 | 331 | ASK { |
| 333 | - BIND({$this->wd( $id )} AS ?item) |
|
| 332 | + BIND({$this->wd($id)} AS ?item) |
|
| 334 | 333 | VALUES ?class { $classesValues } |
| 335 | - ?item {$this->wdt( $this->subclassOfId )}* ?class.$gearingHint |
|
| 334 | + ?item {$this->wdt($this->subclassOfId)}* ?class.$gearingHint |
|
| 336 | 335 | } |
| 337 | 336 | EOF; |
| 338 | 337 | |
| 339 | - $result = $this->runQuery( $query, $this->primaryEndpoint ); |
|
| 338 | + $result = $this->runQuery($query, $this->primaryEndpoint); |
|
| 340 | 339 | $metadatas[] = $result->getMetadata(); |
| 341 | - if ( $result->getArray()['boolean'] ) { |
|
| 340 | + if ($result->getArray()['boolean']) { |
|
| 342 | 341 | return new CachedBool( |
| 343 | 342 | true, |
| 344 | - Metadata::merge( $metadatas ) |
|
| 343 | + Metadata::merge($metadatas) |
|
| 345 | 344 | ); |
| 346 | 345 | } |
| 347 | 346 | } |
| 348 | 347 | |
| 349 | 348 | return new CachedBool( |
| 350 | 349 | false, |
| 351 | - Metadata::merge( $metadatas ) |
|
| 350 | + Metadata::merge($metadatas) |
|
| 352 | 351 | ); |
| 353 | 352 | } |
| 354 | 353 | |
@@ -365,12 +364,12 @@ discard block |
||
| 365 | 364 | array $separators |
| 366 | 365 | ): CachedEntityIds { |
| 367 | 366 | $mainSnak = $statement->getMainSnak(); |
| 368 | - if ( !( $mainSnak instanceof PropertyValueSnak ) ) { |
|
| 369 | - return new CachedEntityIds( [], Metadata::blank() ); |
|
| 367 | + if (!($mainSnak instanceof PropertyValueSnak)) { |
|
| 368 | + return new CachedEntityIds([], Metadata::blank()); |
|
| 370 | 369 | } |
| 371 | 370 | |
| 372 | 371 | $propertyId = $statement->getPropertyId(); |
| 373 | - $pPredicateAndObject = "{$this->p( $propertyId )} ?otherStatement."; // p:P123 ?otherStatement. |
|
| 372 | + $pPredicateAndObject = "{$this->p($propertyId)} ?otherStatement."; // p:P123 ?otherStatement. |
|
| 374 | 373 | $otherStatementPredicateAndObject = $this->getSnakPredicateAndObject( |
| 375 | 374 | $entityId, |
| 376 | 375 | $mainSnak, |
@@ -379,57 +378,57 @@ discard block |
||
| 379 | 378 | |
| 380 | 379 | $isSeparator = []; |
| 381 | 380 | $unusedSeparators = []; |
| 382 | - foreach ( $separators as $separator ) { |
|
| 381 | + foreach ($separators as $separator) { |
|
| 383 | 382 | $isSeparator[$separator->getSerialization()] = true; |
| 384 | 383 | $unusedSeparators[$separator->getSerialization()] = $separator; |
| 385 | 384 | } |
| 386 | 385 | $separatorFilters = ''; |
| 387 | - foreach ( $statement->getQualifiers() as $qualifier ) { |
|
| 386 | + foreach ($statement->getQualifiers() as $qualifier) { |
|
| 388 | 387 | $qualPropertyId = $qualifier->getPropertyId(); |
| 389 | - if ( !( $isSeparator[$qualPropertyId->getSerialization()] ?? false ) ) { |
|
| 388 | + if (!($isSeparator[$qualPropertyId->getSerialization()] ?? false)) { |
|
| 390 | 389 | continue; |
| 391 | 390 | } |
| 392 | - unset( $unusedSeparators[$qualPropertyId->getSerialization()] ); |
|
| 391 | + unset($unusedSeparators[$qualPropertyId->getSerialization()]); |
|
| 393 | 392 | // only look for other statements with the same qualifier |
| 394 | - if ( $qualifier instanceof PropertyValueSnak ) { |
|
| 393 | + if ($qualifier instanceof PropertyValueSnak) { |
|
| 395 | 394 | $sepPredicateAndObject = $this->getSnakPredicateAndObject( |
| 396 | 395 | $entityId, |
| 397 | 396 | $qualifier, |
| 398 | 397 | RdfVocabulary::NSP_QUALIFIER |
| 399 | 398 | ); |
| 400 | 399 | $separatorFilters .= " ?otherStatement $sepPredicateAndObject\n"; |
| 401 | - } elseif ( $qualifier instanceof PropertyNoValueSnak ) { |
|
| 402 | - $sepPredicateAndObject = "a {$this->wdno( $qualPropertyId )}."; // a wdno:P123. |
|
| 400 | + } elseif ($qualifier instanceof PropertyNoValueSnak) { |
|
| 401 | + $sepPredicateAndObject = "a {$this->wdno($qualPropertyId)}."; // a wdno:P123. |
|
| 403 | 402 | $separatorFilters .= " ?otherStatement $sepPredicateAndObject\n"; |
| 404 | 403 | } else { |
| 405 | 404 | // "some value" / "unknown value" is always different from everything else, |
| 406 | 405 | // therefore the whole statement has no duplicates and we can return immediately |
| 407 | - return new CachedEntityIds( [], Metadata::blank() ); |
|
| 406 | + return new CachedEntityIds([], Metadata::blank()); |
|
| 408 | 407 | } |
| 409 | 408 | } |
| 410 | - foreach ( $unusedSeparators as $unusedSeparator ) { |
|
| 409 | + foreach ($unusedSeparators as $unusedSeparator) { |
|
| 411 | 410 | // exclude other statements which have a separator that this one lacks |
| 412 | - $separatorFilters .= " MINUS { ?otherStatement {$this->pq( $unusedSeparator )} []. }\n"; |
|
| 413 | - $separatorFilters .= " MINUS { ?otherStatement a {$this->wdno( $unusedSeparator )}. }\n"; |
|
| 411 | + $separatorFilters .= " MINUS { ?otherStatement {$this->pq($unusedSeparator)} []. }\n"; |
|
| 412 | + $separatorFilters .= " MINUS { ?otherStatement a {$this->wdno($unusedSeparator)}. }\n"; |
|
| 414 | 413 | } |
| 415 | 414 | |
| 416 | 415 | $query = <<<SPARQL |
| 417 | 416 | SELECT DISTINCT ?otherEntity WHERE { |
| 418 | 417 | ?otherEntity $pPredicateAndObject |
| 419 | 418 | ?otherStatement $otherStatementPredicateAndObject |
| 420 | - {$this->minusDeprecatedRank( '?otherStatement' )} |
|
| 421 | - FILTER(?otherEntity != {$this->wd( $entityId )}) |
|
| 419 | + {$this->minusDeprecatedRank('?otherStatement')} |
|
| 420 | + FILTER(?otherEntity != {$this->wd($entityId)}) |
|
| 422 | 421 | $separatorFilters |
| 423 | 422 | } |
| 424 | 423 | LIMIT 10 |
| 425 | 424 | SPARQL; |
| 426 | 425 | |
| 427 | - $results = [ $this->runQuery( $query, $this->primaryEndpoint ) ]; |
|
| 428 | - foreach ( $this->additionalEndpoints as $endpoint ) { |
|
| 429 | - $results[] = $this->runQuery( $query, $endpoint ); |
|
| 426 | + $results = [$this->runQuery($query, $this->primaryEndpoint)]; |
|
| 427 | + foreach ($this->additionalEndpoints as $endpoint) { |
|
| 428 | + $results[] = $this->runQuery($query, $endpoint); |
|
| 430 | 429 | } |
| 431 | 430 | |
| 432 | - return $this->getOtherEntities( $results ); |
|
| 431 | + return $this->getOtherEntities($results); |
|
| 433 | 432 | } |
| 434 | 433 | |
| 435 | 434 | /** |
@@ -448,40 +447,38 @@ discard block |
||
| 448 | 447 | bool $ignoreDeprecatedStatements |
| 449 | 448 | ): CachedEntityIds { |
| 450 | 449 | $propertyId = $snak->getPropertyId(); |
| 451 | - $pPredicateAndObject = "{$this->p( $propertyId )} ?otherStatement."; // p:P123 ?otherStatement. |
|
| 450 | + $pPredicateAndObject = "{$this->p($propertyId)} ?otherStatement."; // p:P123 ?otherStatement. |
|
| 452 | 451 | |
| 453 | 452 | $otherSubject = $type === Context::TYPE_QUALIFIER ? |
| 454 | - '?otherStatement' : |
|
| 455 | - "?otherStatement {$this->prov( 'wasDerivedFrom' )} ?reference.\n ?reference"; |
|
| 453 | + '?otherStatement' : "?otherStatement {$this->prov('wasDerivedFrom')} ?reference.\n ?reference"; |
|
| 456 | 454 | $otherPredicateAndObject = $this->getSnakPredicateAndObject( |
| 457 | 455 | $entityId, |
| 458 | 456 | $snak, |
| 459 | 457 | $type === Context::TYPE_QUALIFIER ? |
| 460 | - RdfVocabulary::NSP_QUALIFIER : |
|
| 461 | - RdfVocabulary::NSP_REFERENCE |
|
| 458 | + RdfVocabulary::NSP_QUALIFIER : RdfVocabulary::NSP_REFERENCE |
|
| 462 | 459 | ); |
| 463 | 460 | |
| 464 | 461 | $deprecatedFilter = ''; |
| 465 | - if ( $ignoreDeprecatedStatements ) { |
|
| 466 | - $deprecatedFilter = ' ' . $this->minusDeprecatedRank( '?otherStatement' ); |
|
| 462 | + if ($ignoreDeprecatedStatements) { |
|
| 463 | + $deprecatedFilter = ' '.$this->minusDeprecatedRank('?otherStatement'); |
|
| 467 | 464 | } |
| 468 | 465 | |
| 469 | 466 | $query = <<<SPARQL |
| 470 | 467 | SELECT DISTINCT ?otherEntity WHERE { |
| 471 | 468 | ?otherEntity $pPredicateAndObject |
| 472 | 469 | $otherSubject $otherPredicateAndObject |
| 473 | - FILTER(?otherEntity != {$this->wd( $entityId )}) |
|
| 470 | + FILTER(?otherEntity != {$this->wd($entityId)}) |
|
| 474 | 471 | $deprecatedFilter |
| 475 | 472 | } |
| 476 | 473 | LIMIT 10 |
| 477 | 474 | SPARQL; |
| 478 | 475 | |
| 479 | - $results = [ $this->runQuery( $query, $this->primaryEndpoint ) ]; |
|
| 480 | - foreach ( $this->additionalEndpoints as $endpoint ) { |
|
| 481 | - $results[] = $this->runQuery( $query, $endpoint ); |
|
| 476 | + $results = [$this->runQuery($query, $this->primaryEndpoint)]; |
|
| 477 | + foreach ($this->additionalEndpoints as $endpoint) { |
|
| 478 | + $results[] = $this->runQuery($query, $endpoint); |
|
| 482 | 479 | } |
| 483 | 480 | |
| 484 | - return $this->getOtherEntities( $results ); |
|
| 481 | + return $this->getOtherEntities($results); |
|
| 485 | 482 | } |
| 486 | 483 | |
| 487 | 484 | /** |
@@ -512,13 +509,13 @@ discard block |
||
| 512 | 509 | $writer->start(); |
| 513 | 510 | $writer->drain(); |
| 514 | 511 | $placeholder1 = 'wbqc'; |
| 515 | - $placeholder2 = 'x' . wfRandomString( 32 ); |
|
| 516 | - $writer->about( $placeholder1, $placeholder2 ); |
|
| 512 | + $placeholder2 = 'x'.wfRandomString(32); |
|
| 513 | + $writer->about($placeholder1, $placeholder2); |
|
| 517 | 514 | |
| 518 | 515 | $propertyId = $snak->getPropertyId(); |
| 519 | 516 | $pid = $propertyId->getSerialization(); |
| 520 | - $propertyRepository = $this->rdfVocabulary->getEntityRepositoryName( $propertyId ); |
|
| 521 | - $entityRepository = $this->rdfVocabulary->getEntityRepositoryName( $entityId ); |
|
| 517 | + $propertyRepository = $this->rdfVocabulary->getEntityRepositoryName($propertyId); |
|
| 518 | + $entityRepository = $this->rdfVocabulary->getEntityRepositoryName($entityId); |
|
| 522 | 519 | $propertyNamespace = $this->rdfVocabulary->propertyNamespaceNames[$propertyRepository][$namespace]; |
| 523 | 520 | $value = $snak->getDataValue(); |
| 524 | 521 | if ( |
@@ -549,21 +546,21 @@ discard block |
||
| 549 | 546 | $writer, |
| 550 | 547 | $propertyNamespace, |
| 551 | 548 | $pid, |
| 552 | - $this->propertyDataTypeLookup->getDataTypeIdForProperty( $propertyId ), |
|
| 549 | + $this->propertyDataTypeLookup->getDataTypeIdForProperty($propertyId), |
|
| 553 | 550 | $this->rdfVocabulary->statementNamespaceNames[$entityRepository][RdfVocabulary::NS_VALUE], // should be unused |
| 554 | 551 | $snak |
| 555 | 552 | ); |
| 556 | 553 | } |
| 557 | 554 | |
| 558 | 555 | $triple = $writer->drain(); // wbqc:xRANDOM ps:PID "value". or similar |
| 559 | - return trim( str_replace( "$placeholder1:$placeholder2", '', $triple ) ); |
|
| 556 | + return trim(str_replace("$placeholder1:$placeholder2", '', $triple)); |
|
| 560 | 557 | } |
| 561 | 558 | |
| 562 | 559 | /** |
| 563 | 560 | * Return SPARQL code for a string literal with $text as content. |
| 564 | 561 | */ |
| 565 | - private function stringLiteral( string $text ): string { |
|
| 566 | - return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"'; |
|
| 562 | + private function stringLiteral(string $text): string { |
|
| 563 | + return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"'; |
|
| 567 | 564 | } |
| 568 | 565 | |
| 569 | 566 | /** |
@@ -573,26 +570,26 @@ discard block |
||
| 573 | 570 | * |
| 574 | 571 | * @return CachedEntityIds |
| 575 | 572 | */ |
| 576 | - private function getOtherEntities( array $results ): CachedEntityIds { |
|
| 573 | + private function getOtherEntities(array $results): CachedEntityIds { |
|
| 577 | 574 | $allResultBindings = []; |
| 578 | 575 | $metadatas = []; |
| 579 | 576 | |
| 580 | - foreach ( $results as $result ) { |
|
| 577 | + foreach ($results as $result) { |
|
| 581 | 578 | $metadatas[] = $result->getMetadata(); |
| 582 | - $allResultBindings = array_merge( $allResultBindings, $result->getArray()['results']['bindings'] ); |
|
| 579 | + $allResultBindings = array_merge($allResultBindings, $result->getArray()['results']['bindings']); |
|
| 583 | 580 | } |
| 584 | 581 | |
| 585 | 582 | $entityIds = array_map( |
| 586 | - function ( $resultBindings ) { |
|
| 583 | + function($resultBindings) { |
|
| 587 | 584 | $entityIRI = $resultBindings['otherEntity']['value']; |
| 588 | - foreach ( $this->entityPrefixes as $entityPrefix ) { |
|
| 589 | - $entityPrefixLength = strlen( $entityPrefix ); |
|
| 590 | - if ( substr( $entityIRI, 0, $entityPrefixLength ) === $entityPrefix ) { |
|
| 585 | + foreach ($this->entityPrefixes as $entityPrefix) { |
|
| 586 | + $entityPrefixLength = strlen($entityPrefix); |
|
| 587 | + if (substr($entityIRI, 0, $entityPrefixLength) === $entityPrefix) { |
|
| 591 | 588 | try { |
| 592 | 589 | return $this->entityIdParser->parse( |
| 593 | - substr( $entityIRI, $entityPrefixLength ) |
|
| 590 | + substr($entityIRI, $entityPrefixLength) |
|
| 594 | 591 | ); |
| 595 | - } catch ( EntityIdParsingException $e ) { |
|
| 592 | + } catch (EntityIdParsingException $e) { |
|
| 596 | 593 | // fall through |
| 597 | 594 | } |
| 598 | 595 | } |
@@ -606,8 +603,8 @@ discard block |
||
| 606 | 603 | ); |
| 607 | 604 | |
| 608 | 605 | return new CachedEntityIds( |
| 609 | - array_values( array_filter( array_unique( $entityIds ) ) ), |
|
| 610 | - Metadata::merge( $metadatas ) |
|
| 606 | + array_values(array_filter(array_unique($entityIds))), |
|
| 607 | + Metadata::merge($metadatas) |
|
| 611 | 608 | ); |
| 612 | 609 | } |
| 613 | 610 | |
@@ -615,43 +612,43 @@ discard block |
||
| 615 | 612 | * @throws SparqlHelperException if the query times out or some other error occurs |
| 616 | 613 | * @throws ConstraintParameterException if the $regex is invalid |
| 617 | 614 | */ |
| 618 | - public function matchesRegularExpression( string $text, string $regex ): bool { |
|
| 615 | + public function matchesRegularExpression(string $text, string $regex): bool { |
|
| 619 | 616 | // caching wrapper around matchesRegularExpressionWithSparql |
| 620 | 617 | |
| 621 | - $textHash = hash( 'sha256', $text ); |
|
| 618 | + $textHash = hash('sha256', $text); |
|
| 622 | 619 | $cacheKey = $this->cache->makeKey( |
| 623 | 620 | 'WikibaseQualityConstraints', // extension |
| 624 | 621 | 'regex', // action |
| 625 | 622 | 'WDQS-Java', // regex flavor |
| 626 | - hash( 'sha256', $regex ) |
|
| 623 | + hash('sha256', $regex) |
|
| 627 | 624 | ); |
| 628 | 625 | |
| 629 | 626 | $cacheMapArray = $this->cache->getWithSetCallback( |
| 630 | 627 | $cacheKey, |
| 631 | 628 | WANObjectCache::TTL_DAY, |
| 632 | - function ( $cacheMapArray ) use ( $text, $regex, $textHash ) { |
|
| 629 | + function($cacheMapArray) use ($text, $regex, $textHash) { |
|
| 633 | 630 | // Initialize the cache map if not set |
| 634 | - if ( $cacheMapArray === false ) { |
|
| 631 | + if ($cacheMapArray === false) { |
|
| 635 | 632 | $key = 'wikibase.quality.constraints.regex.cache.refresh.init'; |
| 636 | - $this->dataFactory->increment( $key ); |
|
| 633 | + $this->dataFactory->increment($key); |
|
| 637 | 634 | return []; |
| 638 | 635 | } |
| 639 | 636 | |
| 640 | 637 | $key = 'wikibase.quality.constraints.regex.cache.refresh'; |
| 641 | - $this->dataFactory->increment( $key ); |
|
| 642 | - $cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $this->cacheMapSize ); |
|
| 643 | - if ( $cacheMap->has( $textHash ) ) { |
|
| 638 | + $this->dataFactory->increment($key); |
|
| 639 | + $cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $this->cacheMapSize); |
|
| 640 | + if ($cacheMap->has($textHash)) { |
|
| 644 | 641 | $key = 'wikibase.quality.constraints.regex.cache.refresh.hit'; |
| 645 | - $this->dataFactory->increment( $key ); |
|
| 646 | - $cacheMap->get( $textHash ); // ping cache |
|
| 642 | + $this->dataFactory->increment($key); |
|
| 643 | + $cacheMap->get($textHash); // ping cache |
|
| 647 | 644 | } else { |
| 648 | 645 | $key = 'wikibase.quality.constraints.regex.cache.refresh.miss'; |
| 649 | - $this->dataFactory->increment( $key ); |
|
| 646 | + $this->dataFactory->increment($key); |
|
| 650 | 647 | try { |
| 651 | - $matches = $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
| 652 | - } catch ( ConstraintParameterException $e ) { |
|
| 653 | - $matches = $this->serializeConstraintParameterException( $e ); |
|
| 654 | - } catch ( SparqlHelperException $e ) { |
|
| 648 | + $matches = $this->matchesRegularExpressionWithSparql($text, $regex); |
|
| 649 | + } catch (ConstraintParameterException $e) { |
|
| 650 | + $matches = $this->serializeConstraintParameterException($e); |
|
| 651 | + } catch (SparqlHelperException $e) { |
|
| 655 | 652 | // don’t cache this |
| 656 | 653 | return $cacheMap->toArray(); |
| 657 | 654 | } |
@@ -675,42 +672,42 @@ discard block |
||
| 675 | 672 | ] |
| 676 | 673 | ); |
| 677 | 674 | |
| 678 | - if ( isset( $cacheMapArray[$textHash] ) ) { |
|
| 675 | + if (isset($cacheMapArray[$textHash])) { |
|
| 679 | 676 | $key = 'wikibase.quality.constraints.regex.cache.hit'; |
| 680 | - $this->dataFactory->increment( $key ); |
|
| 677 | + $this->dataFactory->increment($key); |
|
| 681 | 678 | $matches = $cacheMapArray[$textHash]; |
| 682 | - if ( is_bool( $matches ) ) { |
|
| 679 | + if (is_bool($matches)) { |
|
| 683 | 680 | return $matches; |
| 684 | - } elseif ( is_array( $matches ) && |
|
| 685 | - $matches['type'] == ConstraintParameterException::class ) { |
|
| 686 | - throw $this->deserializeConstraintParameterException( $matches ); |
|
| 681 | + } elseif (is_array($matches) && |
|
| 682 | + $matches['type'] == ConstraintParameterException::class) { |
|
| 683 | + throw $this->deserializeConstraintParameterException($matches); |
|
| 687 | 684 | } else { |
| 688 | 685 | throw new UnexpectedValueException( |
| 689 | - 'Value of unknown type in object cache (' . |
|
| 690 | - 'cache key: ' . $cacheKey . ', ' . |
|
| 691 | - 'cache map key: ' . $textHash . ', ' . |
|
| 692 | - 'value type: ' . get_debug_type( $matches ) . ')' |
|
| 686 | + 'Value of unknown type in object cache ('. |
|
| 687 | + 'cache key: '.$cacheKey.', '. |
|
| 688 | + 'cache map key: '.$textHash.', '. |
|
| 689 | + 'value type: '.get_debug_type($matches).')' |
|
| 693 | 690 | ); |
| 694 | 691 | } |
| 695 | 692 | } else { |
| 696 | 693 | $key = 'wikibase.quality.constraints.regex.cache.miss'; |
| 697 | - $this->dataFactory->increment( $key ); |
|
| 698 | - return $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
| 694 | + $this->dataFactory->increment($key); |
|
| 695 | + return $this->matchesRegularExpressionWithSparql($text, $regex); |
|
| 699 | 696 | } |
| 700 | 697 | } |
| 701 | 698 | |
| 702 | - private function serializeConstraintParameterException( ConstraintParameterException $cpe ): array { |
|
| 699 | + private function serializeConstraintParameterException(ConstraintParameterException $cpe): array { |
|
| 703 | 700 | return [ |
| 704 | 701 | 'type' => ConstraintParameterException::class, |
| 705 | - 'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ), |
|
| 702 | + 'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()), |
|
| 706 | 703 | ]; |
| 707 | 704 | } |
| 708 | 705 | |
| 709 | - private function deserializeConstraintParameterException( array $serialization ): ConstraintParameterException { |
|
| 706 | + private function deserializeConstraintParameterException(array $serialization): ConstraintParameterException { |
|
| 710 | 707 | $message = $this->violationMessageDeserializer->deserialize( |
| 711 | 708 | $serialization['violationMessage'] |
| 712 | 709 | ); |
| 713 | - return new ConstraintParameterException( $message ); |
|
| 710 | + return new ConstraintParameterException($message); |
|
| 714 | 711 | } |
| 715 | 712 | |
| 716 | 713 | /** |
@@ -720,25 +717,25 @@ discard block |
||
| 720 | 717 | * @throws SparqlHelperException if the query times out or some other error occurs |
| 721 | 718 | * @throws ConstraintParameterException if the $regex is invalid |
| 722 | 719 | */ |
| 723 | - public function matchesRegularExpressionWithSparql( string $text, string $regex ): bool { |
|
| 724 | - $textStringLiteral = $this->stringLiteral( $text ); |
|
| 725 | - $regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' ); |
|
| 720 | + public function matchesRegularExpressionWithSparql(string $text, string $regex): bool { |
|
| 721 | + $textStringLiteral = $this->stringLiteral($text); |
|
| 722 | + $regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$'); |
|
| 726 | 723 | |
| 727 | 724 | $query = <<<EOF |
| 728 | 725 | SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {} |
| 729 | 726 | EOF; |
| 730 | 727 | |
| 731 | - $result = $this->runQuery( $query, $this->primaryEndpoint, false ); |
|
| 728 | + $result = $this->runQuery($query, $this->primaryEndpoint, false); |
|
| 732 | 729 | |
| 733 | 730 | $vars = $result->getArray()['results']['bindings'][0]; |
| 734 | - if ( array_key_exists( 'matches', $vars ) ) { |
|
| 731 | + if (array_key_exists('matches', $vars)) { |
|
| 735 | 732 | // true or false ⇒ regex okay, text matches or not |
| 736 | 733 | return $vars['matches']['value'] === 'true'; |
| 737 | 734 | } else { |
| 738 | 735 | // empty result: regex broken |
| 739 | 736 | throw new ConstraintParameterException( |
| 740 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
| 741 | - ->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
| 737 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
| 738 | + ->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE) |
|
| 742 | 739 | ); |
| 743 | 740 | } |
| 744 | 741 | } |
@@ -746,14 +743,14 @@ discard block |
||
| 746 | 743 | /** |
| 747 | 744 | * Check whether the text content of an error response indicates a query timeout. |
| 748 | 745 | */ |
| 749 | - public function isTimeout( string $responseContent ): bool { |
|
| 750 | - $timeoutRegex = implode( '|', array_map( |
|
| 751 | - static function ( $fqn ) { |
|
| 752 | - return preg_quote( $fqn, '/' ); |
|
| 746 | + public function isTimeout(string $responseContent): bool { |
|
| 747 | + $timeoutRegex = implode('|', array_map( |
|
| 748 | + static function($fqn) { |
|
| 749 | + return preg_quote($fqn, '/'); |
|
| 753 | 750 | }, |
| 754 | 751 | $this->timeoutExceptionClasses |
| 755 | - ) ); |
|
| 756 | - return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent ); |
|
| 752 | + )); |
|
| 753 | + return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent); |
|
| 757 | 754 | } |
| 758 | 755 | |
| 759 | 756 | /** |
@@ -765,17 +762,17 @@ discard block |
||
| 765 | 762 | * @return int|boolean the max-age (in seconds) |
| 766 | 763 | * or a plain boolean if no max-age can be determined |
| 767 | 764 | */ |
| 768 | - public function getCacheMaxAge( array $responseHeaders ) { |
|
| 765 | + public function getCacheMaxAge(array $responseHeaders) { |
|
| 769 | 766 | if ( |
| 770 | - array_key_exists( 'x-cache-status', $responseHeaders ) && |
|
| 771 | - preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] ) |
|
| 767 | + array_key_exists('x-cache-status', $responseHeaders) && |
|
| 768 | + preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0]) |
|
| 772 | 769 | ) { |
| 773 | 770 | $maxage = []; |
| 774 | 771 | if ( |
| 775 | - array_key_exists( 'cache-control', $responseHeaders ) && |
|
| 776 | - preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage ) |
|
| 772 | + array_key_exists('cache-control', $responseHeaders) && |
|
| 773 | + preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage) |
|
| 777 | 774 | ) { |
| 778 | - return intval( $maxage[1] ); |
|
| 775 | + return intval($maxage[1]); |
|
| 779 | 776 | } else { |
| 780 | 777 | return true; |
| 781 | 778 | } |
@@ -796,34 +793,34 @@ discard block |
||
| 796 | 793 | * or SparlHelper::EMPTY_RETRY_AFTER if there is an empty Retry-After |
| 797 | 794 | * or SparlHelper::INVALID_RETRY_AFTER if there is something wrong with the format |
| 798 | 795 | */ |
| 799 | - public function getThrottling( MWHttpRequest $request ) { |
|
| 800 | - $retryAfterValue = $request->getResponseHeader( 'Retry-After' ); |
|
| 801 | - if ( $retryAfterValue === null ) { |
|
| 796 | + public function getThrottling(MWHttpRequest $request) { |
|
| 797 | + $retryAfterValue = $request->getResponseHeader('Retry-After'); |
|
| 798 | + if ($retryAfterValue === null) { |
|
| 802 | 799 | return self::NO_RETRY_AFTER; |
| 803 | 800 | } |
| 804 | 801 | |
| 805 | - $trimmedRetryAfterValue = trim( $retryAfterValue ); |
|
| 806 | - if ( $trimmedRetryAfterValue === '' ) { |
|
| 802 | + $trimmedRetryAfterValue = trim($retryAfterValue); |
|
| 803 | + if ($trimmedRetryAfterValue === '') { |
|
| 807 | 804 | return self::EMPTY_RETRY_AFTER; |
| 808 | 805 | } |
| 809 | 806 | |
| 810 | - if ( is_numeric( $trimmedRetryAfterValue ) ) { |
|
| 811 | - $delaySeconds = (int)$trimmedRetryAfterValue; |
|
| 812 | - if ( $delaySeconds >= 0 ) { |
|
| 813 | - return $this->getTimestampInFuture( new DateInterval( 'PT' . $delaySeconds . 'S' ) ); |
|
| 807 | + if (is_numeric($trimmedRetryAfterValue)) { |
|
| 808 | + $delaySeconds = (int) $trimmedRetryAfterValue; |
|
| 809 | + if ($delaySeconds >= 0) { |
|
| 810 | + return $this->getTimestampInFuture(new DateInterval('PT'.$delaySeconds.'S')); |
|
| 814 | 811 | } |
| 815 | 812 | } else { |
| 816 | - $return = strtotime( $trimmedRetryAfterValue ); |
|
| 817 | - if ( $return !== false ) { |
|
| 818 | - return new ConvertibleTimestamp( $return ); |
|
| 813 | + $return = strtotime($trimmedRetryAfterValue); |
|
| 814 | + if ($return !== false) { |
|
| 815 | + return new ConvertibleTimestamp($return); |
|
| 819 | 816 | } |
| 820 | 817 | } |
| 821 | 818 | return self::INVALID_RETRY_AFTER; |
| 822 | 819 | } |
| 823 | 820 | |
| 824 | - private function getTimestampInFuture( DateInterval $delta ): ConvertibleTimestamp { |
|
| 821 | + private function getTimestampInFuture(DateInterval $delta): ConvertibleTimestamp { |
|
| 825 | 822 | $now = new ConvertibleTimestamp(); |
| 826 | - return new ConvertibleTimestamp( $now->timestamp->add( $delta ) ); |
|
| 823 | + return new ConvertibleTimestamp($now->timestamp->add($delta)); |
|
| 827 | 824 | } |
| 828 | 825 | |
| 829 | 826 | /** |
@@ -838,64 +835,63 @@ discard block |
||
| 838 | 835 | * |
| 839 | 836 | * @throws SparqlHelperException if the query times out or some other error occurs |
| 840 | 837 | */ |
| 841 | - protected function runQuery( string $query, string $endpoint, bool $needsPrefixes = true ): CachedQueryResults { |
|
| 842 | - if ( $this->throttlingLock->isLocked( self::EXPIRY_LOCK_ID ) ) { |
|
| 843 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
| 838 | + protected function runQuery(string $query, string $endpoint, bool $needsPrefixes = true): CachedQueryResults { |
|
| 839 | + if ($this->throttlingLock->isLocked(self::EXPIRY_LOCK_ID)) { |
|
| 840 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
| 844 | 841 | throw new TooManySparqlRequestsException(); |
| 845 | 842 | } |
| 846 | 843 | |
| 847 | - if ( $this->sparqlHasWikibaseSupport ) { |
|
| 844 | + if ($this->sparqlHasWikibaseSupport) { |
|
| 848 | 845 | $needsPrefixes = false; |
| 849 | 846 | } |
| 850 | 847 | |
| 851 | - if ( $needsPrefixes ) { |
|
| 852 | - $query = $this->prefixes . $query; |
|
| 848 | + if ($needsPrefixes) { |
|
| 849 | + $query = $this->prefixes.$query; |
|
| 853 | 850 | } |
| 854 | - $query = "#wbqc\n" . $query; |
|
| 851 | + $query = "#wbqc\n".$query; |
|
| 855 | 852 | |
| 856 | - $url = $endpoint . '?' . http_build_query( |
|
| 853 | + $url = $endpoint.'?'.http_build_query( |
|
| 857 | 854 | [ |
| 858 | 855 | 'query' => $query, |
| 859 | 856 | 'format' => 'json', |
| 860 | 857 | 'maxQueryTimeMillis' => $this->maxQueryTimeMillis, |
| 861 | 858 | ], |
| 862 | - '', ini_get( 'arg_separator.output' ), |
|
| 859 | + '', ini_get('arg_separator.output'), |
|
| 863 | 860 | // encode spaces with %20, not + |
| 864 | 861 | PHP_QUERY_RFC3986 |
| 865 | 862 | ); |
| 866 | 863 | |
| 867 | 864 | $options = [ |
| 868 | 865 | 'method' => 'GET', |
| 869 | - 'timeout' => (int)round( ( $this->maxQueryTimeMillis + 1000 ) / 1000 ), |
|
| 866 | + 'timeout' => (int) round(($this->maxQueryTimeMillis + 1000) / 1000), |
|
| 870 | 867 | 'connectTimeout' => 'default', |
| 871 | 868 | 'userAgent' => $this->defaultUserAgent, |
| 872 | 869 | ]; |
| 873 | - $request = $this->requestFactory->create( $url, $options, __METHOD__ ); |
|
| 874 | - $startTime = microtime( true ); |
|
| 870 | + $request = $this->requestFactory->create($url, $options, __METHOD__); |
|
| 871 | + $startTime = microtime(true); |
|
| 875 | 872 | $requestStatus = $request->execute(); |
| 876 | - $endTime = microtime( true ); |
|
| 873 | + $endTime = microtime(true); |
|
| 877 | 874 | $this->dataFactory->timing( |
| 878 | 875 | 'wikibase.quality.constraints.sparql.timing', |
| 879 | - ( $endTime - $startTime ) * 1000 |
|
| 876 | + ($endTime - $startTime) * 1000 |
|
| 880 | 877 | ); |
| 881 | 878 | |
| 882 | - $this->guardAgainstTooManyRequestsError( $request ); |
|
| 879 | + $this->guardAgainstTooManyRequestsError($request); |
|
| 883 | 880 | |
| 884 | - $maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() ); |
|
| 885 | - if ( $maxAge ) { |
|
| 886 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' ); |
|
| 881 | + $maxAge = $this->getCacheMaxAge($request->getResponseHeaders()); |
|
| 882 | + if ($maxAge) { |
|
| 883 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.cached'); |
|
| 887 | 884 | } |
| 888 | 885 | |
| 889 | - if ( $requestStatus->isOK() ) { |
|
| 886 | + if ($requestStatus->isOK()) { |
|
| 890 | 887 | $json = $request->getContent(); |
| 891 | - $jsonStatus = FormatJson::parse( $json, FormatJson::FORCE_ASSOC ); |
|
| 892 | - if ( $jsonStatus->isOK() ) { |
|
| 888 | + $jsonStatus = FormatJson::parse($json, FormatJson::FORCE_ASSOC); |
|
| 889 | + if ($jsonStatus->isOK()) { |
|
| 893 | 890 | return new CachedQueryResults( |
| 894 | 891 | $jsonStatus->getValue(), |
| 895 | 892 | Metadata::ofCachingMetadata( |
| 896 | 893 | $maxAge ? |
| 897 | - CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) : |
|
| 898 | - CachingMetadata::fresh() |
|
| 894 | + CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh() |
|
| 899 | 895 | ) |
| 900 | 896 | ); |
| 901 | 897 | } else { |
@@ -912,9 +908,9 @@ discard block |
||
| 912 | 908 | // fall through to general error handling |
| 913 | 909 | } |
| 914 | 910 | |
| 915 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' ); |
|
| 911 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.error'); |
|
| 916 | 912 | |
| 917 | - if ( $this->isTimeout( $request->getContent() ) ) { |
|
| 913 | + if ($this->isTimeout($request->getContent())) { |
|
| 918 | 914 | $this->dataFactory->increment( |
| 919 | 915 | 'wikibase.quality.constraints.sparql.error.timeout' |
| 920 | 916 | ); |
@@ -929,29 +925,29 @@ discard block |
||
| 929 | 925 | * @param MWHttpRequest $request |
| 930 | 926 | * @throws TooManySparqlRequestsException |
| 931 | 927 | */ |
| 932 | - private function guardAgainstTooManyRequestsError( MWHttpRequest $request ): void { |
|
| 933 | - if ( $request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS ) { |
|
| 928 | + private function guardAgainstTooManyRequestsError(MWHttpRequest $request): void { |
|
| 929 | + if ($request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS) { |
|
| 934 | 930 | return; |
| 935 | 931 | } |
| 936 | 932 | |
| 937 | 933 | $fallbackBlockDuration = $this->sparqlThrottlingFallbackDuration; |
| 938 | 934 | |
| 939 | - if ( $fallbackBlockDuration < 0 ) { |
|
| 940 | - throw new InvalidArgumentException( 'Fallback duration must be positive int but is: ' . |
|
| 941 | - $fallbackBlockDuration ); |
|
| 935 | + if ($fallbackBlockDuration < 0) { |
|
| 936 | + throw new InvalidArgumentException('Fallback duration must be positive int but is: '. |
|
| 937 | + $fallbackBlockDuration); |
|
| 942 | 938 | } |
| 943 | 939 | |
| 944 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
| 945 | - $throttlingUntil = $this->getThrottling( $request ); |
|
| 946 | - if ( !( $throttlingUntil instanceof ConvertibleTimestamp ) ) { |
|
| 947 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid( $request ); |
|
| 940 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
| 941 | + $throttlingUntil = $this->getThrottling($request); |
|
| 942 | + if (!($throttlingUntil instanceof ConvertibleTimestamp)) { |
|
| 943 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid($request); |
|
| 948 | 944 | $this->throttlingLock->lock( |
| 949 | 945 | self::EXPIRY_LOCK_ID, |
| 950 | - $this->getTimestampInFuture( new DateInterval( 'PT' . $fallbackBlockDuration . 'S' ) ) |
|
| 946 | + $this->getTimestampInFuture(new DateInterval('PT'.$fallbackBlockDuration.'S')) |
|
| 951 | 947 | ); |
| 952 | 948 | } else { |
| 953 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent( $throttlingUntil, $request ); |
|
| 954 | - $this->throttlingLock->lock( self::EXPIRY_LOCK_ID, $throttlingUntil ); |
|
| 949 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent($throttlingUntil, $request); |
|
| 950 | + $this->throttlingLock->lock(self::EXPIRY_LOCK_ID, $throttlingUntil); |
|
| 955 | 951 | } |
| 956 | 952 | throw new TooManySparqlRequestsException(); |
| 957 | 953 | } |