Skip to content

Commit 47c96c6

Browse files
authored
Merge pull request #207 from wmde/inline
Inline a few trivial private methods
2 parents 7d7b0ce + 8d0b41d commit 47c96c6

4 files changed

Lines changed: 26 additions & 44 deletions

File tree

src/Deserializers/EntityIdDeserializer.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ public function __construct( EntityIdParser $entityIdParser ) {
3737
* @return EntityId
3838
*/
3939
public function deserialize( $serialization ) {
40-
$this->assertEntityIdIsString( $serialization );
40+
if ( !is_string( $serialization ) ) {
41+
throw new DeserializationException( 'The serialization of an entity ID should be a string' );
42+
}
4143

4244
try {
4345
return $this->entityIdParser->parse( $serialization );
@@ -46,15 +48,4 @@ public function deserialize( $serialization ) {
4648
}
4749
}
4850

49-
/**
50-
* @param string $serialization
51-
*
52-
* @throws DeserializationException
53-
*/
54-
private function assertEntityIdIsString( $serialization ) {
55-
if ( !is_string( $serialization ) ) {
56-
throw new DeserializationException( 'The serialization of an entity ID should be a string' );
57-
}
58-
}
59-
6051
}

src/Deserializers/ReferenceDeserializer.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ private function isValidSerialization( $serialization ) {
5353
* @return Reference
5454
*/
5555
public function deserialize( $serialization ) {
56-
$this->assertCanDeserialize( $serialization );
57-
58-
$reference = $this->getDeserialized( $serialization );
56+
if ( !$this->isValidSerialization( $serialization ) ) {
57+
throw new DeserializationException( 'The serialization is invalid' );
58+
}
5959

60-
return $reference;
60+
return $this->getDeserialized( $serialization );
6161
}
6262

6363
/**
@@ -88,12 +88,6 @@ private function deserializeSnaks( array $serialization ) {
8888
return $snaks;
8989
}
9090

91-
private function assertCanDeserialize( $serialization ) {
92-
if ( !$this->isValidSerialization( $serialization ) ) {
93-
throw new DeserializationException( 'The serialization is invalid' );
94-
}
95-
}
96-
9791
private function assertSnaksOrderIsArray( array $serialization ) {
9892
if ( !is_array( $serialization['snaks-order'] ) ) {
9993
throw new InvalidAttributeException(

src/Deserializers/ReferenceListDeserializer.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public function __construct( Deserializer $referenceDeserializer ) {
3636
* @return ReferenceList
3737
*/
3838
public function deserialize( $serialization ) {
39-
$this->assertIsArray( $serialization );
39+
if ( !is_array( $serialization ) ) {
40+
throw new DeserializationException( 'The ReferenceList serialization should be an array' );
41+
}
4042

4143
return $this->getDeserialized( $serialization );
4244
}
@@ -58,10 +60,4 @@ private function getDeserialized( array $serialization ) {
5860
return $referenceList;
5961
}
6062

61-
private function assertIsArray( $serialization ) {
62-
if ( !is_array( $serialization ) ) {
63-
throw new DeserializationException( 'The ReferenceList serialization should be an array' );
64-
}
65-
}
66-
6763
}

src/Deserializers/StatementDeserializer.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
*/
2323
class StatementDeserializer implements DispatchableDeserializer {
2424

25-
private $rankIds = array(
25+
private static $rankIds = [
2626
'deprecated' => Statement::RANK_DEPRECATED,
2727
'normal' => Statement::RANK_NORMAL,
2828
'preferred' => Statement::RANK_PREFERRED
29-
);
29+
];
3030

3131
/**
3232
* @var Deserializer
@@ -61,15 +61,18 @@ public function __construct(
6161
* @return bool
6262
*/
6363
public function isDeserializerFor( $serialization ) {
64-
return $this->hasType( $serialization ) && $this->hasCorrectType( $serialization );
64+
return is_array( $serialization )
65+
&& array_key_exists( 'type', $serialization )
66+
&& $this->isValidStatementType( $serialization['type'] );
6567
}
6668

67-
private function hasType( $serialization ) {
68-
return is_array( $serialization ) && array_key_exists( 'type', $serialization );
69-
}
70-
71-
private function hasCorrectType( $serialization ) {
72-
return in_array( $serialization['type'], array( 'claim', 'statement' ) );
69+
/**
70+
* @param string $statementType
71+
*
72+
* @return bool
73+
*/
74+
private function isValidStatementType( $statementType ) {
75+
return $statementType === 'statement' || $statementType === 'claim';
7376
}
7477

7578
/**
@@ -86,14 +89,12 @@ public function deserialize( $serialization ) {
8689
throw new MissingTypeException();
8790
}
8891

89-
if ( $serialization['type'] !== 'claim' && $serialization['type'] !== 'statement' ) {
92+
if ( !$this->isValidStatementType( $serialization['type'] ) ) {
9093
throw new UnsupportedTypeException( $serialization['type'] );
9194
}
9295

9396
if ( !array_key_exists( 'mainsnak', $serialization ) ) {
94-
throw new MissingAttributeException(
95-
'mainsnak'
96-
);
97+
throw new MissingAttributeException( 'mainsnak' );
9798
}
9899

99100
return $this->getDeserialized( $serialization );
@@ -148,11 +149,11 @@ private function setQualifiersFromSerialization( array $serialization, Statement
148149
}
149150

150151
private function setRankFromSerialization( array $serialization, Statement $statement ) {
151-
if ( !array_key_exists( $serialization['rank'], $this->rankIds ) ) {
152+
if ( !array_key_exists( $serialization['rank'], self::$rankIds ) ) {
152153
throw new DeserializationException( 'The rank ' . $serialization['rank'] . ' is not a valid rank.' );
153154
}
154155

155-
$statement->setRank( $this->rankIds[$serialization['rank']] );
156+
$statement->setRank( self::$rankIds[$serialization['rank']] );
156157
}
157158

158159
private function setReferencesFromSerialization( array $serialization, Statement $statement ) {

0 commit comments

Comments
 (0)