Assert   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
eloc 5
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A requireFields() 0 8 2
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