Permalink
Browse files

Inline a few trivial private methods

  • Loading branch information...
1 parent 7d7b0ce commit 8d0b41db969ad4426049d2f2df12d5b900fd6f43 @thiemowmde thiemowmde committed Feb 7, 2017
@@ -37,7 +37,9 @@ public function __construct( EntityIdParser $entityIdParser ) {
* @return EntityId
*/
public function deserialize( $serialization ) {
- $this->assertEntityIdIsString( $serialization );
+ if ( !is_string( $serialization ) ) {
+ throw new DeserializationException( 'The serialization of an entity ID should be a string' );
+ }
try {
return $this->entityIdParser->parse( $serialization );
@@ -46,15 +48,4 @@ public function deserialize( $serialization ) {
}
}
- /**
- * @param string $serialization
- *
- * @throws DeserializationException
- */
- private function assertEntityIdIsString( $serialization ) {
- if ( !is_string( $serialization ) ) {
- throw new DeserializationException( 'The serialization of an entity ID should be a string' );
- }
- }
-
}
@@ -53,11 +53,11 @@ private function isValidSerialization( $serialization ) {
* @return Reference
*/
public function deserialize( $serialization ) {
- $this->assertCanDeserialize( $serialization );
-
- $reference = $this->getDeserialized( $serialization );
+ if ( !$this->isValidSerialization( $serialization ) ) {
+ throw new DeserializationException( 'The serialization is invalid' );
+ }
- return $reference;
+ return $this->getDeserialized( $serialization );
}
/**
@@ -88,12 +88,6 @@ private function deserializeSnaks( array $serialization ) {
return $snaks;
}
- private function assertCanDeserialize( $serialization ) {
- if ( !$this->isValidSerialization( $serialization ) ) {
- throw new DeserializationException( 'The serialization is invalid' );
- }
- }
-
private function assertSnaksOrderIsArray( array $serialization ) {
if ( !is_array( $serialization['snaks-order'] ) ) {
throw new InvalidAttributeException(
@@ -36,7 +36,9 @@ public function __construct( Deserializer $referenceDeserializer ) {
* @return ReferenceList
*/
public function deserialize( $serialization ) {
- $this->assertIsArray( $serialization );
+ if ( !is_array( $serialization ) ) {
+ throw new DeserializationException( 'The ReferenceList serialization should be an array' );
+ }
return $this->getDeserialized( $serialization );
}
@@ -58,10 +60,4 @@ private function getDeserialized( array $serialization ) {
return $referenceList;
}
- private function assertIsArray( $serialization ) {
- if ( !is_array( $serialization ) ) {
- throw new DeserializationException( 'The ReferenceList serialization should be an array' );
- }
- }
-
}
@@ -22,11 +22,11 @@
*/
class StatementDeserializer implements DispatchableDeserializer {
- private $rankIds = array(
+ private static $rankIds = [
'deprecated' => Statement::RANK_DEPRECATED,
'normal' => Statement::RANK_NORMAL,
'preferred' => Statement::RANK_PREFERRED
- );
+ ];
/**
* @var Deserializer
@@ -61,15 +61,18 @@ public function __construct(
* @return bool
*/
public function isDeserializerFor( $serialization ) {
- return $this->hasType( $serialization ) && $this->hasCorrectType( $serialization );
+ return is_array( $serialization )
+ && array_key_exists( 'type', $serialization )
+ && $this->isValidStatementType( $serialization['type'] );
}
- private function hasType( $serialization ) {
- return is_array( $serialization ) && array_key_exists( 'type', $serialization );
- }
-
- private function hasCorrectType( $serialization ) {
- return in_array( $serialization['type'], array( 'claim', 'statement' ) );
+ /**
+ * @param string $statementType
+ *
+ * @return bool
+ */
+ private function isValidStatementType( $statementType ) {
+ return $statementType === 'statement' || $statementType === 'claim';
}
/**
@@ -86,14 +89,12 @@ public function deserialize( $serialization ) {
throw new MissingTypeException();
}
- if ( $serialization['type'] !== 'claim' && $serialization['type'] !== 'statement' ) {
+ if ( !$this->isValidStatementType( $serialization['type'] ) ) {
throw new UnsupportedTypeException( $serialization['type'] );
}
if ( !array_key_exists( 'mainsnak', $serialization ) ) {
- throw new MissingAttributeException(
- 'mainsnak'
- );
+ throw new MissingAttributeException( 'mainsnak' );
}
return $this->getDeserialized( $serialization );
@@ -148,11 +149,11 @@ private function setQualifiersFromSerialization( array $serialization, Statement
}
private function setRankFromSerialization( array $serialization, Statement $statement ) {
- if ( !array_key_exists( $serialization['rank'], $this->rankIds ) ) {
+ if ( !array_key_exists( $serialization['rank'], self::$rankIds ) ) {
throw new DeserializationException( 'The rank ' . $serialization['rank'] . ' is not a valid rank.' );
}
- $statement->setRank( $this->rankIds[$serialization['rank']] );
+ $statement->setRank( self::$rankIds[$serialization['rank']] );
}
private function setReferencesFromSerialization( array $serialization, Statement $statement ) {

0 comments on commit 8d0b41d

Please sign in to comment.