jenkins-bot has submitted this change and it was merged.

Change subject: Got rid of PropertyValueSnak::newFromPropertyValue
......................................................................


Got rid of PropertyValueSnak::newFromPropertyValue

Change-Id: Ifa76632e17459a63b89aa92404513f655b5d228f
---
M DataModel/DataModel/Snak/PropertyValueSnak.php
M DataModel/DataModel/Snak/SnakFactory.php
2 files changed, 20 insertions(+), 37 deletions(-)

Approvals:
  Daniel Kinzler: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/DataModel/DataModel/Snak/PropertyValueSnak.php 
b/DataModel/DataModel/Snak/PropertyValueSnak.php
index fcc4d7b..ada5083 100644
--- a/DataModel/DataModel/Snak/PropertyValueSnak.php
+++ b/DataModel/DataModel/Snak/PropertyValueSnak.php
@@ -3,7 +3,6 @@
 namespace Wikibase;
 
 use DataValues\DataValue;
-use MWException;
 
 /**
  * Class representing a property value snak.
@@ -117,40 +116,6 @@
         */
        public function getType() {
                return 'value';
-       }
-
-       /**
-        * Returns a new PropertyValueSnak constructed from the provided value.
-        * The DataValue
-        *
-        * @since 0.3
-        * @deprecated since 0.4
-        *
-        * @param EntityId $propertyId
-        * @param mixed $rawDataValue
-        *
-        * @return PropertyValueSnak
-        * @throws MWException
-        */
-       public static function newFromPropertyValue( EntityId $propertyId, 
$rawDataValue ) {
-               if ( $propertyId->getEntityType() !== Property::ENTITY_TYPE ) {
-                       throw new MWException( 'Expected an EntityId of a 
property' );
-               }
-
-               $content = EntityContentFactory::singleton()->getFromId( 
$propertyId );
-
-               if ( $content === null ) {
-                       throw new MWException( 'Cannot create a DataValue for a 
non-existing property' );
-               }
-
-               /**
-                * @var Property $property
-                */
-               $property = $content->getEntity();
-
-               $dataValue = $property->newDataValue( $rawDataValue );
-
-               return new static( $propertyId, $dataValue );
        }
 
 }
\ No newline at end of file
diff --git a/DataModel/DataModel/Snak/SnakFactory.php 
b/DataModel/DataModel/Snak/SnakFactory.php
index ebdc0ef..42e2e99 100644
--- a/DataModel/DataModel/Snak/SnakFactory.php
+++ b/DataModel/DataModel/Snak/SnakFactory.php
@@ -2,10 +2,14 @@
 
 namespace Wikibase;
 
+use InvalidArgumentException;
 use MWException;
 
 /**
  * Factory for creating new snaks.
+ *
+ * FIXME: right now this is dependent on retrieving properties. It thus does 
not
+ * fit in the DataModel component. Perhaps it can be moved to Wikibase lib.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -42,15 +46,29 @@
         *
         * @return Snak
         * @throws MWException
+        * @throws InvalidArgumentException
         */
        public function newSnak( EntityId $propertyId, $snakType, $snakValue = 
null ) {
                if ( $propertyId->getEntityType() !== Property::ENTITY_TYPE ) {
-                       throw new MWException( 'Expected an EntityId of a 
property' );
+                       throw new InvalidArgumentException( 'Expected an 
EntityId of a property' );
                }
 
                switch ( $snakType ) {
                        case 'value':
-                               $snak = 
PropertyValueSnak::newFromPropertyValue( $propertyId, $snakValue );
+                               $content = 
EntityContentFactory::singleton()->getFromId( $propertyId );
+
+                               if ( $content === null ) {
+                                       throw new MWException( 'Cannot create a 
DataValue for a non-existing property' );
+                               }
+
+                               /**
+                                * @var Property $property
+                                */
+                               $property = $content->getEntity();
+
+                               $dataValue = 
\DataValues\DataValueFactory::singleton()->newDataValue( 
$property->getDataType()->getDataValueType(), $snakValue );
+
+                               $snak = new PropertyValueSnak( $propertyId, 
$dataValue );
                                break;
                        case 'novalue':
                                $snak = new PropertyNoValueSnak( $propertyId );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ifa76632e17459a63b89aa92404513f655b5d228f
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to