Skip to content

Commit 46b20d9

Browse files
authoredApr 20, 2019
v0.1.2
2 parents f0f7fac + 16013a3 commit 46b20d9

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed
 

‎src/App/Normalizer/Component/SchemaTypeNormalizer.php

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,43 @@
88
*/
99
class SchemaTypeNormalizer
1010
{
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+
];
1132
/**
1233
* @param TypeDoc $doc
1334
*
14-
* @return mixed|string
35+
* @return string
1536
*
1637
* @throws \ReflectionException
1738
*/
1839
public function normalize(TypeDoc $doc) : string
1940
{
2041
$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];
3746
}
47+
48+
return 'string';
3849
}
3950
}

0 commit comments

Comments
 (0)
Please sign in to comment.