@@ -39,13 +39,19 @@ public function __construct( array $idBuilders ) {
3939 public function parse ( $ idSerialization ) {
4040 $ this ->assertIdIsString ( $ idSerialization );
4141
42+ if ( empty ( $ this ->idBuilders ) ) {
43+ throw new EntityIdParsingException ( 'No id builders are configured ' );
44+ }
45+
4246 foreach ( $ this ->idBuilders as $ idPattern => $ idBuilder ) {
4347 if ( preg_match ( $ idPattern , $ idSerialization ) ) {
4448 return $ this ->buildId ( $ idBuilder , $ idSerialization );
4549 }
4650 }
4751
48- throw $ this ->newInvalidIdException ( $ idSerialization );
52+ throw new EntityIdParsingException (
53+ "The serialization \"$ idSerialization \" is not recognized by the configured id builders "
54+ );
4955 }
5056
5157 /**
@@ -55,7 +61,7 @@ public function parse( $idSerialization ) {
5561 */
5662 private function assertIdIsString ( $ idSerialization ) {
5763 if ( !is_string ( $ idSerialization ) ) {
58- throw new EntityIdParsingException ( '$idSerialization must be a string; got ' . gettype ( $ idSerialization ) );
64+ throw new EntityIdParsingException ( '$idSerialization must be a string ' );
5965 }
6066 }
6167
@@ -69,21 +75,10 @@ private function assertIdIsString( $idSerialization ) {
6975 private function buildId ( $ idBuilder , $ idSerialization ) {
7076 try {
7177 return call_user_func ( $ idBuilder , $ idSerialization );
78+ } catch ( InvalidArgumentException $ ex ) {
79+ // Should not happen, but if it does, re-throw the original message
80+ throw new EntityIdParsingException ( $ ex ->getMessage () );
7281 }
73- catch ( InvalidArgumentException $ ex ) {
74- throw $ this ->newInvalidIdException ( $ idSerialization );
75- }
76- }
77-
78- /**
79- * @param string $idSerialization
80- *
81- * @return EntityIdParsingException
82- */
83- private function newInvalidIdException ( $ idSerialization ) {
84- return new EntityIdParsingException (
85- 'The provided id serialization " ' . $ idSerialization . '" is not valid '
86- );
8782 }
8883
8984}
0 commit comments