@@ -238,7 +238,7 @@ public function mergeProperties($object): void
238238 if (Generator::isDefault ($ value )) {
239239 continue ;
240240 }
241- $ identity = method_exists ($ object , 'identity ' ) ? $ object ->identity () : get_class ( $ object) ;
241+ $ identity = method_exists ($ object , 'identity ' ) ? $ object ->identity () : $ object::class ;
242242 $ context1 = $ this ->_context ;
243243 $ context2 = property_exists ($ object , '_context ' ) ? $ object ->_context : 'unknown ' ;
244244 if ($ this ->{$ property } instanceof AbstractAnnotation) {
@@ -460,14 +460,13 @@ public function validate(array $stack = [], array $skip = [], string $ref = '',
460460 break ;
461461 }
462462
463- /** @var class-string<AbstractAnnotation> $class */
464- $ class = get_class ($ annotation );
463+ $ class = $ annotation ::class;
465464 if ($ details = $ this ->matchNested ($ annotation )) {
466465 $ property = $ details ->value ;
467466 if (is_array ($ property )) {
468- $ this ->_context ->logger ->warning ('Only one ' . static ::shorten (get_class ( $ annotation) ) . '() allowed for ' . $ this ->identity () . ' multiple found, skipped: ' . $ annotation ->_context );
467+ $ this ->_context ->logger ->warning ('Only one ' . static ::shorten ($ annotation::class ) . '() allowed for ' . $ this ->identity () . ' multiple found, skipped: ' . $ annotation ->_context );
469468 } else {
470- $ 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 );
469+ $ this ->_context ->logger ->warning ('Only one ' . static ::shorten ($ annotation::class ) . '() allowed for ' . $ this ->identity () . " multiple found in: \n Using: " . $ this ->{$ property }->_context . "\n Skipped: " . $ annotation ->_context );
471470 }
472471 } elseif ($ annotation instanceof AbstractAnnotation) {
473472 $ message = 'Unexpected ' . $ annotation ->identity ();
@@ -505,7 +504,7 @@ public function validate(array $stack = [], array $skip = [], string $ref = '',
505504 }
506505
507506 if (property_exists ($ this , 'ref ' ) && !Generator::isDefault ($ this ->ref ) && is_string ($ this ->ref )) {
508- if (substr ($ this ->ref , 0 , 2 ) === '#/ ' && $ stack !== [] && $ stack [0 ] instanceof OpenApi) {
507+ if (str_starts_with ($ this ->ref , '#/ ' ) && $ stack !== [] && $ stack [0 ] instanceof OpenApi) {
509508 // Internal reference
510509 try {
511510 $ stack [0 ]->ref ($ this ->ref );
@@ -552,7 +551,7 @@ public function validate(array $stack = [], array $skip = [], string $ref = '',
552551 $ this ->_context ->logger ->warning ($ this ->identity () . '-> ' . $ property . ' " ' . $ value . '" is invalid, expecting " ' . implode ('", " ' , $ type ) . '" in ' . $ this ->_context );
553552 }
554553 } else {
555- throw new OpenApiException ('Invalid ' . get_class ( $ this ) . '::$_types[ ' . $ property . '] ' );
554+ throw new OpenApiException ('Invalid ' . static ::class . '::$_types[ ' . $ property . '] ' );
556555 }
557556 }
558557 $ stack [] = $ this ;
@@ -611,7 +610,7 @@ private static function _validate($fields, array $stack, array $skip, string $ba
611610 */
612611 public function identity (): string
613612 {
614- $ class = get_class ( $ this ) ;
613+ $ class = static ::class ;
615614 $ properties = [];
616615 /** @var class-string<AbstractAnnotation> $parent */
617616 foreach (static ::$ _parents as $ parent ) {
@@ -652,10 +651,10 @@ public function matchNested($other)
652651 */
653652 public function getRoot (): string
654653 {
655- $ class = get_class ( $ this ) ;
654+ $ class = static ::class ;
656655
657656 do {
658- if (0 === strpos ($ class , 'OpenApi \\Annotations \\' )) {
657+ if (str_starts_with ($ class , 'OpenApi \\Annotations \\' )) {
659658 break ;
660659 }
661660 } while ($ class = get_parent_class ($ class ));
@@ -670,7 +669,7 @@ public function getRoot(): string
670669 */
671670 public function isRoot (string $ rootClass ): bool
672671 {
673- return get_class ( $ this ) === $ rootClass || $ this ->getRoot () === $ rootClass ;
672+ return static ::class === $ rootClass || $ this ->getRoot () === $ rootClass ;
674673 }
675674
676675 /**
@@ -686,7 +685,7 @@ protected function _identity(array $properties): string
686685 }
687686 }
688687
689- return static ::shorten (get_class ( $ this ) ) . '( ' . implode (', ' , $ fields ) . ') ' ;
688+ return static ::shorten (static ::class ) . '( ' . implode (', ' , $ fields ) . ') ' ;
690689 }
691690
692691 /**
@@ -697,7 +696,7 @@ protected function _identity(array $properties): string
697696 */
698697 private function validateType (string $ type , $ value ): bool
699698 {
700- if (substr ($ type , 0 , 1 ) === '[ ' && substr ($ type , - 1 ) === '] ' ) { // Array of a specified type?
699+ if (str_starts_with ($ type , '[ ' ) && str_ends_with ($ type , '] ' ) ) { // Array of a specified type?
701700 if ($ this ->validateType ('array ' , $ value ) === false ) {
702701 return false ;
703702 }
@@ -737,24 +736,16 @@ private function validateDefaultTypes(string $type, $value): bool
737736 return false ;
738737 }
739738
740- switch ($ type ) {
741- case 'string ' :
742- return is_string ($ value );
743- case 'boolean ' :
744- return is_bool ($ value );
745- case 'integer ' :
746- return is_int ($ value );
747- case 'number ' :
748- return is_numeric ($ value );
749- case 'object ' :
750- return is_object ($ value );
751- case 'array ' :
752- return $ this ->validateArrayType ($ value );
753- case 'scheme ' :
754- return in_array ($ value , ['http ' , 'https ' , 'ws ' , 'wss ' ], true );
755- default :
756- throw new OpenApiException ('Invalid type " ' . $ type . '" ' );
757- }
739+ return match ($ type ) {
740+ 'string ' => is_string ($ value ),
741+ 'boolean ' => is_bool ($ value ),
742+ 'integer ' => is_int ($ value ),
743+ 'number ' => is_numeric ($ value ),
744+ 'object ' => is_object ($ value ),
745+ 'array ' => $ this ->validateArrayType ($ value ),
746+ 'scheme ' => in_array ($ value , ['http ' , 'https ' , 'ws ' , 'wss ' ], true ),
747+ default => throw new OpenApiException ('Invalid type " ' . $ type . '" ' ),
748+ };
758749 }
759750
760751 /**
0 commit comments