@@ -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
0 commit comments