Arr   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
c 2
b 0
f 0
dl 0
loc 32
ccs 9
cts 9
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A firstValue() 0 3 1
A attachClass() 0 3 1
A attach() 0 9 3
1
<?php
2
3
namespace Braunstetter\Helper;
4
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
35
    {
36
        return array_values($array)[0] ?? null;
37
    }
38
}