@@ -70,16 +70,32 @@ class Parser implements ParserInterface, LoggerAwareInterface
70
70
{
71
71
use LoggerAwareTrait;
72
72
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
+
73
78
/**
74
79
* Message code.
75
80
*/
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 ;
77
87
78
88
/**
79
89
* Default messages.
80
90
*/
81
91
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. ' ,
83
99
];
84
100
85
101
/**
@@ -291,13 +307,21 @@ protected function analyzeData($data): array
291
307
* @return SchemaInterface
292
308
*
293
309
* @SuppressWarnings(PHPMD.StaticAccess)
310
+ * @SuppressWarnings(PHPMD.ElseExpression)
294
311
*/
295
312
private function getSchema ($ resource , StackFrameReadOnlyInterface $ frame ): SchemaInterface
296
313
{
297
314
try {
298
315
$ schema = $ this ->container ->getSchema ($ resource );
299
316
} 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
+
301
325
throw new InvalidArgumentException ($ message , 0 , $ exception );
302
326
}
303
327
0 commit comments