Skip to content

Commit 15ababd

Browse files
manickiWMDE bot
authored andcommitted
Removed the usage of splitSerialization from DispatchingIdParser
Bug: T291823 Change-Id: I41fe09b424af5d828cda04a65efe407362b1f3c4
1 parent e1bb894 commit 15ababd

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

src/Entity/DispatchingEntityIdParser.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,14 @@ public function __construct( array $idBuilders ) {
3737
* @return EntityId
3838
*/
3939
public function parse( $idSerialization ) {
40+
$this->assertIdIsString( $idSerialization );
41+
4042
if ( $this->idBuilders === [] ) {
4143
throw new EntityIdParsingException( 'No id builders are configured' );
4244
}
4345

44-
try {
45-
list( , , $localId ) = SerializableEntityId::splitSerialization( $idSerialization );
46-
} catch ( InvalidArgumentException $ex ) {
47-
// SerializableEntityId::splitSerialization performs some sanity checks which
48-
// might result in an exception. Should this happen, re-throw the exception message
49-
throw new EntityIdParsingException( $ex->getMessage(), 0, $ex );
50-
}
51-
5246
foreach ( $this->idBuilders as $idPattern => $idBuilder ) {
53-
if ( preg_match( $idPattern, $localId ) ) {
47+
if ( preg_match( $idPattern, $idSerialization ) ) {
5448
return $this->buildId( $idBuilder, $idSerialization );
5549
}
5650
}
@@ -60,6 +54,21 @@ public function parse( $idSerialization ) {
6054
);
6155
}
6256

57+
/**
58+
* @param string $idSerialization
59+
*
60+
* @throws EntityIdParsingException
61+
*/
62+
private function assertIdIsString( $idSerialization ) {
63+
if ( !is_string( $idSerialization ) ) {
64+
throw new EntityIdParsingException(
65+
'$idSerialization must be a string, got ' . ( is_object( $idSerialization )
66+
? get_class( $idSerialization )
67+
: getType( $idSerialization ) )
68+
);
69+
}
70+
}
71+
6372
/**
6473
* @param callable $idBuilder
6574
* @param string $idSerialization

tests/unit/Entity/DispatchingEntityIdParserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public static function entityIdProvider() {
3838
[ 'Q1337', new ItemId( 'Q1337' ) ],
3939
[ 'p1', new NumericPropertyId( 'p1' ) ],
4040
[ 'P100000', new NumericPropertyId( 'P100000' ) ],
41-
[ ':Q1337', new ItemId( ':Q1337' ) ],
4241
];
4342
}
4443

@@ -61,6 +60,7 @@ public static function invalidIdSerializationProvider() {
6160
[ '' ],
6261
[ 'q0' ],
6362
[ '1p' ],
63+
[ ':Q1337' ],
6464
[ 'foo:' ],
6565
[ 'foo:bar:' ],
6666
[ '::Q1337' ],

0 commit comments

Comments
 (0)