Passed
Pull Request — master (#111)
by David
03:01
created

SafeFunctions   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 4
dl 0
loc 16
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A arrayCombine() 0 7 2
1
<?php
2
3
4
namespace TheCodingMachine\TDBM;
5
6
7
use function array_combine;
8
use function error_get_last;
9
use RuntimeException;
10
11
class SafeFunctions
12
{
13
    /**
14
     * A wrapper around array_combine that never returns false.
15
     *
16
     * @param array<int|string> $keys
17
     * @param mixed[] $values
18
     * @return mixed[]
19
     */
20
    public static function arrayCombine(array $keys, array $values): array
21
    {
22
        $array = array_combine($keys, $values);
23
        if ($array === false) {
24
            throw new RuntimeException(error_get_last()['message']);
25
        }
26
        return $array;
27
    }
28
}