Skip to content

Commit 18f87fc

Browse files
committed
Streamline ItemId and PropertyId constructors a little
1 parent 3de9bfe commit 18f87fc

2 files changed

Lines changed: 8 additions & 18 deletions

File tree

src/Entity/ItemId.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,14 @@ class ItemId extends EntityId implements Int32EntityId {
2222
* @throws InvalidArgumentException
2323
*/
2424
public function __construct( $idSerialization ) {
25-
$serializationParts = self::splitSerialization( $idSerialization );
26-
$localId = strtoupper( $serializationParts[2] );
27-
$this->assertValidIdFormat( $localId );
25+
$parts = self::splitSerialization( $idSerialization );
26+
$this->assertValidIdFormat( $parts[2] );
2827
parent::__construct( self::joinSerialization(
29-
[ $serializationParts[0], $serializationParts[1], $localId ] )
30-
);
28+
[ $parts[0], $parts[1], strtoupper( $parts[2] ) ]
29+
) );
3130
}
3231

3332
private function assertValidIdFormat( $idSerialization ) {
34-
if ( !is_string( $idSerialization ) ) {
35-
throw new InvalidArgumentException( '$idSerialization must be a string' );
36-
}
37-
3833
if ( !preg_match( self::PATTERN, $idSerialization ) ) {
3934
throw new InvalidArgumentException( '$idSerialization must match ' . self::PATTERN );
4035
}

src/Entity/PropertyId.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,14 @@ class PropertyId extends EntityId implements Int32EntityId {
2222
* @throws InvalidArgumentException
2323
*/
2424
public function __construct( $idSerialization ) {
25-
$serializationParts = self::splitSerialization( $idSerialization );
26-
$localId = strtoupper( $serializationParts[2] );
27-
$this->assertValidIdFormat( $localId );
25+
$parts = self::splitSerialization( $idSerialization );
26+
$this->assertValidIdFormat( $parts[2] );
2827
parent::__construct( self::joinSerialization(
29-
[ $serializationParts[0], $serializationParts[1], $localId ] )
30-
);
28+
[ $parts[0], $parts[1], strtoupper( $parts[2] ) ]
29+
) );
3130
}
3231

3332
private function assertValidIdFormat( $idSerialization ) {
34-
if ( !is_string( $idSerialization ) ) {
35-
throw new InvalidArgumentException( '$idSerialization must be a string' );
36-
}
37-
3833
if ( !preg_match( self::PATTERN, $idSerialization ) ) {
3934
throw new InvalidArgumentException( '$idSerialization must match ' . self::PATTERN );
4035
}

0 commit comments

Comments
 (0)