Lucas Werkmeister (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/373259 )

Change subject: Use class constants for context types
......................................................................

Use class constants for context types

This protects against accidental typos of the type.

(FakeSnakContext returns a different type than the documented ones, but
I think for a test class that’s acceptable.)

Change-Id: Ib888e508847b572a03397e7c6969ff2a94c34094
---
M api/CheckConstraints.php
M includes/ConstraintCheck/Checker/MandatoryQualifiersChecker.php
M includes/ConstraintCheck/Checker/QualifiersChecker.php
M includes/ConstraintCheck/Checker/UniqueValueChecker.php
M includes/ConstraintCheck/Context/Context.php
M includes/ConstraintCheck/Context/StatementContext.php
M includes/ConstraintCheck/Helper/LoggingHelper.php
M tests/phpunit/Context/StatementContextTest.php
8 files changed, 33 insertions(+), 11 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQualityConstraints
 refs/changes/59/373259/1

diff --git a/api/CheckConstraints.php b/api/CheckConstraints.php
index 914cde9..547bdc9 100644
--- a/api/CheckConstraints.php
+++ b/api/CheckConstraints.php
@@ -24,6 +24,7 @@
 use Wikibase\Repo\Api\ResultBuilder;
 use Wikibase\Repo\EntityIdLabelFormatterFactory;
 use Wikibase\Repo\WikibaseRepo;
+use WikibaseQuality\ConstraintReport\ConstraintCheck\Context\Context;
 use 
WikibaseQuality\ConstraintReport\ConstraintCheck\DelegatingConstraintChecker;
 use 
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConstraintParameterParser;
 use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResult;
@@ -358,7 +359,7 @@
                        if ( $checkResult->getMessage() ) {
                                $result['message-html'] = 
$checkResult->getMessage();
                        }
-                       if ( $checkResult->getContext()->getType() === 
'statement' ) {
+                       if ( $checkResult->getContext()->getType() === 
Context::TYPE_STATEMENT ) {
                                $result['claim'] = 
$checkResult->getContext()->getSnakStatement()->getGuid();
                        }
 
diff --git a/includes/ConstraintCheck/Checker/MandatoryQualifiersChecker.php 
b/includes/ConstraintCheck/Checker/MandatoryQualifiersChecker.php
index 0d44f5c..f08b6b6 100644
--- a/includes/ConstraintCheck/Checker/MandatoryQualifiersChecker.php
+++ b/includes/ConstraintCheck/Checker/MandatoryQualifiersChecker.php
@@ -56,7 +56,7 @@
                if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
                        return new CheckResult( $context, $constraint, [], 
CheckResult::STATUS_DEPRECATED );
                }
-               if ( $context->getType() !== 'statement' ) {
+               if ( $context->getType() !== Context::TYPE_STATEMENT ) {
                        return new CheckResult( $context, $constraint, [], 
CheckResult::STATUS_TODO );
                }
 
diff --git a/includes/ConstraintCheck/Checker/QualifiersChecker.php 
b/includes/ConstraintCheck/Checker/QualifiersChecker.php
index a30eb31..df6b6a9 100644
--- a/includes/ConstraintCheck/Checker/QualifiersChecker.php
+++ b/includes/ConstraintCheck/Checker/QualifiersChecker.php
@@ -56,7 +56,7 @@
                if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
                        return new CheckResult( $context, $constraint, [], 
CheckResult::STATUS_DEPRECATED );
                }
-               if ( $context->getType() !== 'statement' ) {
+               if ( $context->getType() !== Context::TYPE_STATEMENT ) {
                        return new CheckResult( $context, $constraint, [], 
CheckResult::STATUS_TODO );
                }
 
diff --git a/includes/ConstraintCheck/Checker/UniqueValueChecker.php 
b/includes/ConstraintCheck/Checker/UniqueValueChecker.php
index 6dc0f39..f552d8a 100644
--- a/includes/ConstraintCheck/Checker/UniqueValueChecker.php
+++ b/includes/ConstraintCheck/Checker/UniqueValueChecker.php
@@ -57,7 +57,7 @@
                if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) {
                        return new CheckResult( $context, $constraint, [], 
CheckResult::STATUS_DEPRECATED );
                }
