1010use OpenApi \Generator ;
1111use OpenApi \Annotations as OA ;
1212use OpenApi \OpenApiException ;
13- use OpenApi \Util ;
1413use Symfony \Component \Yaml \Yaml ;
1514
1615/**
@@ -454,14 +453,14 @@ public function validate(array $stack = [], array $skip = [], string $ref = '',
454453 if ($ details = $ this ->matchNested ($ annotation )) {
455454 $ property = $ details ->value ;
456455 if (is_array ($ property )) {
457- $ this ->_context ->logger ->warning ('Only one ' . Util ::shorten (get_class ($ annotation )) . '() allowed for ' . $ this ->identity () . ' multiple found, skipped: ' . $ annotation ->_context );
456+ $ this ->_context ->logger ->warning ('Only one ' . static ::shorten (get_class ($ annotation )) . '() allowed for ' . $ this ->identity () . ' multiple found, skipped: ' . $ annotation ->_context );
458457 } else {
459- $ this ->_context ->logger ->warning ('Only one ' . Util ::shorten (get_class ($ annotation )) . '() allowed for ' . $ this ->identity () . " multiple found in: \n Using: " . $ this ->{$ property }->_context . "\n Skipped: " . $ annotation ->_context );
458+ $ this ->_context ->logger ->warning ('Only one ' . static ::shorten (get_class ($ annotation )) . '() allowed for ' . $ this ->identity () . " multiple found in: \n Using: " . $ this ->{$ property }->_context . "\n Skipped: " . $ annotation ->_context );
460459 }
461460 } elseif ($ annotation instanceof AbstractAnnotation) {
462461 $ message = 'Unexpected ' . $ annotation ->identity ();
463462 if ($ class ::$ _parents ) {
464- $ message .= ', expected to be inside ' . implode (', ' , Util ::shorten ($ class ::$ _parents ));
463+ $ message .= ', expected to be inside ' . implode (', ' , static ::shorten ($ class ::$ _parents ));
465464 }
466465 $ this ->_context ->logger ->warning ($ message . ' in ' . $ annotation ->_context );
467466 }
@@ -481,7 +480,7 @@ public function validate(array $stack = [], array $skip = [], string $ref = '',
481480 $ keyField = $ nested [1 ];
482481 foreach ($ this ->{$ property } as $ key => $ item ) {
483482 if (is_array ($ item ) && is_numeric ($ key ) === false ) {
484- $ this ->_context ->logger ->warning ($ this ->identity () . '-> ' . $ property . ' is an object literal, use nested ' . Util ::shorten ($ annotationClass ) . '() annotation(s) in ' . $ this ->_context );
483+ $ this ->_context ->logger ->warning ($ this ->identity () . '-> ' . $ property . ' is an object literal, use nested ' . static ::shorten ($ annotationClass ) . '() annotation(s) in ' . $ this ->_context );
485484 $ keys [$ key ] = $ item ;
486485 } elseif (Generator::isDefault ($ item ->{$ keyField })) {
487486 $ this ->_context ->logger ->error ($ item ->identity () . ' is missing key-field: " ' . $ keyField . '" in ' . $ item ->_context );
@@ -511,11 +510,11 @@ public function validate(array $stack = [], array $skip = [], string $ref = '',
511510 $ nestedProperty = is_array ($ nested ) ? $ nested [0 ] : $ nested ;
512511 if ($ property === $ nestedProperty ) {
513512 if ($ this instanceof OpenApi) {
514- $ message = 'Required ' . Util ::shorten ($ class ) . '() not found ' ;
513+ $ message = 'Required ' . static ::shorten ($ class ) . '() not found ' ;
515514 } elseif (is_array ($ nested )) {
516- $ message = $ this ->identity () . ' requires at least one ' . Util ::shorten ($ class ) . '() in ' . $ this ->_context ;
515+ $ message = $ this ->identity () . ' requires at least one ' . static ::shorten ($ class ) . '() in ' . $ this ->_context ;
517516 } else {
518- $ message = $ this ->identity () . ' requires a ' . Util ::shorten ($ class ) . '() in ' . $ this ->_context ;
517+ $ message = $ this ->identity () . ' requires a ' . static ::shorten ($ class ) . '() in ' . $ this ->_context ;
519518 }
520519 break ;
521520 }
@@ -675,7 +674,7 @@ protected function _identity(array $properties): string
675674 }
676675 }
677676
678- return Util ::shorten (get_class ($ this )) . '( ' . implode (', ' , $ fields ) . ') ' ;
677+ return static ::shorten (get_class ($ this )) . '( ' . implode (', ' , $ fields ) . ') ' ;
679678 }
680679
681680 /**
@@ -794,4 +793,24 @@ protected function combine(...$args): array
794793
795794 return array_filter ($ combined , fn ($ value ): bool => !Generator::isDefault ($ value ) && $ value !== null );
796795 }
796+
797+ /**
798+ * Shorten class name(s).
799+ *
800+ * @param array|object|string $classes Class(es) to shorten
801+ *
802+ * @return string|string[] One or more shortened class names
803+ */
804+ protected static function shorten ($ classes )
805+ {
806+ $ short = [];
807+ foreach ((array ) $ classes as $ class ) {
808+ $ short [] = '@ ' . str_replace ([
809+ 'OpenApi \\Annotations \\' ,
810+ 'OpenApi \\Attributes \\' ,
811+ ], 'OA \\' , $ class );
812+ }
813+
814+ return is_array ($ classes ) ? $ short : array_pop ($ short );
815+ }
797816}
0 commit comments