jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/402882 )
Change subject: Declare ConstraintChecker’s supported and default context types ...................................................................... Declare ConstraintChecker’s supported and default context types ConstraintChecker::getSupportedContextTypes() describes which context types (scopes) a constraint type supports, and getDefaultContextTypes() describes which should be checked by default. Using this information, the constraint scope parameter can be parsed and validated in a single location (most likely DelegatingConstraintChecker) without duplicating error handling code in several locations. Bug: T183542 Change-Id: I6720b4a984a6ba2daa7425a6de21a30e09af22db --- M src/ConstraintCheck/Checker/CommonsLinkChecker.php M src/ConstraintCheck/Checker/ConflictsWithChecker.php M src/ConstraintCheck/Checker/DiffWithinRangeChecker.php M src/ConstraintCheck/Checker/FormatChecker.php M src/ConstraintCheck/Checker/InverseChecker.php M src/ConstraintCheck/Checker/ItemChecker.php M src/ConstraintCheck/Checker/MandatoryQualifiersChecker.php M src/ConstraintCheck/Checker/MultiValueChecker.php M src/ConstraintCheck/Checker/OneOfChecker.php M src/ConstraintCheck/Checker/QualifierChecker.php M src/ConstraintCheck/Checker/QualifiersChecker.php M src/ConstraintCheck/Checker/RangeChecker.php M src/ConstraintCheck/Checker/ReferenceChecker.php M src/ConstraintCheck/Checker/SingleValueChecker.php M src/ConstraintCheck/Checker/SymmetricChecker.php M src/ConstraintCheck/Checker/TargetRequiredClaimChecker.php M src/ConstraintCheck/Checker/TypeChecker.php M src/ConstraintCheck/Checker/UniqueValueChecker.php M src/ConstraintCheck/Checker/ValueOnlyChecker.php M src/ConstraintCheck/Checker/ValueTypeChecker.php M src/ConstraintCheck/ConstraintChecker.php M tests/phpunit/Fake/FakeChecker.php 22 files changed, 506 insertions(+), 0 deletions(-) Approvals: Jonas Kress (WMDE): Looks good to me, approved jenkins-bot: Verified diff --git a/src/ConstraintCheck/Checker/CommonsLinkChecker.php b/src/ConstraintCheck/Checker/CommonsLinkChecker.php index 59e0f1e..d6b792c 100644 --- a/src/ConstraintCheck/Checker/CommonsLinkChecker.php +++ b/src/ConstraintCheck/Checker/CommonsLinkChecker.php @@ -52,6 +52,28 @@ } /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getSupportedContextTypes() { + return [ + Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_QUALIFIER => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_REFERENCE => CheckResult::STATUS_COMPLIANCE, + ]; + } + + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getDefaultContextTypes() { + return [ + Context::TYPE_STATEMENT, + Context::TYPE_QUALIFIER, + Context::TYPE_REFERENCE, + ]; + } + + /** * Get the number of a namespace on Wikimedia Commons (commonswiki). * All namespaces not known to this function will be looked up by the TitleParser. * diff --git a/src/ConstraintCheck/Checker/ConflictsWithChecker.php b/src/ConstraintCheck/Checker/ConflictsWithChecker.php index b2f4ddc..e48271e 100644 --- a/src/ConstraintCheck/Checker/ConflictsWithChecker.php +++ b/src/ConstraintCheck/Checker/ConflictsWithChecker.php @@ -60,6 +60,30 @@ } /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getSupportedContextTypes() { + return [ + Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + // TODO T175562 + Context::TYPE_QUALIFIER => CheckResult::STATUS_TODO, + Context::TYPE_REFERENCE => CheckResult::STATUS_TODO, + ]; + } + + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getDefaultContextTypes() { + return [ + Context::TYPE_STATEMENT, + // TODO T175562 + // Context::TYPE_QUALIFIER, + // Context::TYPE_REFERENCE, + ]; + } + + /** * Checks 'Conflicts with' constraint. * * @param Context $context diff --git a/src/ConstraintCheck/Checker/DiffWithinRangeChecker.php b/src/ConstraintCheck/Checker/DiffWithinRangeChecker.php index 3f48e92..4071d70 100644 --- a/src/ConstraintCheck/Checker/DiffWithinRangeChecker.php +++ b/src/ConstraintCheck/Checker/DiffWithinRangeChecker.php @@ -62,6 +62,30 @@ } /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getSupportedContextTypes() { + return [ + Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + // TODO T175565 + Context::TYPE_QUALIFIER => CheckResult::STATUS_TODO, + Context::TYPE_REFERENCE => CheckResult::STATUS_TODO, + ]; + } + + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getDefaultContextTypes() { + return [ + Context::TYPE_STATEMENT, + // TODO T175565 + // Context::TYPE_QUALIFIER, + // Context::TYPE_REFERENCE, + ]; + } + + /** * @param Constraint $constraint * * @throws ConstraintParameterException diff --git a/src/ConstraintCheck/Checker/FormatChecker.php b/src/ConstraintCheck/Checker/FormatChecker.php index b3f845c..f495130 100644 --- a/src/ConstraintCheck/Checker/FormatChecker.php +++ b/src/ConstraintCheck/Checker/FormatChecker.php @@ -63,6 +63,28 @@ } /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getSupportedContextTypes() { + return [ + Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_QUALIFIER => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_REFERENCE => CheckResult::STATUS_COMPLIANCE, + ]; + } + + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getDefaultContextTypes() { + return [ + Context::TYPE_STATEMENT, + Context::TYPE_QUALIFIER, + Context::TYPE_REFERENCE, + ]; + } + + /** * Checks 'Format' constraint. * * @param Context $context diff --git a/src/ConstraintCheck/Checker/InverseChecker.php b/src/ConstraintCheck/Checker/InverseChecker.php index 42b9611..14193e8 100644 --- a/src/ConstraintCheck/Checker/InverseChecker.php +++ b/src/ConstraintCheck/Checker/InverseChecker.php @@ -63,6 +63,30 @@ } /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getSupportedContextTypes() { + return [ + Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + // TODO T175594 + Context::TYPE_QUALIFIER => CheckResult::STATUS_TODO, + Context::TYPE_REFERENCE => CheckResult::STATUS_TODO, + ]; + } + + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getDefaultContextTypes() { + return [ + Context::TYPE_STATEMENT, + // TODO T175594 + // Context::TYPE_QUALIFIER, + // Context::TYPE_REFERENCE, + ]; + } + + /** * Checks 'Inverse' constraint. * * @param Context $context diff --git a/src/ConstraintCheck/Checker/ItemChecker.php b/src/ConstraintCheck/Checker/ItemChecker.php index 135a8af..b81d99d 100644 --- a/src/ConstraintCheck/Checker/ItemChecker.php +++ b/src/ConstraintCheck/Checker/ItemChecker.php @@ -59,6 +59,30 @@ } /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getSupportedContextTypes() { + return [ + Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + // TODO T175562 + Context::TYPE_QUALIFIER => CheckResult::STATUS_TODO, + Context::TYPE_REFERENCE => CheckResult::STATUS_TODO, + ]; + } + + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getDefaultContextTypes() { + return [ + Context::TYPE_STATEMENT, + // TODO T175562 + // Context::TYPE_QUALIFIER, + // Context::TYPE_REFERENCE, + ]; + } + + /** * Checks 'Item' constraint. * * @param Context $context diff --git a/src/ConstraintCheck/Checker/MandatoryQualifiersChecker.php b/src/ConstraintCheck/Checker/MandatoryQualifiersChecker.php index 3a1843a..c4dc4e8 100644 --- a/src/ConstraintCheck/Checker/MandatoryQualifiersChecker.php +++ b/src/ConstraintCheck/Checker/MandatoryQualifiersChecker.php @@ -42,6 +42,26 @@ } /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getSupportedContextTypes() { + return [ + Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_QUALIFIER => CheckResult::STATUS_NOT_IN_SCOPE, + Context::TYPE_REFERENCE => CheckResult::STATUS_NOT_IN_SCOPE, + ]; + } + + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getDefaultContextTypes() { + return [ + Context::TYPE_STATEMENT, + ]; + } + + /** * Checks 'Mandatory qualifiers' constraint. * * @param Context $context diff --git a/src/ConstraintCheck/Checker/MultiValueChecker.php b/src/ConstraintCheck/Checker/MultiValueChecker.php index e21a53d..588de3f 100644 --- a/src/ConstraintCheck/Checker/MultiValueChecker.php +++ b/src/ConstraintCheck/Checker/MultiValueChecker.php @@ -25,6 +25,29 @@ } /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getSupportedContextTypes() { + return [ + Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + // TODO T175566 + Context::TYPE_QUALIFIER => CheckResult::STATUS_TODO, + Context::TYPE_REFERENCE => CheckResult::STATUS_TODO, + ]; + } + + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getDefaultContextTypes() { + return [ + Context::TYPE_STATEMENT, + Context::TYPE_QUALIFIER, + Context::TYPE_REFERENCE, + ]; + } + + /** * Checks 'Multi value' constraint. * * @param Context $context diff --git a/src/ConstraintCheck/Checker/OneOfChecker.php b/src/ConstraintCheck/Checker/OneOfChecker.php index d1215c2..95d03cb 100644 --- a/src/ConstraintCheck/Checker/OneOfChecker.php +++ b/src/ConstraintCheck/Checker/OneOfChecker.php @@ -41,6 +41,28 @@ } /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getSupportedContextTypes() { + return [ + Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_QUALIFIER => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_REFERENCE => CheckResult::STATUS_COMPLIANCE, + ]; + } + + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getDefaultContextTypes() { + return [ + Context::TYPE_STATEMENT, + Context::TYPE_QUALIFIER, + Context::TYPE_REFERENCE, + ]; + } + + /** * Checks 'One of' constraint. * * @param Context $context diff --git a/src/ConstraintCheck/Checker/QualifierChecker.php b/src/ConstraintCheck/Checker/QualifierChecker.php index 9095431..f00dae0 100644 --- a/src/ConstraintCheck/Checker/QualifierChecker.php +++ b/src/ConstraintCheck/Checker/QualifierChecker.php @@ -17,6 +17,28 @@ } /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getSupportedContextTypes() { + return [ + Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_QUALIFIER => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_REFERENCE => CheckResult::STATUS_COMPLIANCE, + ]; + } + + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getDefaultContextTypes() { + return [ + Context::TYPE_STATEMENT, + Context::TYPE_QUALIFIER, + Context::TYPE_REFERENCE, + ]; + } + + /** * Checks 'Qualifier' constraint. * * @param Context $context diff --git a/src/ConstraintCheck/Checker/QualifiersChecker.php b/src/ConstraintCheck/Checker/QualifiersChecker.php index ad2c279..41aea9b 100644 --- a/src/ConstraintCheck/Checker/QualifiersChecker.php +++ b/src/ConstraintCheck/Checker/QualifiersChecker.php @@ -42,6 +42,26 @@ } /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getSupportedContextTypes() { + return [ + Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_QUALIFIER => CheckResult::STATUS_NOT_IN_SCOPE, + Context::TYPE_REFERENCE => CheckResult::STATUS_NOT_IN_SCOPE, + ]; + } + + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getDefaultContextTypes() { + return [ + Context::TYPE_STATEMENT, + ]; + } + + /** * Checks 'Qualifiers' constraint. * * @param Context $context diff --git a/src/ConstraintCheck/Checker/RangeChecker.php b/src/ConstraintCheck/Checker/RangeChecker.php index bfb7b8e..bb6525c 100644 --- a/src/ConstraintCheck/Checker/RangeChecker.php +++ b/src/ConstraintCheck/Checker/RangeChecker.php @@ -60,6 +60,28 @@ } /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getSupportedContextTypes() { + return [ + Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_QUALIFIER => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_REFERENCE => CheckResult::STATUS_COMPLIANCE, + ]; + } + + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getDefaultContextTypes() { + return [ + Context::TYPE_STATEMENT, + Context::TYPE_QUALIFIER, + Context::TYPE_REFERENCE, + ]; + } + + /** * Checks 'Range' constraint. * * @param Context $context diff --git a/src/ConstraintCheck/Checker/ReferenceChecker.php b/src/ConstraintCheck/Checker/ReferenceChecker.php index 9f546a3..2601cb8 100644 --- a/src/ConstraintCheck/Checker/ReferenceChecker.php +++ b/src/ConstraintCheck/Checker/ReferenceChecker.php @@ -13,6 +13,28 @@ */ class ReferenceChecker implements ConstraintChecker { + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getSupportedContextTypes() { + return [ + Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_QUALIFIER => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_REFERENCE => CheckResult::STATUS_COMPLIANCE, + ]; + } + + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getDefaultContextTypes() { + return [ + Context::TYPE_STATEMENT, + Context::TYPE_QUALIFIER, + Context::TYPE_REFERENCE, + ]; + } + public function checkConstraint( Context $context, Constraint $constraint ) { if ( $context->getType() === Context::TYPE_REFERENCE ) { return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE, '' ); diff --git a/src/ConstraintCheck/Checker/SingleValueChecker.php b/src/ConstraintCheck/Checker/SingleValueChecker.php index 95ceaf1..fd6040e 100644 --- a/src/ConstraintCheck/Checker/SingleValueChecker.php +++ b/src/ConstraintCheck/Checker/SingleValueChecker.php @@ -25,6 +25,29 @@ } /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getSupportedContextTypes() { + return [ + Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + // TODO T175566 + Context::TYPE_QUALIFIER => CheckResult::STATUS_TODO, + Context::TYPE_REFERENCE => CheckResult::STATUS_TODO, + ]; + } + + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getDefaultContextTypes() { + return [ + Context::TYPE_STATEMENT, + Context::TYPE_QUALIFIER, + Context::TYPE_REFERENCE, + ]; + } + + /** * Checks 'Single value' constraint. * * @param Context $context diff --git a/src/ConstraintCheck/Checker/SymmetricChecker.php b/src/ConstraintCheck/Checker/SymmetricChecker.php index e806e2f..4690138 100644 --- a/src/ConstraintCheck/Checker/SymmetricChecker.php +++ b/src/ConstraintCheck/Checker/SymmetricChecker.php @@ -53,6 +53,30 @@ } /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getSupportedContextTypes() { + return [ + Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + // TODO T175594 + Context::TYPE_QUALIFIER => CheckResult::STATUS_TODO, + Context::TYPE_REFERENCE => CheckResult::STATUS_TODO, + ]; + } + + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getDefaultContextTypes() { + return [ + Context::TYPE_STATEMENT, + // TODO T175594 + // Context::TYPE_QUALIFIER, + // Context::TYPE_REFERENCE, + ]; + } + + /** * Checks 'Symmetric' constraint. * * @param Context $context diff --git a/src/ConstraintCheck/Checker/TargetRequiredClaimChecker.php b/src/ConstraintCheck/Checker/TargetRequiredClaimChecker.php index acb2ef6..2cc2548 100644 --- a/src/ConstraintCheck/Checker/TargetRequiredClaimChecker.php +++ b/src/ConstraintCheck/Checker/TargetRequiredClaimChecker.php @@ -63,6 +63,28 @@ } /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getSupportedContextTypes() { + return [ + Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_QUALIFIER => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_REFERENCE => CheckResult::STATUS_COMPLIANCE, + ]; + } + + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getDefaultContextTypes() { + return [ + Context::TYPE_STATEMENT, + Context::TYPE_QUALIFIER, + Context::TYPE_REFERENCE, + ]; + } + + /** * Checks 'Target required claim' constraint. * * @param Context $context diff --git a/src/ConstraintCheck/Checker/TypeChecker.php b/src/ConstraintCheck/Checker/TypeChecker.php index ea1e4c2..17c2562 100644 --- a/src/ConstraintCheck/Checker/TypeChecker.php +++ b/src/ConstraintCheck/Checker/TypeChecker.php @@ -60,6 +60,26 @@ } /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getSupportedContextTypes() { + return [ + Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_QUALIFIER => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_REFERENCE => CheckResult::STATUS_COMPLIANCE, + ]; + } + + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getDefaultContextTypes() { + return [ + Context::TYPE_STATEMENT, + ]; + } + + /** * Checks 'Type' constraint. * * @param Context $context diff --git a/src/ConstraintCheck/Checker/UniqueValueChecker.php b/src/ConstraintCheck/Checker/UniqueValueChecker.php index d921196..6a2708c 100644 --- a/src/ConstraintCheck/Checker/UniqueValueChecker.php +++ b/src/ConstraintCheck/Checker/UniqueValueChecker.php @@ -42,6 +42,28 @@ } /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getSupportedContextTypes() { + return [ + Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_QUALIFIER => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_REFERENCE => CheckResult::STATUS_COMPLIANCE, + ]; + } + + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getDefaultContextTypes() { + return [ + Context::TYPE_STATEMENT, + Context::TYPE_QUALIFIER, + Context::TYPE_REFERENCE, + ]; + } + + /** * Checks 'Unique value' constraint. * * @param Context $context diff --git a/src/ConstraintCheck/Checker/ValueOnlyChecker.php b/src/ConstraintCheck/Checker/ValueOnlyChecker.php index 6fb601b..4640d0c 100644 --- a/src/ConstraintCheck/Checker/ValueOnlyChecker.php +++ b/src/ConstraintCheck/Checker/ValueOnlyChecker.php @@ -13,6 +13,28 @@ */ class ValueOnlyChecker implements ConstraintChecker { + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getSupportedContextTypes() { + return [ + Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_QUALIFIER => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_REFERENCE => CheckResult::STATUS_COMPLIANCE, + ]; + } + + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getDefaultContextTypes() { + return [ + Context::TYPE_STATEMENT, + Context::TYPE_QUALIFIER, + Context::TYPE_REFERENCE, + ]; + } + public function checkConstraint( Context $context, Constraint $constraint ) { if ( $context->getType() === Context::TYPE_STATEMENT ) { return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE, '' ); diff --git a/src/ConstraintCheck/Checker/ValueTypeChecker.php b/src/ConstraintCheck/Checker/ValueTypeChecker.php index f2f1806..677b4da 100644 --- a/src/ConstraintCheck/Checker/ValueTypeChecker.php +++ b/src/ConstraintCheck/Checker/ValueTypeChecker.php @@ -73,6 +73,28 @@ } /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getSupportedContextTypes() { + return [ + Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_QUALIFIER => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_REFERENCE => CheckResult::STATUS_COMPLIANCE, + ]; + } + + /** + * @codeCoverageIgnore This method is purely declarative. + */ + public function getDefaultContextTypes() { + return [ + Context::TYPE_STATEMENT, + Context::TYPE_QUALIFIER, + Context::TYPE_REFERENCE, + ]; + } + + /** * Checks 'Value type' constraint. * * @param Context $context diff --git a/src/ConstraintCheck/ConstraintChecker.php b/src/ConstraintCheck/ConstraintChecker.php index bcbe747..11d7395 100644 --- a/src/ConstraintCheck/ConstraintChecker.php +++ b/src/ConstraintCheck/ConstraintChecker.php @@ -17,6 +17,50 @@ interface ConstraintChecker { /** + * Determines which context types this constraint type supports. + * checkConstraint() should only be called for contexts with one of the supported types. + * + * Returns an array from context types + * (i. e., Context::TYPE_* constants) + * to result status (i. e., CheckResult::STATUS_* constants). + * STATUS_COMPLIANCE means that the constraint type supports this context type + * (checkConstraint() might of course return a different status, e. g. VIOLATION); + * STATUS_TODO means that the constraint type might support this context type in the future, + * but it is not currently supported; + * and STATUS_NOT_IN_SCOPE means that the constraint type does not support this context type. + * + * For example, the array + * + * [ + * Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + * Context::TYPE_QUALIFIER => CheckResult::STATUS_TODO, + * Context::TYPE_REFERENCE => CheckResult::STATUS_NOT_IN_SCOPE, + * ] + * + * indicates that a constraint type makes sense on statements and qualifiers + * (but not references), but has only been implemented on statements so far. + * + * @return string[] + */ + public function getSupportedContextTypes(); + + /** + * Determines the context types where this constraint type is checked + * if the constraint scope has not been explicitly specified as a constraint parameter. + * Returns an array of context types (i. e., Context::TYPE_* constants). + * + * For example, the array [ Context::TYPE_STATEMENT ] indicates that, + * by default, a constraint should only be checked on the main snak of a statement. + * Depending on the {@link getSupportedContextTypes supported context types}, + * it might also be checked on other context types + * if the constraint explicitly specifies a different scope + * (which might not even include the “statement” scope). + * + * @return string[] + */ + public function getDefaultContextTypes(); + + /** * @param Context $context * @param Constraint $constraint * diff --git a/tests/phpunit/Fake/FakeChecker.php b/tests/phpunit/Fake/FakeChecker.php index b097652..0b2193f 100644 --- a/tests/phpunit/Fake/FakeChecker.php +++ b/tests/phpunit/Fake/FakeChecker.php @@ -26,6 +26,22 @@ $this->status = $status; } + public function getSupportedContextTypes() { + return [ + Context::TYPE_STATEMENT => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_QUALIFIER => CheckResult::STATUS_COMPLIANCE, + Context::TYPE_REFERENCE => CheckResult::STATUS_COMPLIANCE, + ]; + } + + public function getDefaultContextTypes() { + return [ + Context::TYPE_STATEMENT, + Context::TYPE_QUALIFIER, + Context::TYPE_REFERENCE, + ]; + } + /** * @see ConstraintChecker::checkConstraint */ -- To view, visit https://gerrit.wikimedia.org/r/402882 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I6720b4a984a6ba2daa7425a6de21a30e09af22db Gerrit-PatchSet: 6 Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints Gerrit-Branch: master Gerrit-Owner: Lucas Werkmeister (WMDE) <lucas.werkmeis...@wikimedia.de> Gerrit-Reviewer: Jonas Kress (WMDE) <jonas.kr...@wikimedia.de> Gerrit-Reviewer: Lucas Werkmeister (WMDE) <lucas.werkmeis...@wikimedia.de> Gerrit-Reviewer: WMDE-leszek <leszek.mani...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits