@@ -237,7 +237,7 @@ public function mergeProperties($object): void
237237 if (Generator::isDefault ($ value )) {
238238 continue ;
239239 }
240- $ identity = method_exists ($ object , 'identity ' ) ? $ object ->identity () : get_class ( $ object) ;
240+ $ identity = method_exists ($ object , 'identity ' ) ? $ object ->identity () : $ object::class ;
241241 $ context1 = $ this ->_context ;
242242 $ context2 = property_exists ($ object , '_context ' ) ? $ object ->_context : 'unknown ' ;
243243 if ($ this ->{$ property } instanceof AbstractAnnotation) {
@@ -449,13 +449,13 @@ public function validate(array $stack = [], array $skip = [], string $ref = '',
449449 }
450450
451451 /** @var class-string<AbstractAnnotation> $class */
452- $ class = get_class ( $ annotation) ;
452+ $ class = $ annotation::class ;
453453 if ($ details = $ this ->matchNested ($ annotation )) {
454454 $ property = $ details ->value ;
455455 if (is_array ($ property )) {
456- $ this ->_context ->logger ->warning ('Only one ' . static ::shorten (get_class ( $ annotation) ) . '() allowed for ' . $ this ->identity () . ' multiple found, skipped: ' . $ annotation ->_context );
456+ $ this ->_context ->logger ->warning ('Only one ' . static ::shorten ($ annotation::class ) . '() allowed for ' . $ this ->identity () . ' multiple found, skipped: ' . $ annotation ->_context );
457457 } else {
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 );
458+ $ 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 );
459459 }
460460 } elseif ($ annotation instanceof AbstractAnnotation) {
461461 $ message = 'Unexpected ' . $ annotation ->identity ();
@@ -493,7 +493,7 @@ public function validate(array $stack = [], array $skip = [], string $ref = '',
493493 }
494494
495495 if (property_exists ($ this , 'ref ' ) && !Generator::isDefault ($ this ->ref ) && is_string ($ this ->ref )) {
496- if (substr ($ this ->ref , 0 , 2 ) === '#/ ' && $ stack !== [] && $ stack [0 ] instanceof OpenApi) {
496+ if (str_starts_with ($ this ->ref , '#/ ' ) && $ stack !== [] && $ stack [0 ] instanceof OpenApi) {
497497 // Internal reference
498498 try {
499499 $ stack [0 ]->ref ($ this ->ref );
@@ -540,7 +540,7 @@ public function validate(array $stack = [], array $skip = [], string $ref = '',
540540 $ this ->_context ->logger ->warning ($ this ->identity () . '-> ' . $ property . ' " ' . $ value . '" is invalid, expecting " ' . implode ('", " ' , $ type ) . '" in ' . $ this ->_context );
541541 }
542542 } else {
543- throw new OpenApiException ('Invalid ' . get_class ( $ this ) . '::$_types[ ' . $ property . '] ' );
543+ throw new OpenApiException ('Invalid ' . static ::class . '::$_types[ ' . $ property . '] ' );
544544 }
545545 }
546546 $ stack [] = $ this ;
@@ -599,7 +599,7 @@ private static function _validate($fields, array $stack, array $skip, string $ba
599599 */
600600 public function identity (): string
601601 {
602- $ class = get_class ( $ this ) ;
602+ $ class = static ::class ;
603603 $ properties = [];
604604 /** @var class-string<AbstractAnnotation> $parent */
605605 foreach (static ::$ _parents as $ parent ) {
@@ -640,10 +640,10 @@ public function matchNested($other)
640640 */
641641 public function getRoot (): string
642642 {
643- $ class = get_class ( $ this ) ;
643+ $ class = static ::class ;
644644
645645 do {
646- if (0 === strpos ($ class , 'OpenApi \\Annotations \\' )) {
646+ if (str_starts_with ($ class , 'OpenApi \\Annotations \\' )) {
647647 break ;
648648 }
649649 } while ($ class = get_parent_class ($ class ));
@@ -658,7 +658,7 @@ public function getRoot(): string
658658 */
659659 public function isRoot (string $ rootClass ): bool
660660 {
661- return get_class ( $ this ) === $ rootClass || $ this ->getRoot () === $ rootClass ;
661+ return static ::class === $ rootClass || $ this ->getRoot () === $ rootClass ;
662662 }
663663
664664 /**
@@ -674,7 +674,7 @@ protected function _identity(array $properties): string
674674 }
675675 }
676676
677- return static ::shorten (get_class ( $ this ) ) . '( ' . implode (', ' , $ fields ) . ') ' ;
677+ return static ::shorten (static ::class ) . '( ' . implode (', ' , $ fields ) . ') ' ;
678678 }
679679
680680 /**
@@ -685,7 +685,7 @@ protected function _identity(array $properties): string
685685 */
686686 private function validateType (string $ type , $ value ): bool
687687 {
688- if (substr ($ type , 0 , 1 ) === '[ ' && substr ($ type , - 1 ) === '] ' ) { // Array of a specified type?
688+ if (str_starts_with ($ type , '[ ' ) && str_ends_with ($ type , '] ' ) ) { // Array of a specified type?
689689 if ($ this ->validateType ('array ' , $ value ) === false ) {
690690 return false ;
691691 }
@@ -725,24 +725,16 @@ private function validateDefaultTypes(string $type, $value): bool
725725 return false ;
726726 }
727727
728- switch ($ type ) {
729- case 'string ' :
730- return is_string ($ value );
731- case 'boolean ' :
732- return is_bool ($ value );
733- case 'integer ' :
734- return is_int ($ value );
735- case 'number ' :
736- return is_numeric ($ value );
737- case 'object ' :
738- return is_object ($ value );
739- case 'array ' :
740- return $ this ->validateArrayType ($ value );
741- case 'scheme ' :
742- return in_array ($ value , ['http ' , 'https ' , 'ws ' , 'wss ' ], true );
743- default :
744- throw new OpenApiException ('Invalid type " ' . $ type . '" ' );
745- }
728+ return match ($ type ) {
729+ 'string ' => is_string ($ value ),
730+ 'boolean ' => is_bool ($ value ),
731+ 'integer ' => is_int ($ value ),
732+ 'number ' => is_numeric ($ value ),
733+ 'object ' => is_object ($ value ),
734+ 'array ' => $ this ->validateArrayType ($ value ),
735+ 'scheme ' => in_array ($ value , ['http ' , 'https ' , 'ws ' , 'wss ' ], true ),
736+ default => throw new OpenApiException ('Invalid type " ' . $ type . '" ' ),
737+ };
746738 }
747739
748740 /**
0 commit comments