| Conditions | 9 |
| Paths | 8 |
| Total Lines | 23 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 4 |
| CRAP Score | 9.648 |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | 1 | public function parse($type, $value) |
|
| 21 | { |
||
| 22 | switch ($type) { |
||
| 23 | case ATTR_TYPE::INTEGER: |
||
| 24 | return (int) $value; |
||
| 25 | case ATTR_TYPE::STRING: |
||
| 26 | case ATTR_TYPE::TEXT: |
||
| 27 | 1 | case ATTR_TYPE::MANUAL: |
|
| 28 | return $value; |
||
| 29 | 1 | case ATTR_TYPE::DATETIME: |
|
| 30 | return (new DateTime($value))->format('Y-m-d H:i:s'); |
||
| 31 | 1 | case ATTR_TYPE::DECIMAL: |
|
| 32 | $valueStr = (string)$value; |
||
| 33 | // Find the position of the decimal point |
||
| 34 | $decimalPos = strpos($valueStr, '.'); |
||
| 35 | // If there is a decimal point and more than 6 decimals |
||
| 36 | if ($decimalPos !== false && strlen($valueStr) > $decimalPos + 7) { |
||
| 37 | // Cut the value after 6 decimals |
||
| 38 | $valueStr = substr($valueStr, 0, $decimalPos + 7); |
||
| 39 | } |
||
| 40 | return rtrim(rtrim($valueStr, '0'), '.'); |
||
| 41 | default: |
||
| 42 | throw new InvalidArgumentException("Unknown attribute type: " . $type); |
||
| 43 | } |
||
| 45 | } |