| Total Complexity | 4 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 28 | trait ParsesAttributes |
||
| 29 | {
|
||
| 30 | |||
| 31 | /** |
||
| 32 | * Convert camelCase to snake_case |
||
| 33 | * |
||
| 34 | * @param string $key |
||
| 35 | * |
||
| 36 | * @return string |
||
| 37 | */ |
||
| 38 | public function fromCamelToSnake($key) |
||
| 39 | {
|
||
| 40 | preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $key, $matches);
|
||
| 41 | $ret = $matches[0]; |
||
| 42 | foreach ($ret as &$match) {
|
||
| 43 | $match = $match == strtoupper($match) ? strtolower($match) : lcfirst($match); |
||
| 44 | } |
||
| 45 | return implode('_', $ret);
|
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Convert snake_case to camelCase |
||
| 50 | * |
||
| 51 | * @param string $key |
||
| 52 | * |
||
| 53 | * @return mixed |
||
| 54 | */ |
||
| 55 | public function fromSnakeToCamel($key) |
||
| 60 | } |
||
| 61 | |||
| 62 | } |