@@ -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) {
@@ -448,14 +448,13 @@ public function validate(array $stack = [], array $skip = [], string $ref = '',
448448 break ;
449449 }
450450
451- /** @var class-string<AbstractAnnotation> $class */
452- $ class = get_class ($ annotation );
451+ $ class = $ annotation ::class;
453452 if ($ details = $ this ->matchNested ($ annotation )) {
454453 $ property = $ details ->value ;
455454 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 );
455+ $ this ->_context ->logger ->warning ('Only one ' . static ::shorten ($ annotation::class ) . '() allowed for ' . $ this ->identity () . ' multiple found, skipped: ' . $ annotation ->_context );
457456 } 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 );
457+ $ 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 );
459458 }
460459 } elseif ($ annotation instanceof AbstractAnnotation) {
461460 $ message = 'Unexpected ' . $ annotation ->identity ();
@@ -493,7 +492,7 @@ public function validate(array $stack = [], array $skip = [], string $ref = '',
493492 }
494493
495494 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) {
495+ if (str_starts_with ($ this ->ref , '#/ ' ) && $ stack !== [] && $ stack [0 ] instanceof OpenApi) {
497496 // Internal reference
498497 try {
499498 $ stack [0 ]->ref ($ this ->ref );
@@ -540,7 +539,7 @@ public function validate(array $stack = [], array $skip = [], string $ref = '',
540539 $ this ->_context ->logger ->warning ($ this ->identity () . '-> ' . $ property . ' " ' . $ value . '" is invalid, expecting " ' . implode ('", " ' , $ type ) . '" in ' . $ this ->_context );
541540 }
542541 } else {
543- throw new OpenApiException ('Invalid ' . get_class ( $ this ) . '::$_types[ ' . $ property . '] ' );
542+ throw new OpenApiException ('Invalid ' . static ::class . '::$_types[ ' . $ property . '] ' );
544543 }
545544 }
546545 $ stack [] = $ this ;
@@ -599,7 +598,7 @@ private static function _validate($fields, array $stack, array $skip, string $ba
599598 */
600599 public function identity (): string
601600 {
602- $ class = get_class ( $ this ) ;
601+ $ class = static ::class ;
603602 $ properties = [];
604603 /** @var class-string<AbstractAnnotation> $parent */
605604 foreach (static ::$ _parents as $ parent ) {
@@ -640,10 +639,10 @@ public function matchNested($other)
640639 */
641640 public function getRoot (): string
642641 {
643- $ class = get_class ( $ this ) ;
642+ $ class = static ::class ;
644643
645644 do {
646- if (0 === strpos ($ class , 'OpenApi \\Annotations \\' )) {
645+ if (str_starts_with ($ class , 'OpenApi \\Annotations \\' )) {
647646 break ;
648647 }
649648 } while ($ class = get_parent_class ($ class ));
@@ -658,7 +657,7 @@ public function getRoot(): string
658657 */
659658 public function isRoot (string $ rootClass ): bool
660659 {
661- return get_class ( $ this ) === $ rootClass || $ this ->getRoot () === $ rootClass ;
660+ return static ::class === $ rootClass || $ this ->getRoot () === $ rootClass ;
662661 }
663662
664663 /**
@@ -674,7 +673,7 @@ protected function _identity(array $properties): string
674673 }
675674 }
676675
677- return static ::shorten (get_class ( $ this ) ) . '( ' . implode (', ' , $ fields ) . ') ' ;
676+ return static ::shorten (static ::class ) . '( ' . implode (', ' , $ fields ) . ') ' ;
678677 }
679678
680679 /**
@@ -685,7 +684,7 @@ protected function _identity(array $properties): string
685684 */
686685 private function validateType (string $ type , $ value ): bool
687686 {
688- if (substr ($ type , 0 , 1 ) === '[ ' && substr ($ type , - 1 ) === '] ' ) { // Array of a specified type?
687+ if (str_starts_with ($ type , '[ ' ) && str_ends_with ($ type , '] ' ) ) { // Array of a specified type?
689688 if ($ this ->validateType ('array ' , $ value ) === false ) {
690689 return false ;
691690 }
@@ -725,24 +724,16 @@ private function validateDefaultTypes(string $type, $value): bool
725724 return false ;
726725 }
727726
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- }
727+ return match ($ type ) {
728+ 'string ' => is_string ($ value ),
729+ 'boolean ' => is_bool ($ value ),
730+ 'integer ' => is_int ($ value ),
731+ 'number ' => is_numeric ($ value ),
732+ 'object ' => is_object ($ value ),
733+ 'array ' => $ this ->validateArrayType ($ value ),
734+ 'scheme ' => in_array ($ value , ['http ' , 'https ' , 'ws ' , 'wss ' ], true ),
735+ default => throw new OpenApiException ('Invalid type " ' . $ type . '" ' ),
736+ };
746737 }
747738
748739 /**
0 commit comments