Addshore has uploaded a new change for review.
https://gerrit.wikimedia.org/r/84300
Change subject: Split ChangeOp into interface and base class
......................................................................
Split ChangeOp into interface and base class
We can now type hint the ChangeOp without having
IDE errors!
Change-Id: I9a86c52a88535488ebe6bf5872dfc4042b421031
---
M repo/Wikibase.classes.php
M repo/includes/changeop/ChangeOp.php
M repo/includes/changeop/ChangeOpAliases.php
A repo/includes/changeop/ChangeOpBase.php
M repo/includes/changeop/ChangeOpClaim.php
M repo/includes/changeop/ChangeOpDescription.php
M repo/includes/changeop/ChangeOpLabel.php
M repo/includes/changeop/ChangeOpMainSnak.php
M repo/includes/changeop/ChangeOpQualifier.php
M repo/includes/changeop/ChangeOpReference.php
M repo/includes/changeop/ChangeOpSiteLink.php
M repo/includes/changeop/ChangeOpStatementRank.php
M repo/includes/changeop/ChangeOps.php
13 files changed, 65 insertions(+), 131 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/00/84300/1
diff --git a/repo/Wikibase.classes.php b/repo/Wikibase.classes.php
index e1050b6..00adfa0 100644
--- a/repo/Wikibase.classes.php
+++ b/repo/Wikibase.classes.php
@@ -52,6 +52,7 @@
// includes/changeop
'Wikibase\ChangeOps' => 'includes/changeop/ChangeOps.php',
'Wikibase\ChangeOp' => 'includes/changeop/ChangeOp.php',
+ 'Wikibase\ChangeOpBase' => 'includes/changeop/ChangeOpBase.php',
'Wikibase\ChangeOpLabel' =>
'includes/changeop/ChangeOpLabel.php',
'Wikibase\ChangeOpDescription' =>
'includes/changeop/ChangeOpDescription.php',
'Wikibase\ChangeOpAliases' =>
'includes/changeop/ChangeOpAliases.php',
diff --git a/repo/includes/changeop/ChangeOp.php
b/repo/includes/changeop/ChangeOp.php
index 58565a9..93b016e 100644
--- a/repo/includes/changeop/ChangeOp.php
+++ b/repo/includes/changeop/ChangeOp.php
@@ -2,20 +2,15 @@
namespace Wikibase;
-use InvalidArgumentException;
-
/**
- * Base class for change operations.
- *
- * @since 0.4
- *
+ * @since 0.5
* @licence GNU GPL v2+
- * @author Tobias Gritschacher < [email protected] >
+ * @author Adam Shorland
*/
-abstract class ChangeOp {
+interface ChangeOp {
/**
- * @since 0.4
+ * @since 0.5
*
* @param Entity $entity
* @param Summary|null $summary
@@ -24,28 +19,6 @@
*
* @throws ChangeOpException
*/
- abstract public function apply( Entity $entity, Summary $summary = null
);
+ public function apply( Entity $entity, Summary $summary = null );
- /**
- * @since 0.4
- *
- * @param Summary $summary
- * @param string $action
- * @param string $language
- * @param string|array $args
- *
- * @throws InvalidArgumentException
- */
- protected function updateSummary( $summary, $action, $language = '',
$args = '' ) {
- if ( $summary !== null && !$summary instanceof Summary ) {
- throw new InvalidArgumentException( '$summary needs to
be an instance of Summary or null' );
- }
-
- if ( $summary !== null ) {
- $summary->setAction( $action );
- $summary->setLanguage( $language );
- $summary->addAutoSummaryArgs( $args );
- }
- }
-
-}
+}
\ No newline at end of file
diff --git a/repo/includes/changeop/ChangeOpAliases.php
b/repo/includes/changeop/ChangeOpAliases.php
index f1cf61a..4f3ae2b 100644
--- a/repo/includes/changeop/ChangeOpAliases.php
+++ b/repo/includes/changeop/ChangeOpAliases.php
@@ -29,7 +29,7 @@
* @licence GNU GPL v2+
* @author Tobias Gritschacher < [email protected] >
*/
-class ChangeOpAliases extends ChangeOp {
+class ChangeOpAliases extends ChangeOpBase {
/**
* @since 0.4
@@ -76,16 +76,7 @@
}
/**
- * Applies the change to the given entity
- *
- * @since 0.4
- *
- * @param Entity $entity
- * @param Summary|null $summary
- *
- * @return bool
- *
- * @throws ChangeOpException
+ * @see ChangeOp::apply()
*/
public function apply( Entity $entity, Summary $summary = null ) {
if ( $this->action === "" || $this->action === "set" ) {
diff --git a/repo/includes/changeop/ChangeOpBase.php
b/repo/includes/changeop/ChangeOpBase.php
new file mode 100644
index 0000000..210d079
--- /dev/null
+++ b/repo/includes/changeop/ChangeOpBase.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace Wikibase;
+
+use InvalidArgumentException;
+
+/**
+ * Base class for change operations.
+ *
+ * @since 0.4
+ *
+ * @licence GNU GPL v2+
+ * @author Tobias Gritschacher < [email protected] >
+ */
+abstract class ChangeOpBase implements ChangeOp {
+
+ /**
+ * @since 0.4
+ *
+ * @param Summary $summary
+ * @param string $action
+ * @param string $language
+ * @param string|array $args
+ *
+ * @throws InvalidArgumentException
+ */
+ protected function updateSummary( $summary, $action, $language = '',
$args = '' ) {
+ if ( $summary !== null && !$summary instanceof Summary ) {
+ throw new InvalidArgumentException( '$summary needs to
be an instance of Summary or null' );
+ }
+
+ if ( $summary !== null ) {
+ $summary->setAction( $action );
+ $summary->setLanguage( $language );
+ $summary->addAutoSummaryArgs( $args );
+ }
+ }
+
+}
diff --git a/repo/includes/changeop/ChangeOpClaim.php
b/repo/includes/changeop/ChangeOpClaim.php
index 5a7667b..ba54979 100644
--- a/repo/includes/changeop/ChangeOpClaim.php
+++ b/repo/includes/changeop/ChangeOpClaim.php
@@ -16,7 +16,7 @@
* @licence GNU GPL v2+
* @author Adam Shorland
*/
-class ChangeOpClaim extends ChangeOp {
+class ChangeOpClaim extends ChangeOpBase {
/**
* @since 0.4
@@ -63,16 +63,7 @@
}
/**
- * Applies the change to the given entity
- *
- * @since 0.4
- *
- * @param Entity $entity
- * @param Summary|null $summary
- *
- * @return bool
- *
- * @throws ChangeOpException
+ * @see ChangeOp::apply()
*/
public function apply( Entity $entity, Summary $summary = null ) {
diff --git a/repo/includes/changeop/ChangeOpDescription.php
b/repo/includes/changeop/ChangeOpDescription.php
index c249180..83d89aa 100644
--- a/repo/includes/changeop/ChangeOpDescription.php
+++ b/repo/includes/changeop/ChangeOpDescription.php
@@ -29,7 +29,7 @@
* @licence GNU GPL v2+
* @author Tobias Gritschacher < [email protected] >
*/
-class ChangeOpDescription extends ChangeOp {
+class ChangeOpDescription extends ChangeOpBase {
/**
* @since 0.4
@@ -63,14 +63,7 @@
}
/**
- * Applies the change to the given entity
- *
- * @since 0.4
- *
- * @param Entity $entity
- * @param Summary|null $summary
- *
- * @return bool
+ * @see ChangeOp::apply()
*/
public function apply( Entity $entity, Summary $summary = null ) {
if ( $this->description === null ) {
diff --git a/repo/includes/changeop/ChangeOpLabel.php
b/repo/includes/changeop/ChangeOpLabel.php
index 9f825ee..3c1ee13 100644
--- a/repo/includes/changeop/ChangeOpLabel.php
+++ b/repo/includes/changeop/ChangeOpLabel.php
@@ -29,7 +29,7 @@
* @licence GNU GPL v2+
* @author Tobias Gritschacher < [email protected] >
*/
-class ChangeOpLabel extends ChangeOp {
+class ChangeOpLabel extends ChangeOpBase {
/**
* @since 0.4
@@ -63,14 +63,7 @@
}
/**
- * Applies the change to the given entity
- *
- * @since 0.4
- *
- * @param Entity $entity
- * @param Summary|null $summary
- *
- * @return bool
+ * @see ChangeOp::apply()
*/
public function apply( Entity $entity, Summary $summary = null ) {
if ( $this->label === null ) {
diff --git a/repo/includes/changeop/ChangeOpMainSnak.php
b/repo/includes/changeop/ChangeOpMainSnak.php
index 247e5a1..b65dca2 100644
--- a/repo/includes/changeop/ChangeOpMainSnak.php
+++ b/repo/includes/changeop/ChangeOpMainSnak.php
@@ -31,7 +31,7 @@
* @licence GNU GPL v2+
* @author Tobias Gritschacher < [email protected] >
*/
-class ChangeOpMainSnak extends ChangeOp {
+class ChangeOpMainSnak extends ChangeOpBase {
/**
* @since 0.4
@@ -88,20 +88,10 @@
}
/**
- * Applies the change to the given entity
- *
+ * @see ChangeOp::apply()
* - the claim gets removed when $claimGuid is set and $snak is not set
* - a new claim with $snak as mainsnak gets added when $claimGuid is
empty and $snak is set
* - the claim's mainsnak gets set to $snak when $claimGuid and $snak
are set
- *
- * @since 0.4
- *
- * @param Entity $entity
- * @param Summary|null $summary
- *
- * @return bool
- *
- * @throws ChangeOpException
*/
public function apply( Entity $entity, Summary $summary = null ) {
$claims = new Claims( $entity->getClaims() );
diff --git a/repo/includes/changeop/ChangeOpQualifier.php
b/repo/includes/changeop/ChangeOpQualifier.php
index 7440d0b..86b6f6b 100644
--- a/repo/includes/changeop/ChangeOpQualifier.php
+++ b/repo/includes/changeop/ChangeOpQualifier.php
@@ -32,7 +32,7 @@
* @licence GNU GPL v2+
* @author Tobias Gritschacher < [email protected] >
*/
-class ChangeOpQualifier extends ChangeOp {
+class ChangeOpQualifier extends ChangeOpBase {
/**
* @since 0.4
@@ -98,20 +98,10 @@
}
/**
- * Applies the change to the given entity
- *
+ * @see ChangeOp::apply()
* - the qualifier gets removed when $snakHash is set and $snak is not
set
* - a new qualifier gets added when $snakHash is empty and $snak is set
* - the qualifier gets set to $snak when $snakHash and $snak are set
- *
- * @since 0.4
- *
- * @param Entity $entity
- * @param Summary|null $summary
- *
- * @return bool
- *
- * @throws ChangeOpException
*/
public function apply( Entity $entity, Summary $summary = null ) {
$claims = new Claims( $entity->getClaims() );
diff --git a/repo/includes/changeop/ChangeOpReference.php
b/repo/includes/changeop/ChangeOpReference.php
index b8f7bd5..b56df8e 100644
--- a/repo/includes/changeop/ChangeOpReference.php
+++ b/repo/includes/changeop/ChangeOpReference.php
@@ -34,7 +34,7 @@
* @licence GNU GPL v2+
* @author Tobias Gritschacher < [email protected] >
*/
-class ChangeOpReference extends ChangeOp {
+class ChangeOpReference extends ChangeOpBase {
/**
* @since 0.4
@@ -100,20 +100,10 @@
}
/**
- * Applies the change to the given entity
- *
+ * @see ChangeOp::apply()
* - the reference gets removed when $referenceHash is set and
$reference is not set
* - a new reference gets added when $referenceHash is empty and
$reference is set
* - the reference gets set to $reference when $referenceHash and
$reference are set
- *
- * @since 0.4
- *
- * @param Entity $entity
- * @param Summary|null $summary
- *
- * @return bool
- *
- * @throws ChangeOpException
*/
public function apply( Entity $entity, Summary $summary = null ) {
$claims = new Claims( $entity->getClaims() );
diff --git a/repo/includes/changeop/ChangeOpSiteLink.php
b/repo/includes/changeop/ChangeOpSiteLink.php
index 9b4e408..a7b0756 100644
--- a/repo/includes/changeop/ChangeOpSiteLink.php
+++ b/repo/includes/changeop/ChangeOpSiteLink.php
@@ -31,7 +31,7 @@
* @licence GNU GPL v2+
* @author Tobias Gritschacher < [email protected] >
*/
-class ChangeOpSiteLink extends ChangeOp {
+class ChangeOpSiteLink extends ChangeOpBase {
/**
* @since 0.4
@@ -69,15 +69,7 @@
}
/**
- * Applies the change to the given entity
- *
- * @since 0.4
- *
- * @param Entity $entity
- * @param Summary|null $summary
- *
- * @throws InvalidArgumentException
- * @throws ChangeOpException
+ * @see ChangeOp::apply()
*/
public function apply( Entity $entity, Summary $summary = null ) {
if ( !( $entity instanceof Item ) ) {
diff --git a/repo/includes/changeop/ChangeOpStatementRank.php
b/repo/includes/changeop/ChangeOpStatementRank.php
index 4346d0b..75527ff 100644
--- a/repo/includes/changeop/ChangeOpStatementRank.php
+++ b/repo/includes/changeop/ChangeOpStatementRank.php
@@ -33,7 +33,7 @@
* @licence GNU GPL v2+
* @author Tobias Gritschacher < [email protected] >
*/
-class ChangeOpStatementRank extends ChangeOp {
+class ChangeOpStatementRank extends ChangeOpBase {
/**
* @since 0.4
@@ -82,16 +82,7 @@
}
/**
- * Applies the change to the given entity
- *
- * @since 0.4
- *
- * @param Entity $entity
- * @param Summary|null $summary
- *
- * @return bool
- *
- * @throws ChangeOpException
+ * @see ChangeOp::apply()
*/
public function apply( Entity $entity, Summary $summary = null ) {
$claims = new Claims( $entity->getClaims() );
diff --git a/repo/includes/changeop/ChangeOps.php
b/repo/includes/changeop/ChangeOps.php
index b2f32bc..79ebc4a 100644
--- a/repo/includes/changeop/ChangeOps.php
+++ b/repo/includes/changeop/ChangeOps.php
@@ -92,9 +92,9 @@
* @param Entity $entity
* @param Summary|null $summary
*
+ * @throws ChangeOpException
* @return bool
*
- * @throws Change
*/
public function apply( Entity $entity, Summary $summary = null ) {
try {
--
To view, visit https://gerrit.wikimedia.org/r/84300
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9a86c52a88535488ebe6bf5872dfc4042b421031
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits