Skip to content

Commit 60f8995

Browse files
manickiWMDE bot
authored andcommitted
DM: Removed the use of split/join Serialization from Item/Property ID
Bug: T291823 Change-Id: I9bb82a4420984f30cf924721fea89366e06ac770
1 parent e5140f3 commit 60f8995

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

src/Entity/ItemId.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ class ItemId extends SerializableEntityId implements Int32EntityId {
2222
* @throws InvalidArgumentException
2323
*/
2424
public function __construct( $idSerialization ) {
25-
$parts = self::splitSerialization( $idSerialization );
26-
$this->assertValidIdFormat( $parts[2] );
27-
parent::__construct( self::joinSerialization(
28-
[ $parts[0], $parts[1], strtoupper( $parts[2] ) ]
29-
) );
25+
$this->assertValidIdFormat( $idSerialization );
26+
parent::__construct( strtoupper( $idSerialization ) );
3027
}
3128

3229
private function assertValidIdFormat( $idSerialization ) {
30+
if ( !is_string( $idSerialization ) ) {
31+
throw new InvalidArgumentException( '$idSerialization must be a string' );
32+
}
33+
3334
if ( !preg_match( self::PATTERN, $idSerialization ) ) {
3435
throw new InvalidArgumentException( '$idSerialization must match ' . self::PATTERN );
3536
}
@@ -48,8 +49,7 @@ private function assertValidIdFormat( $idSerialization ) {
4849
* @return int Guaranteed to be a distinct integer in the range [1..2147483647].
4950
*/
5051
public function getNumericId() {
51-
$serializationParts = self::splitSerialization( $this->serialization );
52-
return (int)substr( $serializationParts[2], 1 );
52+
return (int)substr( $this->serialization, 1 );
5353
}
5454

5555
/**

src/Entity/NumericPropertyId.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ class NumericPropertyId extends SerializableEntityId implements PropertyId, Int3
1818
* @throws InvalidArgumentException
1919
*/
2020
public function __construct( $idSerialization ) {
21-
$parts = self::splitSerialization( $idSerialization );
22-
$this->assertValidIdFormat( $parts[2] );
23-
parent::__construct( self::joinSerialization(
24-
[ $parts[0], $parts[1], strtoupper( $parts[2] ) ]
25-
) );
21+
$this->assertValidIdFormat( $idSerialization );
22+
parent::__construct( strtoupper( $idSerialization ) );
2623
}
2724

2825
private function assertValidIdFormat( $idSerialization ) {
26+
if ( !is_string( $idSerialization ) ) {
27+
throw new InvalidArgumentException( '$idSerialization must be a string' );
28+
}
29+
2930
if ( !preg_match( self::PATTERN, $idSerialization ) ) {
3031
throw new InvalidArgumentException( '$idSerialization must match ' . self::PATTERN );
3132
}
@@ -44,8 +45,7 @@ private function assertValidIdFormat( $idSerialization ) {
4445
* @return int Guaranteed to be a distinct integer in the range [1..2147483647].
4546
*/
4647
public function getNumericId() {
47-
$serializationParts = self::splitSerialization( $this->serialization );
48-
return (int)substr( $serializationParts[2], 1 );
48+
return (int)substr( $this->serialization, 1 );
4949
}
5050

5151
/**

0 commit comments

Comments
 (0)