@@ -34,44 +34,46 @@ public static function convertToJsonSchema(array $shorthand): array
3434 if (! \is_string ($ property ) || empty ($ property )) {
3535 throw InvalidShorthand::emptyString ($ shorthand );
3636 }
37-
3837 $ schemaProperty = $ property ;
3938
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+ }
4647
47- if (! \is_string ($ shorthandDefinition )) {
48- throw InvalidShorthand::refNotString ($ shorthand );
49- }
48+ if (! \is_string ($ shorthandDefinition )) {
49+ throw InvalidShorthand::refNotString ($ shorthand );
50+ }
5051
51- $ shorthandDefinition = \str_replace ('#/definitions/ ' , '' , $ shorthandDefinition );
52+ $ shorthandDefinition = \str_replace ('#/definitions/ ' , '' , $ shorthandDefinition );
5253
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+ }
6061
61- if (! \is_string ($ shorthandDefinition )) {
62- throw InvalidShorthand::itemsNotString ($ shorthand );
63- }
62+ if (! \is_string ($ shorthandDefinition )) {
63+ throw InvalidShorthand::itemsNotString ($ shorthand );
64+ }
6465
65- if (\mb_substr ($ shorthandDefinition , -2 ) !== '[] ' ) {
66- $ shorthandDefinition .= '[] ' ;
67- }
66+ if (\mb_substr ($ shorthandDefinition , -2 ) !== '[] ' ) {
67+ $ shorthandDefinition .= '[] ' ;
68+ }
6869
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 ;
7577 }
7678
7779 if (\is_array ($ shorthandDefinition )) {
0 commit comments