GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( e25774...cbbeec )
by Cees-Jan
04:38 queued 59s
created

validate_array()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 8
nc 4
nop 3
dl 0
loc 18
ccs 7
cts 7
cp 1
crap 5
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace WyriHaximus;
4
5
function validate_array(array $data, array $fields, string $exception = null): bool
6
{
7 3
    foreach ($fields as $field) {
8
        if (
9 3
            !isset($data[$field]) && // This is faster,
10
                                     // but it will also return false on fields which
11
                                     // value is null, so calling array_key_exists when that happens.
12 3
            !array_key_exists($field, $data)
13
        ) {
14 2
            if ($exception === null) {
15 1
                return false;
16
            }
17
18 2
            throw new $exception($data, $field);
19
        }
20
    }
21
22 1
    return true;
23
}
24