Thiemo Mättig (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/218348

Change subject: Rename some $claimGuid to $guid
......................................................................

Rename some $claimGuid to $guid

This is pure refactoring split from I54f5c79. I'm trying to make some
code independent from the terms "Claim" vs. "Statement" where possible.
I know that a gazzillion more lines of code need update. Please do not
downvote this patch based on lines I do *not* touch.

Change-Id: I3a10d39eeb180a2d08c2e61737c41a5108d18e9b
---
M repo/includes/api/CreateClaim.php
M repo/includes/api/GetClaims.php
M repo/includes/api/ModifyClaim.php
M repo/includes/api/RemoveClaims.php
M repo/includes/api/RemoveQualifiers.php
M repo/includes/api/RemoveReferences.php
M repo/includes/api/SetClaim.php
M repo/includes/api/SetClaimValue.php
M repo/includes/api/SetQualifier.php
M repo/includes/api/SetReference.php
10 files changed, 52 insertions(+), 58 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/48/218348/1

diff --git a/repo/includes/api/CreateClaim.php 
b/repo/includes/api/CreateClaim.php
index 7245686..9c2f8b2 100644
--- a/repo/includes/api/CreateClaim.php
+++ b/repo/includes/api/CreateClaim.php
@@ -85,11 +85,10 @@
         * @params array $params
         */
        private function validateParameters( array $params ) {
-               if ( $params['snaktype'] == 'value' XOR isset( $params['value'] 
) ) {
-                       if ( $params['snaktype'] == 'value' ) {
+               if ( $params['snaktype'] === 'value' XOR isset( 
$params['value'] ) ) {
+                       if ( $params['snaktype'] === 'value' ) {
                                $this->dieError( 'A value needs to be provided 
when creating a claim with PropertyValueSnak snak', 'param-missing' );
-                       }
-                       else {
+                       } else {
                                $this->dieError( 'You cannot provide a value 
when creating a claim with no PropertyValueSnak as main snak', 'param-illegal' 
);
                        }
                }
diff --git a/repo/includes/api/GetClaims.php b/repo/includes/api/GetClaims.php
index ec9a9f7..bf4005b 100644
--- a/repo/includes/api/GetClaims.php
+++ b/repo/includes/api/GetClaims.php
@@ -30,12 +30,12 @@
        /**
         * @var ClaimGuidValidator
         */
-       private $claimGuidValidator;
+       private $guidValidator;
 
        /**
         * @var ClaimGuidParser
         */
-       private $claimGuidParser;
+       private $guidParser;
 
        /**
         * @param ApiMain $mainModule
@@ -48,8 +48,8 @@
                parent::__construct( $mainModule, $moduleName, $modulePrefix );
 
                //TODO: provide a mechanism to override the services
-               $this->claimGuidValidator = 
WikibaseRepo::getDefaultInstance()->getClaimGuidValidator();
-               $this->claimGuidParser = 
WikibaseRepo::getDefaultInstance()->getClaimGuidParser();
+               $this->guidValidator = 
WikibaseRepo::getDefaultInstance()->getClaimGuidValidator();
+               $this->guidParser = 
WikibaseRepo::getDefaultInstance()->getClaimGuidParser();
        }
 
        /**
@@ -61,10 +61,10 @@
                $params = $this->extractRequestParams();
                $this->validateParameters( $params );
 
-               list( $id, $claimGuid ) = $this->getIdentifiers( $params );
+               list( $idString, $guid ) = $this->getIdentifiers( $params );
 
                try {
-                       $entityId = $this->getIdParser()->parse( $id );
+                       $entityId = $this->getIdParser()->parse( $idString );
                } catch ( EntityIdParsingException $e ) {
                        $this->dieException( $e, 'param-invalid' );
                }
@@ -80,7 +80,7 @@
                                );
                }
 
-               $claims = $this->getClaims( $entity, $claimGuid );
+               $claims = $this->getClaims( $entity, $guid );
                $this->getResultBuilder()->addClaims( $claims, null );
        }
 
@@ -157,34 +157,35 @@
         * Obtains the id of the entity for which to obtain claims and the 
claim GUID
         * in case it was also provided.
         *
-        * @param $params
+        * @param array $params
         *
         * @return array
-        * First element is a prefixed entity id
-        * Second element is either null or a claim GUID
+        * First element is a prefixed entity id string.
+        * Second element is either null or a statements GUID.
         */
-       private function getIdentifiers( $params ) {
-               if ( isset( $params['claim'] ) ) {
-                       $claimGuid = $params['claim'];
-                       $entityId = $this->getEntityIdFromClaimGuid( 
$params['claim'] );
+       private function getIdentifiers( array $params ) {
+               $guid = null;
 
-                       if( isset( $params['entity'] ) && $entityId !== 
$params['entity'] ) {
+               if ( isset( $params['claim'] ) ) {
+                       $guid = $params['claim'];
+                       $idString = $this->getEntityIdFromStatementGuid( 
$params['claim'] );
+
+                       if ( isset( $params['entity'] ) && $idString !== 
$params['entity'] ) {
                                $this->dieError( 'If both entity id and claim 
key are provided they need to point to the same entity', 'param-illegal' );
                        }
                } else {
-                       $claimGuid = null;
-                       $entityId = $params['entity'];
+                       $idString = $params['entity'];
                }
 
-               return array( $entityId, $claimGuid );
+               return array( $idString, $guid );
        }
 
-       private function getEntityIdFromClaimGuid( $claimGuid ) {
-               if ( $this->claimGuidValidator->validateFormat( $claimGuid ) 
=== false ) {
-                       $this->dieError( 'Invalid claim guid' , 'invalid-guid' 
);
+       private function getEntityIdFromStatementGuid( $claimGuid ) {
+               if ( $this->guidValidator->validateFormat( $claimGuid ) === 
false ) {
+                       $this->dieError( 'Invalid claim guid', 'invalid-guid' );
                }
 
-               return $this->claimGuidParser->parse( $claimGuid 
)->getEntityId()->getSerialization();
+               return $this->guidParser->parse( $claimGuid 
)->getEntityId()->getSerialization();
        }
 
        /**
diff --git a/repo/includes/api/ModifyClaim.php 
b/repo/includes/api/ModifyClaim.php
index dd3ac27..da2acb2 100644
--- a/repo/includes/api/ModifyClaim.php
+++ b/repo/includes/api/ModifyClaim.php
@@ -32,7 +32,7 @@
         *
         * @var ClaimGuidParser
         */
-       protected $claimGuidParser;
+       protected $guidParser;
 
        /**
         * @param ApiMain $mainModule
@@ -51,7 +51,7 @@
                        $this->getErrorReporter()
                );
 
-               $this->claimGuidParser = 
WikibaseRepo::getDefaultInstance()->getClaimGuidParser();
+               $this->guidParser = 
WikibaseRepo::getDefaultInstance()->getClaimGuidParser();
        }
 
        /**
diff --git a/repo/includes/api/RemoveClaims.php 
b/repo/includes/api/RemoveClaims.php
index 92f2248..5724d9a 100644
--- a/repo/includes/api/RemoveClaims.php
+++ b/repo/includes/api/RemoveClaims.php
@@ -89,9 +89,9 @@
                        }
 
                        if ( is_null( $entityId ) ) {
-                               $entityId = $this->claimGuidParser->parse( 
$guid )->getEntityId();
+                               $entityId = $this->guidParser->parse( $guid 
)->getEntityId();
                        } else {
-                               if ( !$this->claimGuidParser->parse( $guid 
)->getEntityId()->equals( $entityId ) ) {
+                               if ( !$this->guidParser->parse( $guid 
)->getEntityId()->equals( $entityId ) ) {
                                        $this->dieError( 'All claims must 
belong to the same entity' , 'invalid-guid' );
                                }
                        }
diff --git a/repo/includes/api/RemoveQualifiers.php 
b/repo/includes/api/RemoveQualifiers.php
index 169b8a5..04b18cd 100644
--- a/repo/includes/api/RemoveQualifiers.php
+++ b/repo/includes/api/RemoveQualifiers.php
@@ -48,19 +48,19 @@
                $params = $this->extractRequestParams();
                $this->validateParameters( $params );
 
-               $claimGuid = $params['claim'];
-               $entityId = $this->claimGuidParser->parse( $claimGuid 
)->getEntityId();
+               $guid = $params['claim'];
+               $entityId = $this->guidParser->parse( $guid )->getEntityId();
                $baseRevisionId = isset( $params['baserevid'] ) ? 
(int)$params['baserevid'] : null;
                $entityRevision = $this->loadEntityRevision( $entityId, 
$baseRevisionId );
                $entity = $entityRevision->getEntity();
                $summary = $this->modificationHelper->createSummary( $params, 
$this );
 
-               $claim = $this->modificationHelper->getStatementFromEntity( 
$claimGuid, $entity );
+               $claim = $this->modificationHelper->getStatementFromEntity( 
$guid, $entity );
 
                $qualifierHashes = $this->getQualifierHashesFromParams( 
$params, $claim );
 
                $changeOps = new ChangeOps();
-               $changeOps->add( $this->getChangeOps( $claimGuid, 
$qualifierHashes ) );
+               $changeOps->add( $this->getChangeOps( $guid, $qualifierHashes ) 
);
 
                try {
                        $changeOps->apply( $entity, $summary );
diff --git a/repo/includes/api/RemoveReferences.php 
b/repo/includes/api/RemoveReferences.php
index fbe293b..6ca2a85 100644
--- a/repo/includes/api/RemoveReferences.php
+++ b/repo/includes/api/RemoveReferences.php
@@ -49,7 +49,7 @@
                $this->validateParameters( $params );
 
                $guid = $params['statement'];
-               $entityId = $this->claimGuidParser->parse( $guid 
)->getEntityId();
+               $entityId = $this->guidParser->parse( $guid )->getEntityId();
                $baseRevisionId = isset( $params['baserevid'] ) ? 
(int)$params['baserevid'] : null;
                $entityRevision = $this->loadEntityRevision( $entityId, 
$baseRevisionId );
                $entity = $entityRevision->getEntity();
diff --git a/repo/includes/api/SetClaim.php b/repo/includes/api/SetClaim.php
index cadb14d..93062e3 100644
--- a/repo/includes/api/SetClaim.php
+++ b/repo/includes/api/SetClaim.php
@@ -65,7 +65,7 @@
                }
 
                try {
-                       $claimGuid = $this->claimGuidParser->parse( $guid );
+                       $claimGuid = $this->guidParser->parse( $guid );
                } catch ( ClaimGuidParsingException $ex ) {
                        $this->dieException( $ex, 'invalid-claim' );
                }
diff --git a/repo/includes/api/SetClaimValue.php 
b/repo/includes/api/SetClaimValue.php
index 90e7030..baed397 100644
--- a/repo/includes/api/SetClaimValue.php
+++ b/repo/includes/api/SetClaimValue.php
@@ -44,22 +44,19 @@
                $params = $this->extractRequestParams();
                $this->validateParameters( $params );
 
-               $claimGuid = $params['claim'];
-               $entityId = $this->claimGuidParser->parse( $claimGuid 
)->getEntityId();
+               $guid = $params['claim'];
+               $entityId = $this->guidParser->parse( $guid )->getEntityId();
                $baseRevisionId = isset( $params['baserevid'] ) ? 
(int)$params['baserevid'] : null;
                $entityRevision = $this->loadEntityRevision( $entityId, 
$baseRevisionId );
                $entity = $entityRevision->getEntity();
 
-               $claim = $this->modificationHelper->getStatementFromEntity( 
$claimGuid, $entity );
+               $claim = $this->modificationHelper->getStatementFromEntity( 
$guid, $entity );
 
                $snak = $this->modificationHelper->getSnakInstance( $params, 
$claim->getMainSnak()->getPropertyId() );
 
                $summary = $this->modificationHelper->createSummary( $params, 
$this );
 
-               $changeOp = $this->claimChangeOpFactory->newSetMainSnakOp(
-                       $claimGuid,
-                       $snak
-               );
+               $changeOp = $this->claimChangeOpFactory->newSetMainSnakOp( 
$guid, $snak );
 
                $this->modificationHelper->applyChangeOp( $changeOp, $entity, 
$summary );
 
diff --git a/repo/includes/api/SetQualifier.php 
b/repo/includes/api/SetQualifier.php
index ec14b00..abe4d08 100644
--- a/repo/includes/api/SetQualifier.php
+++ b/repo/includes/api/SetQualifier.php
@@ -6,8 +6,8 @@
 use ApiMain;
 use Wikibase\ChangeOp\ChangeOpQualifier;
 use Wikibase\ChangeOp\ClaimChangeOpFactory;
-use Wikibase\DataModel\Claim\Claim;
 use Wikibase\DataModel\Entity\PropertyId;
+use Wikibase\DataModel\Statement\Statement;
 use Wikibase\Repo\WikibaseRepo;
 
 /**
@@ -48,17 +48,17 @@
                $params = $this->extractRequestParams();
                $this->validateParameters( $params );
 
-               $entityId = $this->claimGuidParser->parse( $params['claim'] 
)->getEntityId();
+               $entityId = $this->guidParser->parse( $params['claim'] 
)->getEntityId();
                $baseRevisionId = isset( $params['baserevid'] ) ? 
(int)$params['baserevid'] : null;
                $entityRevision = $this->loadEntityRevision( $entityId, 
$baseRevisionId );
                $entity = $entityRevision->getEntity();
 
                $summary = $this->modificationHelper->createSummary( $params, 
$this );
 
-               $claim = $this->modificationHelper->getStatementFromEntity( 
$params['claim'], $entity );
+               $statement = $this->modificationHelper->getStatementFromEntity( 
$params['claim'], $entity );
 
                if ( isset( $params['snakhash'] ) ) {
-                       $this->validateQualifierHash( $claim, 
$params['snakhash'] );
+                       $this->validateQualifierHash( $statement, 
$params['snakhash'] );
                }
 
                $changeOp = $this->getChangeOp();
@@ -66,7 +66,7 @@
 
                $this->saveChanges( $entity, $summary );
                $this->getResultBuilder()->markSuccess();
-               $this->getResultBuilder()->addClaim( $claim );
+               $this->getResultBuilder()->addClaim( $statement );
        }
 
        /**
@@ -94,11 +94,11 @@
        }
 
        /**
-        * @param Claim $claim
+        * @param Statement $statement
         * @param string $qualifierHash
         */
-       private function validateQualifierHash( Claim $claim, $qualifierHash ) {
-               if ( !$claim->getQualifiers()->hasSnakHash( $qualifierHash ) ) {
+       private function validateQualifierHash( Statement $statement, 
$qualifierHash ) {
+               if ( !$statement->getQualifiers()->hasSnakHash( $qualifierHash 
) ) {
                        $this->dieError( "Claim does not have a qualifier with 
the given hash" , 'no-such-qualifier' );
                }
        }
@@ -109,7 +109,7 @@
        private function getChangeOp() {
                $params = $this->extractRequestParams();
 
-               $claimGuid = $params['claim'];
+               $guid = $params['claim'];
 
                $propertyId = $this->modificationHelper->getEntityIdFromString( 
$params['property'] );
                if ( !$propertyId instanceof PropertyId ) {
@@ -120,11 +120,8 @@
                }
                $newQualifier = $this->modificationHelper->getSnakInstance( 
$params, $propertyId );
 
-               if ( isset( $params['snakhash'] ) ) {
-                       $changeOp = 
$this->claimChangeOpFactory->newSetQualifierOp( $claimGuid, $newQualifier, 
$params['snakhash'] );
-               } else {
-                       $changeOp = 
$this->claimChangeOpFactory->newSetQualifierOp( $claimGuid, $newQualifier, '' );
-               }
+               $snakHash = isset( $params['snakhash'] ) ? $params['snakhash'] 
: '';
+               $changeOp = $this->claimChangeOpFactory->newSetQualifierOp( 
$guid, $newQualifier, $snakHash );
 
                return $changeOp;
        }
diff --git a/repo/includes/api/SetReference.php 
b/repo/includes/api/SetReference.php
index df1c135..e93501c 100644
--- a/repo/includes/api/SetReference.php
+++ b/repo/includes/api/SetReference.php
@@ -51,7 +51,7 @@
                $params = $this->extractRequestParams();
                $this->validateParameters( $params );
 
-               $entityId = $this->claimGuidParser->parse( $params['statement'] 
)->getEntityId();
+               $entityId = $this->guidParser->parse( $params['statement'] 
)->getEntityId();
                $baseRevisionId = isset( $params['baserevid'] ) ? 
(int)$params['baserevid'] : null;
                $entityRevision = $this->loadEntityRevision( $entityId, 
$baseRevisionId );
                $entity = $entityRevision->getEntity();

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3a10d39eeb180a2d08c2e61737c41a5108d18e9b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>

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

Reply via email to