Assert::requireFields()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 2
rs 10
c 0
b 0
f 0
eloc 4
nc 2
nop 3
1
<?php declare(strict_types=1);
2
3
namespace Zalas\Toolbox\Json\Factory;
4
5
final class Assert
6
{
7 48
    public static function requireFields(array $fields, array $data, string $type): void
8
    {
9 48
        $missingFields = \array_filter($fields, function (string $field) use ($data) {
10 48
            return !isset($data[$field]);
11 48
        });
12
13 48
        if (!empty($missingFields)) {
14 21
            throw new \InvalidArgumentException(\sprintf('Missing fields "%s" in the %s: `%s`.', \implode(', ', $missingFields), $type, \json_encode($data)));
15
        }
16
    }
17
}
18