| Total Complexity | 5 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 5 | class Arr |
||
| 6 | { |
||
| 7 | 1 | /** |
|
| 8 | * This method is just handy when it comes to add a class to an existing class string. |
||
| 9 | 1 | */ |
|
| 10 | public static function attachClass(array $array, string $class): array |
||
| 11 | { |
||
| 12 | 2 | return static::attach($array, ['class' => $class]); |
|
| 13 | } |
||
| 14 | 2 | ||
| 15 | 2 | ||
| 16 | 2 | /** |
|
| 17 | * Sometimes just want to add some new attribute to an existing string. |
||
| 18 | */ |
||
| 19 | public static function attach(array $array, array $data): array |
||
| 20 | 2 | { |
|
| 21 | foreach ($data as $key => $value) { |
||
| 22 | $array = array_replace( |
||
| 23 | $array, [$key => array_key_exists($key, $array) ? $array[$key] . ' ' . $value : $value] |
||
| 24 | ); |
||
| 25 | } |
||
| 26 | |||
| 27 | return $array; |
||
| 28 | } |
||
| 29 | |||
| 30 | 1 | /** |
|
| 31 | * Returns the first value of a given array. |
||
| 32 | 1 | * If the array is empty it returns null. |
|
| 33 | */ |
||
| 34 | public static function firstValue(array $array): mixed |
||
| 37 | } |
||
| 38 | } |