@@ -34,44 +34,46 @@ public static function convertToJsonSchema(array $shorthand): array
34
34
if (! \is_string ($ property ) || empty ($ property )) {
35
35
throw InvalidShorthand::emptyString ($ shorthand );
36
36
}
37
-
38
37
$ schemaProperty = $ property ;
39
38
40
- if (\mb_substr ($ property , -1 ) === '? ' ) {
41
- $ schemaProperty = \mb_substr ($ property , 0 , -1 );
42
- } elseif ($ schemaProperty === '$ref ' ) {
43
- if (\count ($ shorthand ) > 1 ) {
44
- throw InvalidShorthand::refWithOtherProperties ($ shorthand );
45
- }
39
+ switch (true ) {
40
+ case \mb_substr ($ property , -1 ) === '? ' :
41
+ $ schemaProperty = \mb_substr ($ property , 0 , -1 );
42
+ break ;
43
+ case $ schemaProperty === '$ref ' :
44
+ if (\count ($ shorthand ) > 1 ) {
45
+ throw InvalidShorthand::refWithOtherProperties ($ shorthand );
46
+ }
46
47
47
- if (! \is_string ($ shorthandDefinition )) {
48
- throw InvalidShorthand::refNotString ($ shorthand );
49
- }
48
+ if (! \is_string ($ shorthandDefinition )) {
49
+ throw InvalidShorthand::refNotString ($ shorthand );
50
+ }
50
51
51
- $ shorthandDefinition = \str_replace ('#/definitions/ ' , '' , $ shorthandDefinition );
52
+ $ shorthandDefinition = \str_replace ('#/definitions/ ' , '' , $ shorthandDefinition );
52
53
53
- return [
54
- '$ref ' => "#/definitions/ $ shorthandDefinition " ,
55
- ];
56
- } elseif ( $ schemaProperty === '$items ' ) {
57
- if (\count ($ shorthand ) > 1 ) {
58
- throw InvalidShorthand::itemsWithOtherProperties ($ shorthand );
59
- }
54
+ return [
55
+ '$ref ' => "#/definitions/ $ shorthandDefinition " ,
56
+ ];
57
+ case $ schemaProperty === '$items ' :
58
+ if (\count ($ shorthand ) > 1 ) {
59
+ throw InvalidShorthand::itemsWithOtherProperties ($ shorthand );
60
+ }
60
61
61
- if (! \is_string ($ shorthandDefinition )) {
62
- throw InvalidShorthand::itemsNotString ($ shorthand );
63
- }
62
+ if (! \is_string ($ shorthandDefinition )) {
63
+ throw InvalidShorthand::itemsNotString ($ shorthand );
64
+ }
64
65
65
- if (\mb_substr ($ shorthandDefinition , -2 ) !== '[] ' ) {
66
- $ shorthandDefinition .= '[] ' ;
67
- }
66
+ if (\mb_substr ($ shorthandDefinition , -2 ) !== '[] ' ) {
67
+ $ shorthandDefinition .= '[] ' ;
68
+ }
68
69
69
- return self ::convertShorthandStringToJsonSchema ($ shorthandDefinition );
70
- } elseif ($ schemaProperty === '$title ' ) {
71
- $ schema ['title ' ] = $ shorthandDefinition ;
72
- continue ;
73
- } else {
74
- $ schema ['required ' ][] = $ schemaProperty ;
70
+ return self ::convertShorthandStringToJsonSchema ($ shorthandDefinition );
71
+ case $ schemaProperty === '$title ' :
72
+ $ schema ['title ' ] = $ shorthandDefinition ;
73
+ continue 2 ;
74
+ default :
75
+ $ schema ['required ' ][] = $ schemaProperty ;
76
+ break ;
75
77
}
76
78
77
79
if (\is_array ($ shorthandDefinition )) {
0 commit comments