Thiemo Mättig (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/370915 )

Change subject: Remove unused code snippets from EntityChangeFactory and related
......................................................................

Remove unused code snippets from EntityChangeFactory and related

This tackles post-merge comments from Iaa98722.

Bug: T172394
Change-Id: If47e719af40088b25e81c29059530146707d7de3
---
M client/includes/Changes/InjectRCRecordsJob.php
M lib/includes/Changes/EntityChangeFactory.php
2 files changed, 21 insertions(+), 20 deletions(-)


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

diff --git a/client/includes/Changes/InjectRCRecordsJob.php 
b/client/includes/Changes/InjectRCRecordsJob.php
index 6a50900..8371e89 100644
--- a/client/includes/Changes/InjectRCRecordsJob.php
+++ b/client/includes/Changes/InjectRCRecordsJob.php
@@ -2,17 +2,16 @@
 
 namespace Wikibase\Client\Changes;
 
+use InvalidArgumentException;
 use Job;
 use JobSpecification;
 use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
 use Psr\Log\LoggerInterface;
 use Psr\Log\NullLogger;
 use Title;
-use Wikibase\Client\Changes\ChangeHandler;
 use Wikibase\Client\RecentChanges\RecentChangeFactory;
 use Wikibase\Client\RecentChanges\RecentChangesDuplicateDetector;
 use Wikibase\Client\Store\TitleFactory;
-use Wikibase\Client\WikibaseClient;
 use Wikibase\EntityChange;
 use Wikibase\Lib\Changes\EntityChangeFactory;
 use Wikibase\Lib\Store\Sql\EntityChangeLookup;
@@ -114,6 +113,8 @@
         * @param RecentChangeFactory $rcFactory
         * @param array $params Needs to have two keys: "change": the id of the 
change,
         *     "pages": array of pages, represented as $pageId => [ $namespace, 
$dbKey ].
+        *
+        * @throws InvalidArgumentException
         */
        public function __construct(
                LBFactory $lbFactory,
@@ -125,11 +126,6 @@
                $title = Title::makeTitle( NS_SPECIAL, 'Badtitle/' . __CLASS__ 
);
                parent::__construct( 'wikibase-InjectRCRecords', $title, 
$params );
 
-               Assert::parameter(
-                       isset( $params['change'] ),
-                       '$params',
-                       '$params[\'change\'] not set.'
-               );
                // TODO: disallow integer once T172394 has been deployed and 
old jobs have cleared the queue.
                Assert::parameterType(
                        'integer|array',
@@ -137,11 +133,6 @@
                        '$params[\'change\']'
                );
 
-               Assert::parameter(
-                       isset( $params['pages'] ),
-                       '$params',
-                       '$params[\'pages\'] not set.'
-               );
                Assert::parameterElementType(
                        'array',
                        $params['pages'],
@@ -187,6 +178,8 @@
 
        /**
         * @param int $dbBatchSize
+        *
+        * @throws InvalidArgumentException
         */
        public function setDbBatchSize( $dbBatchSize ) {
                Assert::parameterType( 'integer', $dbBatchSize, '$dbBatchSize' 
);
@@ -244,7 +237,7 @@
                $titles = [];
 
                foreach ( $pages as $pageId => list( $namespace, $dbKey ) ) {
-                       $titles[$pageId] = $this->titleFactory->makeTitle( 
$namespace, $dbKey );
+                       $titles[] = $this->titleFactory->makeTitle( $namespace, 
$dbKey );
                }
 
                return $titles;
diff --git a/lib/includes/Changes/EntityChangeFactory.php 
b/lib/includes/Changes/EntityChangeFactory.php
index 8fb9411..e3e85a4 100644
--- a/lib/includes/Changes/EntityChangeFactory.php
+++ b/lib/includes/Changes/EntityChangeFactory.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Lib\Changes;
 
+use InvalidArgumentException;
 use MWException;
 use Wikibase\DataModel\Entity\EntityDocument;
 use Wikibase\DataModel\Entity\EntityId;
@@ -47,7 +48,7 @@
        public function __construct(
                EntityDiffer $entityDiffer,
                EntityIdParser $idParser,
-               array $changeClasses = []
+               array $changeClasses
        ) {
                $this->entityDiffer = $entityDiffer;
                $this->idParser = $idParser;
@@ -92,25 +93,33 @@
         * @param EntityId $entityId
         * @param array $fields additional fields to set
         *
+        * @throws InvalidArgumentException
         * @return EntityChange
         */
        public function newForChangeType( $changeType, EntityId $entityId, 
array $fields ) {
-               $action = explode( '~', $changeType )[1];
+               $changeType = explode( '~', $changeType, 2 );
+               Assert::parameter(
+                       isset( $changeType[1] ),
+                       '$changeType',
+                       'must conform to the format 
"wikibase-<entityType>~<action>"'
+               );
+
+               $action = $changeType[1];
                return $this->newForEntity( $action, $entityId, $fields );
        }
 
        /**
         * @param array $fields all data fields, including at least 'type' and 
'object_id'.
+        *
+        * @throws InvalidArgumentException
         * @return EntityChange
         */
        public function newFromFieldData( array $fields ) {
                Assert::parameter( isset( $fields['type'] ), 
'$fields[\'type\']', 'must be set' );
                Assert::parameter( isset( $fields['object_id'] ), 
'$fields[\'object_id\']', 'must be set' );
 
-               $action = explode( '~', $fields['type'] )[1];
                $entityId = $this->idParser->parse( $fields['object_id'] );
-
-               return $this->newForEntity( $action, $entityId, $fields );
+               return $this->newForChangeType( $fields['type'], $entityId, 
$fields );
        }
 
        /**
@@ -148,8 +157,7 @@
                        $diff = $this->entityDiffer->diffEntities( $oldEntity, 
$newEntity );
                }
 
-               /** @var EntityChange $instance */
-               $instance = self::newForEntity( $action, $id );
+               $instance = $this->newForEntity( $action, $id );
                $instance->setDiff( $diff );
 
                return $instance;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If47e719af40088b25e81c29059530146707d7de3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to