@@ -70,16 +70,32 @@ class Parser implements ParserInterface, LoggerAwareInterface
7070{
7171 use LoggerAwareTrait;
7272
73+ /** @deprecated Use `MSG_GET_SCHEMA_FAILED_FOR_RESOURCE_AT_XXX` instead
74+ * Message code.
75+ */
76+ const MSG_SCHEME_NOT_REGISTERED = self ::MSG_GET_SCHEMA_FAILED_FOR_RESOURCE_AT_PATH ;
77+
7378 /**
7479 * Message code.
7580 */
76- const MSG_SCHEME_NOT_REGISTERED = 0 ;
81+ const MSG_GET_SCHEMA_FAILED_FOR_RESOURCE_AT_ROOT = 0 ;
82+
83+ /**
84+ * Message code.
85+ */
86+ const MSG_GET_SCHEMA_FAILED_FOR_RESOURCE_AT_PATH = self ::MSG_GET_SCHEMA_FAILED_FOR_RESOURCE_AT_ROOT + 1 ;
7787
7888 /**
7989 * Default messages.
8090 */
8191 const MESSAGES = [
82- self ::MSG_SCHEME_NOT_REGISTERED => 'Schema is not registered for a resource at path \'%s \'. ' ,
92+ self ::MSG_GET_SCHEMA_FAILED_FOR_RESOURCE_AT_ROOT =>
93+ 'Getting Schema for a top-level resource of type `%s` failed. ' .
94+ 'Please check you have added a Schema for this type. ' ,
95+
96+ self ::MSG_GET_SCHEMA_FAILED_FOR_RESOURCE_AT_PATH =>
97+ 'Getting Schema for a resource of type `%s` at path `%s` failed. ' .
98+ 'Please check you have added a Schema for this type. ' ,
8399 ];
84100
85101 /**
@@ -291,13 +307,21 @@ protected function analyzeData($data): array
291307 * @return SchemaInterface
292308 *
293309 * @SuppressWarnings(PHPMD.StaticAccess)
310+ * @SuppressWarnings(PHPMD.ElseExpression)
294311 */
295312 private function getSchema ($ resource , StackFrameReadOnlyInterface $ frame ): SchemaInterface
296313 {
297314 try {
298315 $ schema = $ this ->container ->getSchema ($ resource );
299316 } catch (InvalidArgumentException $ exception ) {
300- $ message = _ ($ this ->messages [self ::MSG_SCHEME_NOT_REGISTERED ], $ frame ->getPath ());
317+ $ path = $ frame ->getPath ();
318+ $ typeName = is_object ($ resource ) === true ? get_class ($ resource ) : gettype ($ resource );
319+ if ($ path === null ) {
320+ $ message = _ ($ this ->messages [static ::MSG_GET_SCHEMA_FAILED_FOR_RESOURCE_AT_ROOT ], $ typeName );
321+ } else {
322+ $ message = _ ($ this ->messages [static ::MSG_GET_SCHEMA_FAILED_FOR_RESOURCE_AT_PATH ], $ typeName , $ path );
323+ }
324+
301325 throw new InvalidArgumentException ($ message , 0 , $ exception );
302326 }
303327
0 commit comments