44
55namespace FlixTech \SchemaRegistryApi \Exception ;
66
7+ use Exception ;
78use GuzzleHttp \Exception \RequestException ;
89use Psr \Http \Message \ResponseInterface ;
10+ use RuntimeException ;
11+ use function array_key_exists ;
12+ use function sprintf ;
913
1014final class ExceptionMap
1115{
@@ -14,7 +18,7 @@ final class ExceptionMap
1418 public const ERROR_MESSAGE_FIELD_NAME = 'message ' ;
1519
1620 /**
17- * @var \FlixTech\SchemaRegistryApi\Exception\ ExceptionMap
21+ * @var ExceptionMap
1822 */
1923 private static $ instance ;
2024
@@ -38,7 +42,7 @@ private function __construct()
3842 *
3943 * @return SchemaRegistryException
4044 *
41- * @throws \ RuntimeException
45+ * @throws RuntimeException
4246 */
4347 public function __invoke (RequestException $ exception ): SchemaRegistryException
4448 {
@@ -55,7 +59,7 @@ private function guardAgainstMissingResponse(RequestException $exception): Respo
5559 $ response = $ exception ->getResponse ();
5660
5761 if (!$ response ) {
58- throw new \ RuntimeException ('RequestException has no response to inspect ' , 0 , $ exception );
62+ throw new RuntimeException ('RequestException has no response to inspect ' , 0 , $ exception );
5963 }
6064
6165 return $ response ;
@@ -70,8 +74,8 @@ private function guardAgainstMissingErrorCode(ResponseInterface $response): arra
7074 try {
7175 $ decodedBody = \GuzzleHttp \json_decode ((string ) $ response ->getBody (), true );
7276
73- if (!\ array_key_exists (self ::ERROR_CODE_FIELD_NAME , $ decodedBody )) {
74- throw new \ RuntimeException (
77+ if (!array_key_exists (self ::ERROR_CODE_FIELD_NAME , $ decodedBody )) {
78+ throw new RuntimeException (
7579 sprintf (
7680 'Invalid message body received - cannot find "error_code" field in response body "%s" ' ,
7781 (string ) $ response ->getBody ()
@@ -80,9 +84,9 @@ private function guardAgainstMissingErrorCode(ResponseInterface $response): arra
8084 }
8185
8286 return $ decodedBody ;
83- } catch (\ Exception $ e ) {
84- throw new \ RuntimeException (
85- \ sprintf (
87+ } catch (Exception $ e ) {
88+ throw new RuntimeException (
89+ sprintf (
8690 'Invalid message body received - cannot find "error_code" field in response body "%s" ' ,
8791 (string ) $ response ->getBody ()
8892 ),
@@ -92,12 +96,7 @@ private function guardAgainstMissingErrorCode(ResponseInterface $response): arra
9296 }
9397 }
9498
95- /**
96- * @param int $errorCode
97- * @param string $errorMessage
98- * @return SchemaRegistryException
99- */
100- private function mapErrorCodeToException ($ errorCode , $ errorMessage ): SchemaRegistryException
99+ private function mapErrorCodeToException (int $ errorCode , string $ errorMessage ): SchemaRegistryException
101100 {
102101 switch ($ errorCode ) {
103102 case IncompatibleAvroSchemaException::errorCode ():
@@ -131,7 +130,7 @@ private function mapErrorCodeToException($errorCode, $errorMessage): SchemaRegis
131130 return new InvalidCompatibilityLevelException ($ errorMessage , $ errorCode );
132131
133132 default :
134- throw new \ RuntimeException (sprintf ('Unknown error code "%d" ' , $ errorCode ));
133+ throw new RuntimeException (sprintf ('Unknown error code "%d" ' , $ errorCode ));
135134 }
136135 }
137136}
0 commit comments