@@ -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; |
| 6 | 6 | |
@@ -26,9 +26,9 @@ discard block |
||
| 26 | 26 | public const ENTITY_LOOKUP_WITHOUT_CACHE = 'WBQC_EntityLookupWithoutCache'; |
| 27 | 27 | |
| 28 | 28 | /** @return mixed */ |
| 29 | - private static function getService( ?MediaWikiServices $services, string $name ) { |
|
| 29 | + private static function getService(?MediaWikiServices $services, string $name) { |
|
| 30 | 30 | $services ??= MediaWikiServices::getInstance(); |
| 31 | - return $services->getService( $name ); |
|
| 31 | + return $services->getService($name); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -38,8 +38,8 @@ discard block |
||
| 38 | 38 | * this lookup ignores exceptions (such as unresolved redirects, T93273), |
| 39 | 39 | * as it is more convenient to treat them all as missing entities in WBQC. |
| 40 | 40 | */ |
| 41 | - public static function getEntityLookup( ?MediaWikiServices $services = null ): EntityLookup { |
|
| 42 | - return self::getService( $services, self::ENTITY_LOOKUP ); |
|
| 41 | + public static function getEntityLookup(?MediaWikiServices $services = null): EntityLookup { |
|
| 42 | + return self::getService($services, self::ENTITY_LOOKUP); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | * were exceeding the request memory limit when they were all added to the cache (T227450). |
| 50 | 50 | * Also, like {@link self::getEntityLookup()}, this lookup ignores exceptions. |
| 51 | 51 | */ |
| 52 | - public static function getEntityLookupWithoutCache( ?MediaWikiServices $services = null ): EntityLookup { |
|
| 53 | - return self::getService( $services, self::ENTITY_LOOKUP_WITHOUT_CACHE ); |
|
| 52 | + public static function getEntityLookupWithoutCache(?MediaWikiServices $services = null): EntityLookup { |
|
| 53 | + return self::getService($services, self::ENTITY_LOOKUP_WITHOUT_CACHE); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | } |
@@ -26,8 +26,8 @@ discard block |
||
| 26 | 26 | BeforePageDisplayHook |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - public static function onWikibaseChange( Change $change ) { |
|
| 30 | - if ( !( $change instanceof EntityChange ) ) { |
|
| 29 | + public static function onWikibaseChange(Change $change) { |
|
| 30 | + if (!($change instanceof EntityChange)) { |
|
| 31 | 31 | return; |
| 32 | 32 | } |
| 33 | 33 | /** @var EntityChange $change */ |
@@ -38,48 +38,48 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | // If jobs are enabled and the results would be stored in some way run a job. |
| 40 | 40 | if ( |
| 41 | - $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobs' ) && |
|
| 42 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) && |
|
| 41 | + $config->get('WBQualityConstraintsEnableConstraintsCheckJobs') && |
|
| 42 | + $config->get('WBQualityConstraintsCacheCheckConstraintsResults') && |
|
| 43 | 43 | self::isSelectedForJobRunBasedOnPercentage() |
| 44 | 44 | ) { |
| 45 | - $params = [ 'entityId' => $change->getEntityId()->getSerialization() ]; |
|
| 45 | + $params = ['entityId' => $change->getEntityId()->getSerialization()]; |
|
| 46 | 46 | $jobQueueGroup->lazyPush( |
| 47 | - new JobSpecification( CheckConstraintsJob::COMMAND, $params ) |
|
| 47 | + new JobSpecification(CheckConstraintsJob::COMMAND, $params) |
|
| 48 | 48 | ); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
| 52 | - self::isConstraintStatementsChange( $config, $change ) |
|
| 51 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
| 52 | + self::isConstraintStatementsChange($config, $change) |
|
| 53 | 53 | ) { |
| 54 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
| 54 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
| 55 | 55 | $metadata = $change->getMetadata(); |
| 56 | - if ( array_key_exists( 'rev_id', $metadata ) ) { |
|
| 56 | + if (array_key_exists('rev_id', $metadata)) { |
|
| 57 | 57 | $params['revisionId'] = $metadata['rev_id']; |
| 58 | 58 | } |
| 59 | 59 | $jobQueueGroup->push( |
| 60 | - new JobSpecification( 'constraintsTableUpdate', $params ) |
|
| 60 | + new JobSpecification('constraintsTableUpdate', $params) |
|
| 61 | 61 | ); |
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | private static function isSelectedForJobRunBasedOnPercentage(): bool { |
| 66 | 66 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
| 67 | - $percentage = $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobsRatio' ); |
|
| 67 | + $percentage = $config->get('WBQualityConstraintsEnableConstraintsCheckJobsRatio'); |
|
| 68 | 68 | |
| 69 | - return mt_rand( 1, 100 ) <= $percentage; |
|
| 69 | + return mt_rand(1, 100) <= $percentage; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - public static function isConstraintStatementsChange( Config $config, Change $change ): bool { |
|
| 73 | - if ( !( $change instanceof EntityChange ) || |
|
| 72 | + public static function isConstraintStatementsChange(Config $config, Change $change): bool { |
|
| 73 | + if (!($change instanceof EntityChange) || |
|
| 74 | 74 | $change->getAction() !== EntityChange::UPDATE || |
| 75 | - !( $change->getEntityId() instanceof NumericPropertyId ) |
|
| 75 | + !($change->getEntityId() instanceof NumericPropertyId) |
|
| 76 | 76 | ) { |
| 77 | 77 | return false; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | $info = $change->getInfo(); |
| 81 | 81 | |
| 82 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
| 82 | + if (!array_key_exists('compactDiff', $info)) { |
|
| 83 | 83 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
| 84 | 84 | // so we only know that the change *might* affect the constraint statements |
| 85 | 85 | return true; |
@@ -88,52 +88,52 @@ discard block |
||
| 88 | 88 | /** @var EntityDiffChangedAspects $aspects */ |
| 89 | 89 | $aspects = $info['compactDiff']; |
| 90 | 90 | |
| 91 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
| 92 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
| 91 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
| 92 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** @inheritDoc */ |
| 96 | - public function onArticlePurge( $wikiPage ) { |
|
| 96 | + public function onArticlePurge($wikiPage) { |
|
| 97 | 97 | $entityContentFactory = WikibaseRepo::getEntityContentFactory(); |
| 98 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
| 98 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
| 99 | 99 | $entityIdLookup = WikibaseRepo::getEntityIdLookup(); |
| 100 | - $entityId = $entityIdLookup->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
| 101 | - if ( $entityId !== null ) { |
|
| 100 | + $entityId = $entityIdLookup->getEntityIdForTitle($wikiPage->getTitle()); |
|
| 101 | + if ($entityId !== null) { |
|
| 102 | 102 | $resultsCache = ResultsCache::getDefaultInstance(); |
| 103 | - $resultsCache->delete( $entityId ); |
|
| 103 | + $resultsCache->delete($entityId); |
|
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** @inheritDoc */ |
| 109 | - public function onBeforePageDisplay( $out, $skin ): void { |
|
| 109 | + public function onBeforePageDisplay($out, $skin): void { |
|
| 110 | 110 | $lookup = WikibaseRepo::getEntityNamespaceLookup(); |
| 111 | 111 | $title = $out->getTitle(); |
| 112 | - if ( $title === null ) { |
|
| 112 | + if ($title === null) { |
|
| 113 | 113 | return; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - if ( !$lookup->isNamespaceWithEntities( $title->getNamespace() ) ) { |
|
| 116 | + if (!$lookup->isNamespaceWithEntities($title->getNamespace())) { |
|
| 117 | 117 | return; |
| 118 | 118 | } |
| 119 | - if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) { |
|
| 119 | + if (empty($out->getJsConfigVars()['wbIsEditView'])) { |
|
| 120 | 120 | return; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | $services = MediaWikiServices::getInstance(); |
| 124 | 124 | $config = $services->getMainConfig(); |
| 125 | 125 | |
| 126 | - $isMobileView = ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' ) && |
|
| 127 | - $services->getService( 'MobileFrontend.Context' )->shouldDisplayMobileView(); |
|
| 128 | - if ( $isMobileView ) { |
|
| 126 | + $isMobileView = ExtensionRegistry::getInstance()->isLoaded('MobileFrontend') && |
|
| 127 | + $services->getService('MobileFrontend.Context')->shouldDisplayMobileView(); |
|
| 128 | + if ($isMobileView) { |
|
| 129 | 129 | return; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - $out->addModules( 'wikibase.quality.constraints.suggestions' ); |
|
| 132 | + $out->addModules('wikibase.quality.constraints.suggestions'); |
|
| 133 | 133 | |
| 134 | - if ( $config->get( 'WBQualityConstraintsShowConstraintViolationToNonLoggedInUsers' ) |
|
| 135 | - || $out->getUser()->isRegistered() ) { |
|
| 136 | - $out->addModules( 'wikibase.quality.constraints.gadget' ); |
|
| 134 | + if ($config->get('WBQualityConstraintsShowConstraintViolationToNonLoggedInUsers') |
|
| 135 | + || $out->getUser()->isRegistered()) { |
|
| 136 | + $out->addModules('wikibase.quality.constraints.gadget'); |
|
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
@@ -45,257 +45,257 @@ |
||
| 45 | 45 | public const LABEL_IN_LANGUAGE_CHECKER = 'WBQC_LabelInLanguageChecker'; |
| 46 | 46 | |
| 47 | 47 | /** @return mixed */ |
| 48 | - private static function getService( ?MediaWikiServices $services, string $name ) { |
|
| 48 | + private static function getService(?MediaWikiServices $services, string $name) { |
|
| 49 | 49 | $services ??= MediaWikiServices::getInstance(); |
| 50 | - return $services->getService( $name ); |
|
| 50 | + return $services->getService($name); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * @param MediaWikiServices|null $services |
| 55 | 55 | * @return ConstraintChecker |
| 56 | 56 | */ |
| 57 | - public static function getConflictsWithChecker( ?MediaWikiServices $services = null ) { |
|
| 58 | - return self::getService( $services, self::CONFLICTS_WITH_CHECKER ); |
|
| 57 | + public static function getConflictsWithChecker(?MediaWikiServices $services = null) { |
|
| 58 | + return self::getService($services, self::CONFLICTS_WITH_CHECKER); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | 62 | * @param MediaWikiServices|null $services |
| 63 | 63 | * @return ConstraintChecker |
| 64 | 64 | */ |
| 65 | - public static function getItemChecker( ?MediaWikiServices $services = null ) { |
|
| 66 | - return self::getService( $services, self::ITEM_CHECKER ); |
|
| 65 | + public static function getItemChecker(?MediaWikiServices $services = null) { |
|
| 66 | + return self::getService($services, self::ITEM_CHECKER); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * @param MediaWikiServices|null $services |
| 71 | 71 | * @return ConstraintChecker |
| 72 | 72 | */ |
| 73 | - public static function getTargetRequiredClaimChecker( ?MediaWikiServices $services = null ) { |
|
| 74 | - return self::getService( $services, self::TARGET_REQUIRED_CLAIM_CHECKER ); |
|
| 73 | + public static function getTargetRequiredClaimChecker(?MediaWikiServices $services = null) { |
|
| 74 | + return self::getService($services, self::TARGET_REQUIRED_CLAIM_CHECKER); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | 78 | * @param MediaWikiServices|null $services |
| 79 | 79 | * @return ConstraintChecker |
| 80 | 80 | */ |
| 81 | - public static function getSymmetricChecker( ?MediaWikiServices $services = null ) { |
|
| 82 | - return self::getService( $services, self::SYMMETRIC_CHECKER ); |
|
| 81 | + public static function getSymmetricChecker(?MediaWikiServices $services = null) { |
|
| 82 | + return self::getService($services, self::SYMMETRIC_CHECKER); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
| 86 | 86 | * @param MediaWikiServices|null $services |
| 87 | 87 | * @return ConstraintChecker |
| 88 | 88 | */ |
| 89 | - public static function getInverseChecker( ?MediaWikiServices $services = null ) { |
|
| 90 | - return self::getService( $services, self::INVERSE_CHECKER ); |
|
| 89 | + public static function getInverseChecker(?MediaWikiServices $services = null) { |
|
| 90 | + return self::getService($services, self::INVERSE_CHECKER); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | 94 | * @param MediaWikiServices|null $services |
| 95 | 95 | * @return ConstraintChecker |
| 96 | 96 | */ |
| 97 | - public static function getQualifierChecker( ?MediaWikiServices $services = null ) { |
|
| 98 | - return self::getService( $services, self::QUALIFIER_CHECKER ); |
|
| 97 | + public static function getQualifierChecker(?MediaWikiServices $services = null) { |
|
| 98 | + return self::getService($services, self::QUALIFIER_CHECKER); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | 102 | * @param MediaWikiServices|null $services |
| 103 | 103 | * @return ConstraintChecker |
| 104 | 104 | */ |
| 105 | - public static function getQualifiersChecker( ?MediaWikiServices $services = null ) { |
|
| 106 | - return self::getService( $services, self::QUALIFIERS_CHECKER ); |
|
| 105 | + public static function getQualifiersChecker(?MediaWikiServices $services = null) { |
|
| 106 | + return self::getService($services, self::QUALIFIERS_CHECKER); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
| 110 | 110 | * @param MediaWikiServices|null $services |
| 111 | 111 | * @return ConstraintChecker |
| 112 | 112 | */ |
| 113 | - public static function getMandatoryQualifiersChecker( ?MediaWikiServices $services = null ) { |
|
| 114 | - return self::getService( $services, self::MANDATORY_QUALIFIERS_CHECKER ); |
|
| 113 | + public static function getMandatoryQualifiersChecker(?MediaWikiServices $services = null) { |
|
| 114 | + return self::getService($services, self::MANDATORY_QUALIFIERS_CHECKER); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
| 118 | 118 | * @param MediaWikiServices|null $services |
| 119 | 119 | * @return ConstraintChecker |
| 120 | 120 | */ |
| 121 | - public static function getRangeChecker( ?MediaWikiServices $services = null ) { |
|
| 122 | - return self::getService( $services, self::RANGE_CHECKER ); |
|
| 121 | + public static function getRangeChecker(?MediaWikiServices $services = null) { |
|
| 122 | + return self::getService($services, self::RANGE_CHECKER); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
| 126 | 126 | * @param MediaWikiServices|null $services |
| 127 | 127 | * @return ConstraintChecker |
| 128 | 128 | */ |
| 129 | - public static function getDiffWithinRangeChecker( ?MediaWikiServices $services = null ) { |
|
| 130 | - return self::getService( $services, self::DIFF_WITHIN_RANGE_CHECKER ); |
|
| 129 | + public static function getDiffWithinRangeChecker(?MediaWikiServices $services = null) { |
|
| 130 | + return self::getService($services, self::DIFF_WITHIN_RANGE_CHECKER); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
| 134 | 134 | * @param MediaWikiServices|null $services |
| 135 | 135 | * @return ConstraintChecker |
| 136 | 136 | */ |
| 137 | - public static function getTypeChecker( ?MediaWikiServices $services = null ) { |
|
| 138 | - return self::getService( $services, self::TYPE_CHECKER ); |
|
| 137 | + public static function getTypeChecker(?MediaWikiServices $services = null) { |
|
| 138 | + return self::getService($services, self::TYPE_CHECKER); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
| 142 | 142 | * @param MediaWikiServices|null $services |
| 143 | 143 | * @return ConstraintChecker |
| 144 | 144 | */ |
| 145 | - public static function getValueTypeChecker( ?MediaWikiServices $services = null ) { |
|
| 146 | - return self::getService( $services, self::VALUE_TYPE_CHECKER ); |
|
| 145 | + public static function getValueTypeChecker(?MediaWikiServices $services = null) { |
|
| 146 | + return self::getService($services, self::VALUE_TYPE_CHECKER); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
| 150 | 150 | * @param MediaWikiServices|null $services |
| 151 | 151 | * @return ConstraintChecker |
| 152 | 152 | */ |
| 153 | - public static function getSingleValueChecker( ?MediaWikiServices $services = null ) { |
|
| 154 | - return self::getService( $services, self::SINGLE_VALUE_CHECKER ); |
|
| 153 | + public static function getSingleValueChecker(?MediaWikiServices $services = null) { |
|
| 154 | + return self::getService($services, self::SINGLE_VALUE_CHECKER); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
| 158 | 158 | * @param MediaWikiServices|null $services |
| 159 | 159 | * @return ConstraintChecker |
| 160 | 160 | */ |
| 161 | - public static function getMultiValueChecker( ?MediaWikiServices $services = null ) { |
|
| 162 | - return self::getService( $services, self::MULTI_VALUE_CHECKER ); |
|
| 161 | + public static function getMultiValueChecker(?MediaWikiServices $services = null) { |
|
| 162 | + return self::getService($services, self::MULTI_VALUE_CHECKER); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
| 166 | 166 | * @param MediaWikiServices|null $services |
| 167 | 167 | * @return ConstraintChecker |
| 168 | 168 | */ |
| 169 | - public static function getUniqueValueChecker( ?MediaWikiServices $services = null ) { |
|
| 170 | - return self::getService( $services, self::UNIQUE_VALUE_CHECKER ); |
|
| 169 | + public static function getUniqueValueChecker(?MediaWikiServices $services = null) { |
|
| 170 | + return self::getService($services, self::UNIQUE_VALUE_CHECKER); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
| 174 | 174 | * @param MediaWikiServices|null $services |
| 175 | 175 | * @return ConstraintChecker |
| 176 | 176 | */ |
| 177 | - public static function getFormatChecker( ?MediaWikiServices $services = null ) { |
|
| 178 | - return self::getService( $services, self::FORMAT_CHECKER ); |
|
| 177 | + public static function getFormatChecker(?MediaWikiServices $services = null) { |
|
| 178 | + return self::getService($services, self::FORMAT_CHECKER); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
| 182 | 182 | * @param MediaWikiServices|null $services |
| 183 | 183 | * @return ConstraintChecker |
| 184 | 184 | */ |
| 185 | - public static function getCommonsLinkChecker( ?MediaWikiServices $services = null ) { |
|
| 186 | - return self::getService( $services, self::COMMONS_LINK_CHECKER ); |
|
| 185 | + public static function getCommonsLinkChecker(?MediaWikiServices $services = null) { |
|
| 186 | + return self::getService($services, self::COMMONS_LINK_CHECKER); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | /** |
| 190 | 190 | * @param MediaWikiServices|null $services |
| 191 | 191 | * @return ConstraintChecker |
| 192 | 192 | */ |
| 193 | - public static function getOneOfChecker( ?MediaWikiServices $services = null ) { |
|
| 194 | - return self::getService( $services, self::ONE_OF_CHECKER ); |
|
| 193 | + public static function getOneOfChecker(?MediaWikiServices $services = null) { |
|
| 194 | + return self::getService($services, self::ONE_OF_CHECKER); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
| 198 | 198 | * @param MediaWikiServices|null $services |
| 199 | 199 | * @return ConstraintChecker |
| 200 | 200 | */ |
| 201 | - public static function getValueOnlyChecker( ?MediaWikiServices $services = null ) { |
|
| 202 | - return self::getService( $services, self::VALUE_ONLY_CHECKER ); |
|
| 201 | + public static function getValueOnlyChecker(?MediaWikiServices $services = null) { |
|
| 202 | + return self::getService($services, self::VALUE_ONLY_CHECKER); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
| 206 | 206 | * @param MediaWikiServices|null $services |
| 207 | 207 | * @return ConstraintChecker |
| 208 | 208 | */ |
| 209 | - public static function getReferenceChecker( ?MediaWikiServices $services = null ) { |
|
| 210 | - return self::getService( $services, self::REFERENCE_CHECKER ); |
|
| 209 | + public static function getReferenceChecker(?MediaWikiServices $services = null) { |
|
| 210 | + return self::getService($services, self::REFERENCE_CHECKER); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
| 214 | 214 | * @param MediaWikiServices|null $services |
| 215 | 215 | * @return ConstraintChecker |
| 216 | 216 | */ |
| 217 | - public static function getNoBoundsChecker( ?MediaWikiServices $services = null ) { |
|
| 218 | - return self::getService( $services, self::NO_BOUNDS_CHECKER ); |
|
| 217 | + public static function getNoBoundsChecker(?MediaWikiServices $services = null) { |
|
| 218 | + return self::getService($services, self::NO_BOUNDS_CHECKER); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
| 222 | 222 | * @param MediaWikiServices|null $services |
| 223 | 223 | * @return ConstraintChecker |
| 224 | 224 | */ |
| 225 | - public static function getAllowedUnitsChecker( ?MediaWikiServices $services = null ) { |
|
| 226 | - return self::getService( $services, self::ALLOWED_UNITS_CHECKER ); |
|
| 225 | + public static function getAllowedUnitsChecker(?MediaWikiServices $services = null) { |
|
| 226 | + return self::getService($services, self::ALLOWED_UNITS_CHECKER); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
| 230 | 230 | * @param MediaWikiServices|null $services |
| 231 | 231 | * @return ConstraintChecker |
| 232 | 232 | */ |
| 233 | - public static function getSingleBestValueChecker( ?MediaWikiServices $services = null ) { |
|
| 234 | - return self::getService( $services, self::SINGLE_BEST_VALUE_CHECKER ); |
|
| 233 | + public static function getSingleBestValueChecker(?MediaWikiServices $services = null) { |
|
| 234 | + return self::getService($services, self::SINGLE_BEST_VALUE_CHECKER); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
| 238 | 238 | * @param MediaWikiServices|null $services |
| 239 | 239 | * @return ConstraintChecker |
| 240 | 240 | */ |
| 241 | - public static function getEntityTypeChecker( ?MediaWikiServices $services = null ) { |
|
| 242 | - return self::getService( $services, self::ENTITY_TYPE_CHECKER ); |
|
| 241 | + public static function getEntityTypeChecker(?MediaWikiServices $services = null) { |
|
| 242 | + return self::getService($services, self::ENTITY_TYPE_CHECKER); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
| 246 | 246 | * @param MediaWikiServices|null $services |
| 247 | 247 | * @return ConstraintChecker |
| 248 | 248 | */ |
| 249 | - public static function getNoneOfChecker( ?MediaWikiServices $services = null ) { |
|
| 250 | - return self::getService( $services, self::NONE_OF_CHECKER ); |
|
| 249 | + public static function getNoneOfChecker(?MediaWikiServices $services = null) { |
|
| 250 | + return self::getService($services, self::NONE_OF_CHECKER); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
| 254 | 254 | * @param MediaWikiServices|null $services |
| 255 | 255 | * @return ConstraintChecker |
| 256 | 256 | */ |
| 257 | - public static function getIntegerChecker( ?MediaWikiServices $services = null ) { |
|
| 258 | - return self::getService( $services, self::INTEGER_CHECKER ); |
|
| 257 | + public static function getIntegerChecker(?MediaWikiServices $services = null) { |
|
| 258 | + return self::getService($services, self::INTEGER_CHECKER); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
| 262 | 262 | * @param MediaWikiServices|null $services |
| 263 | 263 | * @return ConstraintChecker |
| 264 | 264 | */ |
| 265 | - public static function getCitationNeededChecker( ?MediaWikiServices $services = null ) { |
|
| 266 | - return self::getService( $services, self::CITATION_NEEDED_CHECKER ); |
|
| 265 | + public static function getCitationNeededChecker(?MediaWikiServices $services = null) { |
|
| 266 | + return self::getService($services, self::CITATION_NEEDED_CHECKER); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
| 270 | 270 | * @param MediaWikiServices|null $services |
| 271 | 271 | * @return ConstraintChecker |
| 272 | 272 | */ |
| 273 | - public static function getPropertyScopeChecker( ?MediaWikiServices $services = null ) { |
|
| 274 | - return self::getService( $services, self::PROPERTY_SCOPE_CHECKER ); |
|
| 273 | + public static function getPropertyScopeChecker(?MediaWikiServices $services = null) { |
|
| 274 | + return self::getService($services, self::PROPERTY_SCOPE_CHECKER); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
| 278 | 278 | * @param MediaWikiServices|null $services |
| 279 | 279 | * @return ConstraintChecker |
| 280 | 280 | */ |
| 281 | - public static function getContemporaryChecker( ?MediaWikiServices $services = null ) { |
|
| 282 | - return self::getService( $services, self::CONTEMPORARY_CHECKER ); |
|
| 281 | + public static function getContemporaryChecker(?MediaWikiServices $services = null) { |
|
| 282 | + return self::getService($services, self::CONTEMPORARY_CHECKER); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | /** |
| 286 | 286 | * @param MediaWikiServices|null $services |
| 287 | 287 | * @return LanguageChecker |
| 288 | 288 | */ |
| 289 | - public static function getLexemeLanguageChecker( ?MediaWikiServices $services = null ) { |
|
| 290 | - return self::getService( $services, self::LEXEME_LANGUAGE_CHECKER ); |
|
| 289 | + public static function getLexemeLanguageChecker(?MediaWikiServices $services = null) { |
|
| 290 | + return self::getService($services, self::LEXEME_LANGUAGE_CHECKER); |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | /** |
| 294 | 294 | * @param MediaWikiServices|null $services |
| 295 | 295 | * @return LabelInLanguageChecker |
| 296 | 296 | */ |
| 297 | - public static function getLabelInLanguageChecker( ?MediaWikiServices $services = null ) { |
|
| 298 | - return self::getService( $services, self::LABEL_IN_LANGUAGE_CHECKER ); |
|
| 297 | + public static function getLabelInLanguageChecker(?MediaWikiServices $services = null) { |
|
| 298 | + return self::getService($services, self::LABEL_IN_LANGUAGE_CHECKER); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @inheritDoc |
| 38 | 38 | */ |
| 39 | 39 | public function getType() { |
| 40 | - throw new LogicException( 'EntityContextCursor has no full associated context' ); |
|
| 40 | + throw new LogicException('EntityContextCursor has no full associated context'); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** @inheritDoc */ |
@@ -49,35 +49,35 @@ discard block |
||
| 49 | 49 | * @codeCoverageIgnore This method is not supported. |
| 50 | 50 | */ |
| 51 | 51 | public function getStatementPropertyId() { |
| 52 | - throw new LogicException( 'EntityContextCursor has no full associated context' ); |
|
| 52 | + throw new LogicException('EntityContextCursor has no full associated context'); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * @codeCoverageIgnore This method is not supported. |
| 57 | 57 | */ |
| 58 | 58 | public function getStatementGuid() { |
| 59 | - throw new LogicException( 'EntityContextCursor has no full associated context' ); |
|
| 59 | + throw new LogicException('EntityContextCursor has no full associated context'); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | 63 | * @codeCoverageIgnore This method is not supported. |
| 64 | 64 | */ |
| 65 | 65 | public function getSnakPropertyId() { |
| 66 | - throw new LogicException( 'EntityContextCursor has no full associated context' ); |
|
| 66 | + throw new LogicException('EntityContextCursor has no full associated context'); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * @codeCoverageIgnore This method is not supported. |
| 71 | 71 | */ |
| 72 | 72 | public function getSnakHash() { |
| 73 | - throw new LogicException( 'EntityContextCursor has no full associated context' ); |
|
| 73 | + throw new LogicException('EntityContextCursor has no full associated context'); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | 77 | * @codeCoverageIgnore This method is not supported. |
| 78 | 78 | */ |
| 79 | - public function &getMainArray( array &$container ) { |
|
| 80 | - throw new LogicException( 'EntityContextCursor cannot store check results' ); |
|
| 79 | + public function &getMainArray(array &$container) { |
|
| 80 | + throw new LogicException('EntityContextCursor cannot store check results'); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -86,14 +86,14 @@ discard block |
||
| 86 | 86 | * @param ?array $result must be null |
| 87 | 87 | * @param array[] &$container |
| 88 | 88 | */ |
| 89 | - public function storeCheckResultInArray( ?array $result, array &$container ) { |
|
| 90 | - if ( $result !== null ) { |
|
| 91 | - throw new LogicException( 'EntityContextCursor cannot store check results' ); |
|
| 89 | + public function storeCheckResultInArray(?array $result, array &$container) { |
|
| 90 | + if ($result !== null) { |
|
| 91 | + throw new LogicException('EntityContextCursor cannot store check results'); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | // this ensures that the claims array is present in the $container, |
| 95 | 95 | // populating it if necessary, even though we ignore the return value |
| 96 | - $this->getClaimsArray( $container ); |
|
| 96 | + $this->getClaimsArray($container); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | } |
@@ -86,29 +86,29 @@ |
||
| 86 | 86 | return $this->snakHash; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - protected function &getMainArray( array &$container ): array { |
|
| 90 | - $statementArray = &$this->getStatementArray( $container ); |
|
| 89 | + protected function &getMainArray(array &$container): array { |
|
| 90 | + $statementArray = &$this->getStatementArray($container); |
|
| 91 | 91 | |
| 92 | - if ( !array_key_exists( 'qualifiers', $statementArray ) ) { |
|
| 92 | + if (!array_key_exists('qualifiers', $statementArray)) { |
|
| 93 | 93 | $statementArray['qualifiers'] = []; |
| 94 | 94 | } |
| 95 | 95 | $qualifiersArray = &$statementArray['qualifiers']; |
| 96 | 96 | |
| 97 | 97 | $snakPropertyId = $this->getSnakPropertyId(); |
| 98 | - if ( !array_key_exists( $snakPropertyId, $qualifiersArray ) ) { |
|
| 98 | + if (!array_key_exists($snakPropertyId, $qualifiersArray)) { |
|
| 99 | 99 | $qualifiersArray[$snakPropertyId] = []; |
| 100 | 100 | } |
| 101 | 101 | $propertyArray = &$qualifiersArray[$snakPropertyId]; |
| 102 | 102 | |
| 103 | 103 | $snakHash = $this->getSnakHash(); |
| 104 | - foreach ( $propertyArray as &$potentialQualifierArray ) { |
|
| 105 | - if ( $potentialQualifierArray['hash'] === $snakHash ) { |
|
| 104 | + foreach ($propertyArray as &$potentialQualifierArray) { |
|
| 105 | + if ($potentialQualifierArray['hash'] === $snakHash) { |
|
| 106 | 106 | $qualifierArray = &$potentialQualifierArray; |
| 107 | 107 | break; |
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | - if ( !isset( $qualifierArray ) ) { |
|
| 111 | - $qualifierArray = [ 'hash' => $snakHash ]; |
|
| 110 | + if (!isset($qualifierArray)) { |
|
| 111 | + $qualifierArray = ['hash' => $snakHash]; |
|
| 112 | 112 | $propertyArray[] = &$qualifierArray; |
| 113 | 113 | } |
| 114 | 114 | |
@@ -78,12 +78,12 @@ |
||
| 78 | 78 | return $this->snakHash; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - protected function &getMainArray( array &$container ): array { |
|
| 82 | - $statementArray = &$this->getStatementArray( $container ); |
|
| 81 | + protected function &getMainArray(array &$container): array { |
|
| 82 | + $statementArray = &$this->getStatementArray($container); |
|
| 83 | 83 | |
| 84 | - if ( !array_key_exists( 'mainsnak', $statementArray ) ) { |
|
| 84 | + if (!array_key_exists('mainsnak', $statementArray)) { |
|
| 85 | 85 | $snakHash = $this->getSnakHash(); |
| 86 | - $statementArray['mainsnak'] = [ 'hash' => $snakHash ]; |
|
| 86 | + $statementArray['mainsnak'] = ['hash' => $snakHash]; |
|
| 87 | 87 | } |
| 88 | 88 | $mainsnakArray = &$statementArray['mainsnak']; |
| 89 | 89 | |
@@ -99,43 +99,43 @@ |
||
| 99 | 99 | return $this->referenceHash; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - protected function &getMainArray( array &$container ): array { |
|
| 103 | - $statementArray = &$this->getStatementArray( $container ); |
|
| 102 | + protected function &getMainArray(array &$container): array { |
|
| 103 | + $statementArray = &$this->getStatementArray($container); |
|
| 104 | 104 | |
| 105 | - if ( !array_key_exists( 'references', $statementArray ) ) { |
|
| 105 | + if (!array_key_exists('references', $statementArray)) { |
|
| 106 | 106 | $statementArray['references'] = []; |
| 107 | 107 | } |
| 108 | 108 | $referencesArray = &$statementArray['references']; |
| 109 | 109 | |
| 110 | 110 | $referenceHash = $this->getReferenceHash(); |
| 111 | - foreach ( $referencesArray as &$potentialReferenceArray ) { |
|
| 112 | - if ( $potentialReferenceArray['hash'] === $referenceHash ) { |
|
| 111 | + foreach ($referencesArray as &$potentialReferenceArray) { |
|
| 112 | + if ($potentialReferenceArray['hash'] === $referenceHash) { |
|
| 113 | 113 | $referenceArray = &$potentialReferenceArray; |
| 114 | 114 | break; |
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | - if ( !isset( $referenceArray ) ) { |
|
| 118 | - $referenceArray = [ 'hash' => $referenceHash, 'snaks' => [] ]; |
|
| 117 | + if (!isset($referenceArray)) { |
|
| 118 | + $referenceArray = ['hash' => $referenceHash, 'snaks' => []]; |
|
| 119 | 119 | $referencesArray[] = &$referenceArray; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | $snaksArray = &$referenceArray['snaks']; |
| 123 | 123 | |
| 124 | 124 | $snakPropertyId = $this->getSnakPropertyId(); |
| 125 | - if ( !array_key_exists( $snakPropertyId, $snaksArray ) ) { |
|
| 125 | + if (!array_key_exists($snakPropertyId, $snaksArray)) { |
|
| 126 | 126 | $snaksArray[$snakPropertyId] = []; |
| 127 | 127 | } |
| 128 | 128 | $propertyArray = &$snaksArray[$snakPropertyId]; |
| 129 | 129 | |
| 130 | 130 | $snakHash = $this->getSnakHash(); |
| 131 | - foreach ( $propertyArray as &$potentialSnakArray ) { |
|
| 132 | - if ( $potentialSnakArray['hash'] === $snakHash ) { |
|
| 131 | + foreach ($propertyArray as &$potentialSnakArray) { |
|
| 132 | + if ($potentialSnakArray['hash'] === $snakHash) { |
|
| 133 | 133 | $snakArray = &$potentialSnakArray; |
| 134 | 134 | break; |
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | - if ( !isset( $snakArray ) ) { |
|
| 138 | - $snakArray = [ 'hash' => $snakHash ]; |
|
| 137 | + if (!isset($snakArray)) { |
|
| 138 | + $snakArray = ['hash' => $snakHash]; |
|
| 139 | 139 | $propertyArray[] = &$snakArray; |
| 140 | 140 | } |
| 141 | 141 | |
@@ -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 | |
@@ -366,12 +365,12 @@ discard block |
||
| 366 | 365 | array $separators |
| 367 | 366 | ): CachedEntityIds { |
| 368 | 367 | $mainSnak = $statement->getMainSnak(); |
| 369 | - if ( !( $mainSnak instanceof PropertyValueSnak ) ) { |
|
| 370 | - return new CachedEntityIds( [], Metadata::blank() ); |
|
| 368 | + if (!($mainSnak instanceof PropertyValueSnak)) { |
|
| 369 | + return new CachedEntityIds([], Metadata::blank()); |
|
| 371 | 370 | } |
| 372 | 371 | |
| 373 | 372 | $propertyId = $statement->getPropertyId(); |
| 374 | - $pPredicateAndObject = "{$this->p( $propertyId )} ?otherStatement."; // p:P123 ?otherStatement. |
|
| 373 | + $pPredicateAndObject = "{$this->p($propertyId)} ?otherStatement."; // p:P123 ?otherStatement. |
|
| 375 | 374 | $otherStatementPredicateAndObject = $this->getSnakPredicateAndObject( |
| 376 | 375 | $entityId, |
| 377 | 376 | $mainSnak, |
@@ -380,57 +379,57 @@ discard block |
||
| 380 | 379 | |
| 381 | 380 | $isSeparator = []; |
| 382 | 381 | $unusedSeparators = []; |
| 383 | - foreach ( $separators as $separator ) { |
|
| 382 | + foreach ($separators as $separator) { |
|
| 384 | 383 | $isSeparator[$separator->getSerialization()] = true; |
| 385 | 384 | $unusedSeparators[$separator->getSerialization()] = $separator; |
| 386 | 385 | } |
| 387 | 386 | $separatorFilters = ''; |
| 388 | - foreach ( $statement->getQualifiers() as $qualifier ) { |
|
| 387 | + foreach ($statement->getQualifiers() as $qualifier) { |
|
| 389 | 388 | $qualPropertyId = $qualifier->getPropertyId(); |
| 390 | - if ( !( $isSeparator[$qualPropertyId->getSerialization()] ?? false ) ) { |
|
| 389 | + if (!($isSeparator[$qualPropertyId->getSerialization()] ?? false)) { |
|
| 391 | 390 | continue; |
| 392 | 391 | } |
| 393 | - unset( $unusedSeparators[$qualPropertyId->getSerialization()] ); |
|
| 392 | + unset($unusedSeparators[$qualPropertyId->getSerialization()]); |
|
| 394 | 393 | // only look for other statements with the same qualifier |
| 395 | - if ( $qualifier instanceof PropertyValueSnak ) { |
|
| 394 | + if ($qualifier instanceof PropertyValueSnak) { |
|
| 396 | 395 | $sepPredicateAndObject = $this->getSnakPredicateAndObject( |
| 397 | 396 | $entityId, |
| 398 | 397 | $qualifier, |
| 399 | 398 | RdfVocabulary::NSP_QUALIFIER |
| 400 | 399 | ); |
| 401 | 400 | $separatorFilters .= " ?otherStatement $sepPredicateAndObject\n"; |
| 402 | - } elseif ( $qualifier instanceof PropertyNoValueSnak ) { |
|
| 403 | - $sepPredicateAndObject = "a {$this->wdno( $qualPropertyId )}."; // a wdno:P123. |
|
| 401 | + } elseif ($qualifier instanceof PropertyNoValueSnak) { |
|
| 402 | + $sepPredicateAndObject = "a {$this->wdno($qualPropertyId)}."; // a wdno:P123. |
|
| 404 | 403 | $separatorFilters .= " ?otherStatement $sepPredicateAndObject\n"; |
| 405 | 404 | } else { |
| 406 | 405 | // "some value" / "unknown value" is always different from everything else, |
| 407 | 406 | // therefore the whole statement has no duplicates and we can return immediately |
| 408 | - return new CachedEntityIds( [], Metadata::blank() ); |
|
| 407 | + return new CachedEntityIds([], Metadata::blank()); |
|
| 409 | 408 | } |
| 410 | 409 | } |
| 411 | - foreach ( $unusedSeparators as $unusedSeparator ) { |
|
| 410 | + foreach ($unusedSeparators as $unusedSeparator) { |
|
| 412 | 411 | // exclude other statements which have a separator that this one lacks |
| 413 | - $separatorFilters .= " MINUS { ?otherStatement {$this->pq( $unusedSeparator )} []. }\n"; |
|
| 414 | - $separatorFilters .= " MINUS { ?otherStatement a {$this->wdno( $unusedSeparator )}. }\n"; |
|
| 412 | + $separatorFilters .= " MINUS { ?otherStatement {$this->pq($unusedSeparator)} []. }\n"; |
|
| 413 | + $separatorFilters .= " MINUS { ?otherStatement a {$this->wdno($unusedSeparator)}. }\n"; |
|
| 415 | 414 | } |
| 416 | 415 | |
| 417 | 416 | $query = <<<SPARQL |
| 418 | 417 | SELECT DISTINCT ?otherEntity WHERE { |
| 419 | 418 | ?otherEntity $pPredicateAndObject |
| 420 | 419 | ?otherStatement $otherStatementPredicateAndObject |
| 421 | - {$this->minusDeprecatedRank( '?otherStatement' )} |
|
| 422 | - FILTER(?otherEntity != {$this->wd( $entityId )}) |
|
| 420 | + {$this->minusDeprecatedRank('?otherStatement')} |
|
| 421 | + FILTER(?otherEntity != {$this->wd($entityId)}) |
|
| 423 | 422 | $separatorFilters |
| 424 | 423 | } |
| 425 | 424 | LIMIT 10 |
| 426 | 425 | SPARQL; |
| 427 | 426 | |
| 428 | - $results = [ $this->runQuery( $query, $this->primaryEndpoint ) ]; |
|
| 429 | - foreach ( $this->additionalEndpoints as $endpoint ) { |
|
| 430 | - $results[] = $this->runQuery( $query, $endpoint ); |
|
| 427 | + $results = [$this->runQuery($query, $this->primaryEndpoint)]; |
|
| 428 | + foreach ($this->additionalEndpoints as $endpoint) { |
|
| 429 | + $results[] = $this->runQuery($query, $endpoint); |
|
| 431 | 430 | } |
| 432 | 431 | |
| 433 | - return $this->getOtherEntities( $results ); |
|
| 432 | + return $this->getOtherEntities($results); |
|
| 434 | 433 | } |
| 435 | 434 | |
| 436 | 435 | /** |
@@ -449,40 +448,38 @@ discard block |
||
| 449 | 448 | bool $ignoreDeprecatedStatements |
| 450 | 449 | ): CachedEntityIds { |
| 451 | 450 | $propertyId = $snak->getPropertyId(); |
| 452 | - $pPredicateAndObject = "{$this->p( $propertyId )} ?otherStatement."; // p:P123 ?otherStatement. |
|
| 451 | + $pPredicateAndObject = "{$this->p($propertyId)} ?otherStatement."; // p:P123 ?otherStatement. |
|
| 453 | 452 | |
| 454 | 453 | $otherSubject = $type === Context::TYPE_QUALIFIER ? |
| 455 | - '?otherStatement' : |
|
| 456 | - "?otherStatement {$this->prov( 'wasDerivedFrom' )} ?reference.\n ?reference"; |
|
| 454 | + '?otherStatement' : "?otherStatement {$this->prov('wasDerivedFrom')} ?reference.\n ?reference"; |
|
| 457 | 455 | $otherPredicateAndObject = $this->getSnakPredicateAndObject( |
| 458 | 456 | $entityId, |
| 459 | 457 | $snak, |
| 460 | 458 | $type === Context::TYPE_QUALIFIER ? |
| 461 | - RdfVocabulary::NSP_QUALIFIER : |
|
| 462 | - RdfVocabulary::NSP_REFERENCE |
|
| 459 | + RdfVocabulary::NSP_QUALIFIER : RdfVocabulary::NSP_REFERENCE |
|
| 463 | 460 | ); |
| 464 | 461 | |
| 465 | 462 | $deprecatedFilter = ''; |
| 466 | - if ( $ignoreDeprecatedStatements ) { |
|
| 467 | - $deprecatedFilter = ' ' . $this->minusDeprecatedRank( '?otherStatement' ); |
|
| 463 | + if ($ignoreDeprecatedStatements) { |
|
| 464 | + $deprecatedFilter = ' '.$this->minusDeprecatedRank('?otherStatement'); |
|
| 468 | 465 | } |
| 469 | 466 | |
| 470 | 467 | $query = <<<SPARQL |
| 471 | 468 | SELECT DISTINCT ?otherEntity WHERE { |
| 472 | 469 | ?otherEntity $pPredicateAndObject |
| 473 | 470 | $otherSubject $otherPredicateAndObject |
| 474 | - FILTER(?otherEntity != {$this->wd( $entityId )}) |
|
| 471 | + FILTER(?otherEntity != {$this->wd($entityId)}) |
|
| 475 | 472 | $deprecatedFilter |
| 476 | 473 | } |
| 477 | 474 | LIMIT 10 |
| 478 | 475 | SPARQL; |
| 479 | 476 | |
| 480 | - $results = [ $this->runQuery( $query, $this->primaryEndpoint ) ]; |
|
| 481 | - foreach ( $this->additionalEndpoints as $endpoint ) { |
|
| 482 | - $results[] = $this->runQuery( $query, $endpoint ); |
|
| 477 | + $results = [$this->runQuery($query, $this->primaryEndpoint)]; |
|
| 478 | + foreach ($this->additionalEndpoints as $endpoint) { |
|
| 479 | + $results[] = $this->runQuery($query, $endpoint); |
|
| 483 | 480 | } |
| 484 | 481 | |
| 485 | - return $this->getOtherEntities( $results ); |
|
| 482 | + return $this->getOtherEntities($results); |
|
| 486 | 483 | } |
| 487 | 484 | |
| 488 | 485 | /** |
@@ -513,13 +510,13 @@ discard block |
||
| 513 | 510 | $writer->start(); |
| 514 | 511 | $writer->drain(); |
| 515 | 512 | $placeholder1 = 'wbqc'; |
| 516 | - $placeholder2 = 'x' . wfRandomString( 32 ); |
|
| 517 | - $writer->about( $placeholder1, $placeholder2 ); |
|
| 513 | + $placeholder2 = 'x'.wfRandomString(32); |
|
| 514 | + $writer->about($placeholder1, $placeholder2); |
|
| 518 | 515 | |
| 519 | 516 | $propertyId = $snak->getPropertyId(); |
| 520 | 517 | $pid = $propertyId->getSerialization(); |
| 521 | - $propertyRepository = $this->rdfVocabulary->getEntityRepositoryName( $propertyId ); |
|
| 522 | - $entityRepository = $this->rdfVocabulary->getEntityRepositoryName( $entityId ); |
|
| 518 | + $propertyRepository = $this->rdfVocabulary->getEntityRepositoryName($propertyId); |
|
| 519 | + $entityRepository = $this->rdfVocabulary->getEntityRepositoryName($entityId); |
|
| 523 | 520 | $propertyNamespace = $this->rdfVocabulary->propertyNamespaceNames[$propertyRepository][$namespace]; |
| 524 | 521 | $value = $snak->getDataValue(); |
| 525 | 522 | if ( |
@@ -550,21 +547,21 @@ discard block |
||
| 550 | 547 | $writer, |
| 551 | 548 | $propertyNamespace, |
| 552 | 549 | $pid, |
| 553 | - $this->propertyDataTypeLookup->getDataTypeIdForProperty( $propertyId ), |
|
| 550 | + $this->propertyDataTypeLookup->getDataTypeIdForProperty($propertyId), |
|
| 554 | 551 | $this->rdfVocabulary->statementNamespaceNames[$entityRepository][RdfVocabulary::NS_VALUE], // should be unused |
| 555 | 552 | $snak |
| 556 | 553 | ); |
| 557 | 554 | } |
| 558 | 555 | |
| 559 | 556 | $triple = $writer->drain(); // wbqc:xRANDOM ps:PID "value". or similar |
| 560 | - return trim( str_replace( "$placeholder1:$placeholder2", '', $triple ) ); |
|
| 557 | + return trim(str_replace("$placeholder1:$placeholder2", '', $triple)); |
|
| 561 | 558 | } |
| 562 | 559 | |
| 563 | 560 | /** |
| 564 | 561 | * Return SPARQL code for a string literal with $text as content. |
| 565 | 562 | */ |
| 566 | - private function stringLiteral( string $text ): string { |
|
| 567 | - return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"'; |
|
| 563 | + private function stringLiteral(string $text): string { |
|
| 564 | + return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"'; |
|
| 568 | 565 | } |
| 569 | 566 | |
| 570 | 567 | /** |
@@ -574,26 +571,26 @@ discard block |
||
| 574 | 571 | * |
| 575 | 572 | * @return CachedEntityIds |
| 576 | 573 | */ |
| 577 | - private function getOtherEntities( array $results ): CachedEntityIds { |
|
| 574 | + private function getOtherEntities(array $results): CachedEntityIds { |
|
| 578 | 575 | $allResultBindings = []; |
| 579 | 576 | $metadatas = []; |
| 580 | 577 | |
| 581 | - foreach ( $results as $result ) { |
|
| 578 | + foreach ($results as $result) { |
|
| 582 | 579 | $metadatas[] = $result->getMetadata(); |
| 583 | - $allResultBindings = array_merge( $allResultBindings, $result->getArray()['results']['bindings'] ); |
|
| 580 | + $allResultBindings = array_merge($allResultBindings, $result->getArray()['results']['bindings']); |
|
| 584 | 581 | } |
| 585 | 582 | |
| 586 | 583 | $entityIds = array_map( |
| 587 | - function ( $resultBindings ) { |
|
| 584 | + function($resultBindings) { |
|
| 588 | 585 | $entityIRI = $resultBindings['otherEntity']['value']; |
| 589 | - foreach ( $this->entityPrefixes as $entityPrefix ) { |
|
| 590 | - $entityPrefixLength = strlen( $entityPrefix ); |
|
| 591 | - if ( substr( $entityIRI, 0, $entityPrefixLength ) === $entityPrefix ) { |
|
| 586 | + foreach ($this->entityPrefixes as $entityPrefix) { |
|
| 587 | + $entityPrefixLength = strlen($entityPrefix); |
|
| 588 | + if (substr($entityIRI, 0, $entityPrefixLength) === $entityPrefix) { |
|
| 592 | 589 | try { |
| 593 | 590 | return $this->entityIdParser->parse( |
| 594 | - substr( $entityIRI, $entityPrefixLength ) |
|
| 591 | + substr($entityIRI, $entityPrefixLength) |
|
| 595 | 592 | ); |
| 596 | - } catch ( EntityIdParsingException $e ) { |
|
| 593 | + } catch (EntityIdParsingException $e) { |
|
| 597 | 594 | // fall through |
| 598 | 595 | } |
| 599 | 596 | } |
@@ -607,8 +604,8 @@ discard block |
||
| 607 | 604 | ); |
| 608 | 605 | |
| 609 | 606 | return new CachedEntityIds( |
| 610 | - array_values( array_filter( array_unique( $entityIds ) ) ), |
|
| 611 | - Metadata::merge( $metadatas ) |
|
| 607 | + array_values(array_filter(array_unique($entityIds))), |
|
| 608 | + Metadata::merge($metadatas) |
|
| 612 | 609 | ); |
| 613 | 610 | } |
| 614 | 611 | |
@@ -616,43 +613,43 @@ discard block |
||
| 616 | 613 | * @throws SparqlHelperException if the query times out or some other error occurs |
| 617 | 614 | * @throws ConstraintParameterException if the $regex is invalid |
| 618 | 615 | */ |
| 619 | - public function matchesRegularExpression( string $text, string $regex ): bool { |
|
| 616 | + public function matchesRegularExpression(string $text, string $regex): bool { |
|
| 620 | 617 | // caching wrapper around matchesRegularExpressionWithSparql |
| 621 | 618 | |
| 622 | - $textHash = hash( 'sha256', $text ); |
|
| 619 | + $textHash = hash('sha256', $text); |
|
| 623 | 620 | $cacheKey = $this->cache->makeKey( |
| 624 | 621 | 'WikibaseQualityConstraints', // extension |
| 625 | 622 | 'regex', // action |
| 626 | 623 | 'WDQS-Java', // regex flavor |
| 627 | - hash( 'sha256', $regex ) |
|
| 624 | + hash('sha256', $regex) |
|
| 628 | 625 | ); |
| 629 | 626 | |
| 630 | 627 | $cacheMapArray = $this->cache->getWithSetCallback( |
| 631 | 628 | $cacheKey, |
| 632 | 629 | WANObjectCache::TTL_DAY, |
| 633 | - function ( $cacheMapArray ) use ( $text, $regex, $textHash ) { |
|
| 630 | + function($cacheMapArray) use ($text, $regex, $textHash) { |
|
| 634 | 631 | // Initialize the cache map if not set |
| 635 | - if ( $cacheMapArray === false ) { |
|
| 632 | + if ($cacheMapArray === false) { |
|
| 636 | 633 | $key = 'wikibase.quality.constraints.regex.cache.refresh.init'; |
| 637 | - $this->dataFactory->increment( $key ); |
|
| 634 | + $this->dataFactory->increment($key); |
|
| 638 | 635 | return []; |
| 639 | 636 | } |
| 640 | 637 | |
| 641 | 638 | $key = 'wikibase.quality.constraints.regex.cache.refresh'; |
| 642 | - $this->dataFactory->increment( $key ); |
|
| 643 | - $cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $this->cacheMapSize ); |
|
| 644 | - if ( $cacheMap->has( $textHash ) ) { |
|
| 639 | + $this->dataFactory->increment($key); |
|
| 640 | + $cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $this->cacheMapSize); |
|
| 641 | + if ($cacheMap->has($textHash)) { |
|
| 645 | 642 | $key = 'wikibase.quality.constraints.regex.cache.refresh.hit'; |
| 646 | - $this->dataFactory->increment( $key ); |
|
| 647 | - $cacheMap->get( $textHash ); // ping cache |
|
| 643 | + $this->dataFactory->increment($key); |
|
| 644 | + $cacheMap->get($textHash); // ping cache |
|
| 648 | 645 | } else { |
| 649 | 646 | $key = 'wikibase.quality.constraints.regex.cache.refresh.miss'; |
| 650 | - $this->dataFactory->increment( $key ); |
|
| 647 | + $this->dataFactory->increment($key); |
|
| 651 | 648 | try { |
| 652 | - $matches = $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
| 653 | - } catch ( ConstraintParameterException $e ) { |
|
| 654 | - $matches = $this->serializeConstraintParameterException( $e ); |
|
| 655 | - } catch ( SparqlHelperException $e ) { |
|
| 649 | + $matches = $this->matchesRegularExpressionWithSparql($text, $regex); |
|
| 650 | + } catch (ConstraintParameterException $e) { |
|
| 651 | + $matches = $this->serializeConstraintParameterException($e); |
|
| 652 | + } catch (SparqlHelperException $e) { |
|
| 656 | 653 | // don’t cache this |
| 657 | 654 | return $cacheMap->toArray(); |
| 658 | 655 | } |
@@ -676,42 +673,42 @@ discard block |
||
| 676 | 673 | ] |
| 677 | 674 | ); |
| 678 | 675 | |
| 679 | - if ( isset( $cacheMapArray[$textHash] ) ) { |
|
| 676 | + if (isset($cacheMapArray[$textHash])) { |
|
| 680 | 677 | $key = 'wikibase.quality.constraints.regex.cache.hit'; |
| 681 | - $this->dataFactory->increment( $key ); |
|
| 678 | + $this->dataFactory->increment($key); |
|
| 682 | 679 | $matches = $cacheMapArray[$textHash]; |
| 683 | - if ( is_bool( $matches ) ) { |
|
| 680 | + if (is_bool($matches)) { |
|
| 684 | 681 | return $matches; |
| 685 | - } elseif ( is_array( $matches ) && |
|
| 686 | - $matches['type'] == ConstraintParameterException::class ) { |
|
| 687 | - throw $this->deserializeConstraintParameterException( $matches ); |
|
| 682 | + } elseif (is_array($matches) && |
|
| 683 | + $matches['type'] == ConstraintParameterException::class) { |
|
| 684 | + throw $this->deserializeConstraintParameterException($matches); |
|
| 688 | 685 | } else { |
| 689 | 686 | throw new UnexpectedValueException( |
| 690 | - 'Value of unknown type in object cache (' . |
|
| 691 | - 'cache key: ' . $cacheKey . ', ' . |
|
| 692 | - 'cache map key: ' . $textHash . ', ' . |
|
| 693 | - 'value type: ' . get_debug_type( $matches ) . ')' |
|
| 687 | + 'Value of unknown type in object cache ('. |
|
| 688 | + 'cache key: '.$cacheKey.', '. |
|
| 689 | + 'cache map key: '.$textHash.', '. |
|
| 690 | + 'value type: '.get_debug_type($matches).')' |
|
| 694 | 691 | ); |
| 695 | 692 | } |
| 696 | 693 | } else { |
| 697 | 694 | $key = 'wikibase.quality.constraints.regex.cache.miss'; |
| 698 | - $this->dataFactory->increment( $key ); |
|
| 699 | - return $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
| 695 | + $this->dataFactory->increment($key); |
|
| 696 | + return $this->matchesRegularExpressionWithSparql($text, $regex); |
|
| 700 | 697 | } |
| 701 | 698 | } |
| 702 | 699 | |
| 703 | - private function serializeConstraintParameterException( ConstraintParameterException $cpe ): array { |
|
| 700 | + private function serializeConstraintParameterException(ConstraintParameterException $cpe): array { |
|
| 704 | 701 | return [ |
| 705 | 702 | 'type' => ConstraintParameterException::class, |
| 706 | - 'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ), |
|
| 703 | + 'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()), |
|
| 707 | 704 | ]; |
| 708 | 705 | } |
| 709 | 706 | |
| 710 | - private function deserializeConstraintParameterException( array $serialization ): ConstraintParameterException { |
|
| 707 | + private function deserializeConstraintParameterException(array $serialization): ConstraintParameterException { |
|
| 711 | 708 | $message = $this->violationMessageDeserializer->deserialize( |
| 712 | 709 | $serialization['violationMessage'] |
| 713 | 710 | ); |
| 714 | - return new ConstraintParameterException( $message ); |
|
| 711 | + return new ConstraintParameterException($message); |
|
| 715 | 712 | } |
| 716 | 713 | |
| 717 | 714 | /** |
@@ -721,25 +718,25 @@ discard block |
||
| 721 | 718 | * @throws SparqlHelperException if the query times out or some other error occurs |
| 722 | 719 | * @throws ConstraintParameterException if the $regex is invalid |
| 723 | 720 | */ |
| 724 | - public function matchesRegularExpressionWithSparql( string $text, string $regex ): bool { |
|
| 725 | - $textStringLiteral = $this->stringLiteral( $text ); |
|
| 726 | - $regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' ); |
|
| 721 | + public function matchesRegularExpressionWithSparql(string $text, string $regex): bool { |
|
| 722 | + $textStringLiteral = $this->stringLiteral($text); |
|
| 723 | + $regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$'); |
|
| 727 | 724 | |
| 728 | 725 | $query = <<<EOF |
| 729 | 726 | SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {} |
| 730 | 727 | EOF; |
| 731 | 728 | |
| 732 | - $result = $this->runQuery( $query, $this->primaryEndpoint, false ); |
|
| 729 | + $result = $this->runQuery($query, $this->primaryEndpoint, false); |
|
| 733 | 730 | |
| 734 | 731 | $vars = $result->getArray()['results']['bindings'][0]; |
| 735 | - if ( array_key_exists( 'matches', $vars ) ) { |
|
| 732 | + if (array_key_exists('matches', $vars)) { |
|
| 736 | 733 | // true or false ⇒ regex okay, text matches or not |
| 737 | 734 | return $vars['matches']['value'] === 'true'; |
| 738 | 735 | } else { |
| 739 | 736 | // empty result: regex broken |
| 740 | 737 | throw new ConstraintParameterException( |
| 741 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
| 742 | - ->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
| 738 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
| 739 | + ->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE) |
|
| 743 | 740 | ); |
| 744 | 741 | } |
| 745 | 742 | } |
@@ -747,14 +744,14 @@ discard block |
||
| 747 | 744 | /** |
| 748 | 745 | * Check whether the text content of an error response indicates a query timeout. |
| 749 | 746 | */ |
| 750 | - public function isTimeout( string $responseContent ): bool { |
|
| 751 | - $timeoutRegex = implode( '|', array_map( |
|
| 752 | - static function ( $fqn ) { |
|
| 753 | - return preg_quote( $fqn, '/' ); |
|
| 747 | + public function isTimeout(string $responseContent): bool { |
|
| 748 | + $timeoutRegex = implode('|', array_map( |
|
| 749 | + static function($fqn) { |
|
| 750 | + return preg_quote($fqn, '/'); |
|
| 754 | 751 | }, |
| 755 | 752 | $this->timeoutExceptionClasses |
| 756 | - ) ); |
|
| 757 | - return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent ); |
|
| 753 | + )); |
|
| 754 | + return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent); |
|
| 758 | 755 | } |
| 759 | 756 | |
| 760 | 757 | /** |
@@ -766,17 +763,17 @@ discard block |
||
| 766 | 763 | * @return int|bool the max-age (in seconds) |
| 767 | 764 | * or a plain boolean if no max-age can be determined |
| 768 | 765 | */ |
| 769 | - public function getCacheMaxAge( array $responseHeaders ) { |
|
| 766 | + public function getCacheMaxAge(array $responseHeaders) { |
|
| 770 | 767 | if ( |
| 771 | - array_key_exists( 'x-cache-status', $responseHeaders ) && |
|
| 772 | - preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] ) |
|
| 768 | + array_key_exists('x-cache-status', $responseHeaders) && |
|
| 769 | + preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0]) |
|
| 773 | 770 | ) { |
| 774 | 771 | $maxage = []; |
| 775 | 772 | if ( |
| 776 | - array_key_exists( 'cache-control', $responseHeaders ) && |
|
| 777 | - preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage ) |
|
| 773 | + array_key_exists('cache-control', $responseHeaders) && |
|
| 774 | + preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage) |
|
| 778 | 775 | ) { |
| 779 | - return intval( $maxage[1] ); |
|
| 776 | + return intval($maxage[1]); |
|
| 780 | 777 | } else { |
| 781 | 778 | return true; |
| 782 | 779 | } |
@@ -797,34 +794,34 @@ discard block |
||
| 797 | 794 | * or SparlHelper::EMPTY_RETRY_AFTER if there is an empty Retry-After |
| 798 | 795 | * or SparlHelper::INVALID_RETRY_AFTER if there is something wrong with the format |
| 799 | 796 | */ |
| 800 | - public function getThrottling( MWHttpRequest $request ) { |
|
| 801 | - $retryAfterValue = $request->getResponseHeader( 'Retry-After' ); |
|
| 802 | - if ( $retryAfterValue === null ) { |
|
| 797 | + public function getThrottling(MWHttpRequest $request) { |
|
| 798 | + $retryAfterValue = $request->getResponseHeader('Retry-After'); |
|
| 799 | + if ($retryAfterValue === null) { |
|
| 803 | 800 | return self::NO_RETRY_AFTER; |
| 804 | 801 | } |
| 805 | 802 | |
| 806 | - $trimmedRetryAfterValue = trim( $retryAfterValue ); |
|
| 807 | - if ( $trimmedRetryAfterValue === '' ) { |
|
| 803 | + $trimmedRetryAfterValue = trim($retryAfterValue); |
|
| 804 | + if ($trimmedRetryAfterValue === '') { |
|
| 808 | 805 | return self::EMPTY_RETRY_AFTER; |
| 809 | 806 | } |
| 810 | 807 | |
| 811 | - if ( is_numeric( $trimmedRetryAfterValue ) ) { |
|
| 812 | - $delaySeconds = (int)$trimmedRetryAfterValue; |
|
| 813 | - if ( $delaySeconds >= 0 ) { |
|
| 814 | - return $this->getTimestampInFuture( new DateInterval( 'PT' . $delaySeconds . 'S' ) ); |
|
| 808 | + if (is_numeric($trimmedRetryAfterValue)) { |
|
| 809 | + $delaySeconds = (int) $trimmedRetryAfterValue; |
|
| 810 | + if ($delaySeconds >= 0) { |
|
| 811 | + return $this->getTimestampInFuture(new DateInterval('PT'.$delaySeconds.'S')); |
|
| 815 | 812 | } |
| 816 | 813 | } else { |
| 817 | - $return = strtotime( $trimmedRetryAfterValue ); |
|
| 818 | - if ( $return !== false ) { |
|
| 819 | - return new ConvertibleTimestamp( $return ); |
|
| 814 | + $return = strtotime($trimmedRetryAfterValue); |
|
| 815 | + if ($return !== false) { |
|
| 816 | + return new ConvertibleTimestamp($return); |
|
| 820 | 817 | } |
| 821 | 818 | } |
| 822 | 819 | return self::INVALID_RETRY_AFTER; |
| 823 | 820 | } |
| 824 | 821 | |
| 825 | - private function getTimestampInFuture( DateInterval $delta ): ConvertibleTimestamp { |
|
| 822 | + private function getTimestampInFuture(DateInterval $delta): ConvertibleTimestamp { |
|
| 826 | 823 | $now = new ConvertibleTimestamp(); |
| 827 | - return new ConvertibleTimestamp( $now->timestamp->add( $delta ) ); |
|
| 824 | + return new ConvertibleTimestamp($now->timestamp->add($delta)); |
|
| 828 | 825 | } |
| 829 | 826 | |
| 830 | 827 | /** |
@@ -839,64 +836,63 @@ discard block |
||
| 839 | 836 | * |
| 840 | 837 | * @throws SparqlHelperException if the query times out or some other error occurs |
| 841 | 838 | */ |
| 842 | - protected function runQuery( string $query, string $endpoint, bool $needsPrefixes = true ): CachedQueryResults { |
|
| 843 | - if ( $this->throttlingLock->isLocked( self::EXPIRY_LOCK_ID ) ) { |
|
| 844 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
| 839 | + protected function runQuery(string $query, string $endpoint, bool $needsPrefixes = true): CachedQueryResults { |
|
| 840 | + if ($this->throttlingLock->isLocked(self::EXPIRY_LOCK_ID)) { |
|
| 841 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
| 845 | 842 | throw new TooManySparqlRequestsException(); |
| 846 | 843 | } |
| 847 | 844 | |
| 848 | - if ( $this->sparqlHasWikibaseSupport ) { |
|
| 845 | + if ($this->sparqlHasWikibaseSupport) { |
|
| 849 | 846 | $needsPrefixes = false; |
| 850 | 847 | } |
| 851 | 848 | |
| 852 | - if ( $needsPrefixes ) { |
|
| 853 | - $query = $this->prefixes . $query; |
|
| 849 | + if ($needsPrefixes) { |
|
| 850 | + $query = $this->prefixes.$query; |
|
| 854 | 851 | } |
| 855 | - $query = "#wbqc\n" . $query; |
|
| 852 | + $query = "#wbqc\n".$query; |
|
| 856 | 853 | |
| 857 | - $url = $endpoint . '?' . http_build_query( |
|
| 854 | + $url = $endpoint.'?'.http_build_query( |
|
| 858 | 855 | [ |
| 859 | 856 | 'query' => $query, |
| 860 | 857 | 'format' => 'json', |
| 861 | 858 | 'maxQueryTimeMillis' => $this->maxQueryTimeMillis, |
| 862 | 859 | ], |
| 863 | - '', ini_get( 'arg_separator.output' ), |
|
| 860 | + '', ini_get('arg_separator.output'), |
|
| 864 | 861 | // encode spaces with %20, not + |
| 865 | 862 | PHP_QUERY_RFC3986 |
| 866 | 863 | ); |
| 867 | 864 | |
| 868 | 865 | $options = [ |
| 869 | 866 | 'method' => 'GET', |
| 870 | - 'timeout' => (int)round( ( $this->maxQueryTimeMillis + 1000 ) / 1000 ), |
|
| 867 | + 'timeout' => (int) round(($this->maxQueryTimeMillis + 1000) / 1000), |
|
| 871 | 868 | 'connectTimeout' => 'default', |
| 872 | 869 | 'userAgent' => $this->defaultUserAgent, |
| 873 | 870 | ]; |
| 874 | - $request = $this->requestFactory->create( $url, $options, __METHOD__ ); |
|
| 875 | - $startTime = microtime( true ); |
|
| 871 | + $request = $this->requestFactory->create($url, $options, __METHOD__); |
|
| 872 | + $startTime = microtime(true); |
|
| 876 | 873 | $requestStatus = $request->execute(); |
| 877 | - $endTime = microtime( true ); |
|
| 874 | + $endTime = microtime(true); |
|
| 878 | 875 | $this->dataFactory->timing( |
| 879 | 876 | 'wikibase.quality.constraints.sparql.timing', |
| 880 | - ( $endTime - $startTime ) * 1000 |
|
| 877 | + ($endTime - $startTime) * 1000 |
|
| 881 | 878 | ); |
| 882 | 879 | |
| 883 | - $this->guardAgainstTooManyRequestsError( $request ); |
|
| 880 | + $this->guardAgainstTooManyRequestsError($request); |
|
| 884 | 881 | |
| 885 | - $maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() ); |
|
| 886 | - if ( $maxAge ) { |
|
| 887 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' ); |
|
| 882 | + $maxAge = $this->getCacheMaxAge($request->getResponseHeaders()); |
|
| 883 | + if ($maxAge) { |
|
| 884 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.cached'); |
|
| 888 | 885 | } |
| 889 | 886 | |
| 890 | - if ( $requestStatus->isOK() ) { |
|
| 887 | + if ($requestStatus->isOK()) { |
|
| 891 | 888 | $json = $request->getContent(); |
| 892 | - $jsonStatus = FormatJson::parse( $json, FormatJson::FORCE_ASSOC ); |
|
| 893 | - if ( $jsonStatus->isOK() ) { |
|
| 889 | + $jsonStatus = FormatJson::parse($json, FormatJson::FORCE_ASSOC); |
|
| 890 | + if ($jsonStatus->isOK()) { |
|
| 894 | 891 | return new CachedQueryResults( |
| 895 | 892 | $jsonStatus->getValue(), |
| 896 | 893 | Metadata::ofCachingMetadata( |
| 897 | 894 | $maxAge ? |
| 898 | - CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) : |
|
| 899 | - CachingMetadata::fresh() |
|
| 895 | + CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh() |
|
| 900 | 896 | ) |
| 901 | 897 | ); |
| 902 | 898 | } else { |
@@ -913,9 +909,9 @@ discard block |
||
| 913 | 909 | // fall through to general error handling |
| 914 | 910 | } |
| 915 | 911 | |
| 916 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' ); |
|
| 912 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.error'); |
|
| 917 | 913 | |
| 918 | - if ( $this->isTimeout( $request->getContent() ) ) { |
|
| 914 | + if ($this->isTimeout($request->getContent())) { |
|
| 919 | 915 | $this->dataFactory->increment( |
| 920 | 916 | 'wikibase.quality.constraints.sparql.error.timeout' |
| 921 | 917 | ); |
@@ -930,29 +926,29 @@ discard block |
||
| 930 | 926 | * @param MWHttpRequest $request |
| 931 | 927 | * @throws TooManySparqlRequestsException |
| 932 | 928 | */ |
| 933 | - private function guardAgainstTooManyRequestsError( MWHttpRequest $request ): void { |
|
| 934 | - if ( $request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS ) { |
|
| 929 | + private function guardAgainstTooManyRequestsError(MWHttpRequest $request): void { |
|
| 930 | + if ($request->getStatus() !== self::HTTP_TOO_MANY_REQUESTS) { |
|
| 935 | 931 | return; |
| 936 | 932 | } |
| 937 | 933 | |
| 938 | 934 | $fallbackBlockDuration = $this->sparqlThrottlingFallbackDuration; |
| 939 | 935 | |
| 940 | - if ( $fallbackBlockDuration < 0 ) { |
|
| 941 | - throw new InvalidArgumentException( 'Fallback duration must be positive int but is: ' . |
|
| 942 | - $fallbackBlockDuration ); |
|
| 936 | + if ($fallbackBlockDuration < 0) { |
|
| 937 | + throw new InvalidArgumentException('Fallback duration must be positive int but is: '. |
|
| 938 | + $fallbackBlockDuration); |
|
| 943 | 939 | } |
| 944 | 940 | |
| 945 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.throttling' ); |
|
| 946 | - $throttlingUntil = $this->getThrottling( $request ); |
|
| 947 | - if ( !( $throttlingUntil instanceof ConvertibleTimestamp ) ) { |
|
| 948 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid( $request ); |
|
| 941 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.throttling'); |
|
| 942 | + $throttlingUntil = $this->getThrottling($request); |
|
| 943 | + if (!($throttlingUntil instanceof ConvertibleTimestamp)) { |
|
| 944 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterInvalid($request); |
|
| 949 | 945 | $this->throttlingLock->lock( |
| 950 | 946 | self::EXPIRY_LOCK_ID, |
| 951 | - $this->getTimestampInFuture( new DateInterval( 'PT' . $fallbackBlockDuration . 'S' ) ) |
|
| 947 | + $this->getTimestampInFuture(new DateInterval('PT'.$fallbackBlockDuration.'S')) |
|
| 952 | 948 | ); |
| 953 | 949 | } else { |
| 954 | - $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent( $throttlingUntil, $request ); |
|
| 955 | - $this->throttlingLock->lock( self::EXPIRY_LOCK_ID, $throttlingUntil ); |
|
| 950 | + $this->loggingHelper->logSparqlHelperTooManyRequestsRetryAfterPresent($throttlingUntil, $request); |
|
| 951 | + $this->throttlingLock->lock(self::EXPIRY_LOCK_ID, $throttlingUntil); |
|
| 956 | 952 | } |
| 957 | 953 | throw new TooManySparqlRequestsException(); |
| 958 | 954 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @return string |
| 29 | 29 | */ |
| 30 | 30 | public function getTime() { |
| 31 | - return gmdate( '+Y-m-d\TH:i:s\Z' ); |
|
| 31 | + return gmdate('+Y-m-d\TH:i:s\Z'); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** @inheritDoc */ |
@@ -43,12 +43,12 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | /** @inheritDoc */ |
| 45 | 45 | public function getArrayValue() { |
| 46 | - throw new LogicException( 'NowValue should never be serialized' ); |
|
| 46 | + throw new LogicException('NowValue should never be serialized'); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** @inheritDoc */ |
| 50 | - public function equals( $value ) { |
|
| 51 | - return get_class( $value ) === self::class; |
|
| 50 | + public function equals($value) { |
|
| 51 | + return get_class($value) === self::class; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | } |