| Total Complexity | 5 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 23 | class ModelParams |
||
| 24 | { |
||
| 25 | 42 | public static function getType($type) |
|
| 26 | { |
||
| 27 | 42 | $string_pattern = static::getStringPattern(); |
|
| 28 | 42 | $int_pattern = '/.*int(?:eger)?\(\d+\).*/i'; |
|
| 29 | $float_pattern = '/(?:dec(?:imal)?' |
||
| 30 | . '|float' |
||
| 31 | . '|real' |
||
| 32 | . '|double' |
||
| 33 | 42 | . ')/i'; |
|
| 34 | |||
| 35 | switch (1) { |
||
| 36 | 42 | case preg_match($string_pattern, $type): |
|
| 37 | 20 | $result = 'string'; |
|
| 38 | 20 | break; |
|
| 39 | 22 | case preg_match($int_pattern, $type): |
|
| 40 | 10 | $result = 'int'; |
|
| 41 | 10 | break; |
|
| 42 | 12 | case preg_match($float_pattern, $type): |
|
| 43 | 10 | $result = 'float'; |
|
| 44 | 10 | break; |
|
| 45 | default: |
||
| 46 | 2 | throw new \RuntimeException('Unknown data type'); |
|
| 47 | } |
||
| 48 | |||
| 49 | 40 | return $result; |
|
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Get string pattern |
||
| 54 | * |
||
| 55 | * @return string |
||
| 56 | */ |
||
| 57 | 40 | protected static function getStringPattern() |
|
| 66 | } |
||
| 67 | } |
||
| 68 |