File tree 1 file changed +28
-17
lines changed
src/App/Normalizer/Component 1 file changed +28
-17
lines changed Original file line number Diff line number Diff line change 8
8
*/
9
9
class SchemaTypeNormalizer
10
10
{
11
+ /**
12
+ * @private
13
+ * @type array
14
+ */
15
+ const MANAGED_TYPE_LIST = [
16
+ 'array ' => true ,
17
+ 'number ' => true ,
18
+ 'object ' => true ,
19
+ 'string ' => true ,
20
+ 'integer ' => true ,
21
+ 'boolean ' => true ,
22
+ 'null ' => true ,
23
+ ];
24
+ /**
25
+ * @private
26
+ * @type array
27
+ */
28
+ const RENAMED_TYPE_LIST = [
29
+ 'float ' => 'number ' ,
30
+ 'collection ' => 'array ' ,
31
+ ];
11
32
/**
12
33
* @param TypeDoc $doc
13
34
*
14
- * @return mixed| string
35
+ * @return string
15
36
*
16
37
* @throws \ReflectionException
17
38
*/
18
39
public function normalize (TypeDoc $ doc ) : string
19
40
{
20
41
$ type = str_replace ('Doc ' , '' , lcfirst ((new \ReflectionClass ($ doc ))->getShortName ()));
21
- // translate type
22
- switch ($ type ) {
23
- case 'array ' :
24
- case 'number ' :
25
- case 'object ' :
26
- case 'string ' :
27
- case 'integer ' :
28
- case 'boolean ' :
29
- case 'null ' :
30
- return $ type ;
31
- case 'float ' :
32
- return 'number ' ;
33
- case 'collection ' :
34
- return 'array ' ;
35
- default :
36
- return 'string ' ;
42
+ if (array_key_exists ($ type , self ::MANAGED_TYPE_LIST )) {
43
+ return $ type ;
44
+ } elseif (array_key_exists ($ type , self ::RENAMED_TYPE_LIST )) {
45
+ return self ::RENAMED_TYPE_LIST [$ type ];
37
46
}
47
+
48
+ return 'string ' ;
38
49
}
39
50
}
You can’t perform that action at this time.
0 commit comments