-               if ( $context->getType() !== 'statement' ) {
+               if ( $context->getType() !== Context::TYPE_STATEMENT ) {
                        return new CheckResult( $context, $constraint, [], 
CheckResult::STATUS_TODO );
                }
 
diff --git a/includes/ConstraintCheck/Context/Context.php 
b/includes/ConstraintCheck/Context/Context.php
index e38bb82..4f0552f 100644
--- a/includes/ConstraintCheck/Context/Context.php
+++ b/includes/ConstraintCheck/Context/Context.php
@@ -12,6 +12,25 @@
 interface Context {
 
        /**
+        * Type of a context for the main snak of a statement.
+        * @see getType()
+        * @var string
+        */
+       const TYPE_STATEMENT = 'statement';
+       /**
+        * Type of a context for a qualifier of a statement.
+        * @see getType()
+        * @var string
+        */
+       const TYPE_QUALIFIER = 'qualifier';
+       /**
+        * Type of a context for a snak of a reference of a statement.
+        * @see getType()
+        * @var string
+        */
+       const TYPE_REFERENCE = 'reference';
+
+       /**
         * The snak that is being checked.
         *
         * @return Snak
@@ -29,7 +48,8 @@
         * The type / role of the snak that is being checked within this 
context.
         * Not to be confused with the snak’s own type 
(value/somevalue/novalue).
         *
-        * @return string 'statement', 'qualifier', 'reference', or something 
else
+        * @return string one of {@link self::TYPE_STATEMENT},
+        * {@link self::TYPE_QUALIFIER} or {@link self::TYPE_REFERENCE}.
         */
        public function getType();
 
@@ -38,16 +58,16 @@
         * Only the main snak of a statement has a rank.
         *
         * @return integer|null One of the Statement::RANK_* constants
-        * if this is a 'statement' context,
+        * if this is a statement context,
         * or null if it’s any other type of context.
         */
        public function getSnakRank();
 
        /**
         * The statement that this snak is the main snak of.
-        * Only the snak of a 'statement' context has a statement.
+        * Only the snak of a statement context has a statement.
         *
-        * @return Statement|null The statement if this is a 'statement' 
context,
+        * @return Statement|null The statement if this is a statement context,
         * or null if it’s any other type of context.
         */
        public function getSnakStatement();
diff --git a/includes/ConstraintCheck/Context/StatementContext.php 
b/includes/ConstraintCheck/Context/StatementContext.php
index b18b750..04d2483 100644
--- a/includes/ConstraintCheck/Context/StatementContext.php
+++ b/includes/ConstraintCheck/Context/StatementContext.php
@@ -32,7 +32,7 @@
        }
 
        public function getType() {
-               return 'statement';
+               return self::TYPE_STATEMENT;
        }
 
        public function getSnakRank() {
diff --git a/includes/ConstraintCheck/Helper/LoggingHelper.php 
b/includes/ConstraintCheck/Helper/LoggingHelper.php
index 47416d5..5d3ff49 100644
--- a/includes/ConstraintCheck/Helper/LoggingHelper.php
+++ b/includes/ConstraintCheck/Helper/LoggingHelper.php
@@ -101,7 +101,7 @@
                if ( !isset( $limitSeconds ) ) {
                        return;
                }
-               if ( $context->getType() !== 'statement' ) {
+               if ( $context->getType() !== Context::TYPE_STATEMENT ) {
                        // TODO log less details but still log something
                        return;
                }
diff --git a/tests/phpunit/Context/StatementContextTest.php 
b/tests/phpunit/Context/StatementContextTest.php
index e82075f..a55eb1d 100644
--- a/tests/phpunit/Context/StatementContextTest.php
+++ b/tests/phpunit/Context/StatementContextTest.php
@@ -5,6 +5,7 @@
 use Wikibase\DataModel\Statement\Statement;
 use Wikibase\Repo\Tests\NewItem;
 use Wikibase\Repo\Tests\NewStatement;
+use WikibaseQuality\ConstraintReport\ConstraintCheck\Context\Context;
 use WikibaseQuality\ConstraintReport\ConstraintCheck\Context\StatementContext;
 
 /**
@@ -42,7 +43,7 @@
                $statement = NewStatement::noValueFor( 'P1' )->build();
                $context = new StatementContext( $entity, $statement );
 
-               $this->assertSame( 'statement', $context->getType() );
+               $this->assertSame( Context::TYPE_STATEMENT, $context->getType() 
);
        }
 
        public function testGetSnakRank() {

-- 
To view, visit https://gerrit.wikimedia.org/r/373259
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib888e508847b572a03397e7c6969ff2a94c34094
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to