Completed
Pull Request — master (#4)
by Jakub
03:36
created

Assert::requireFields()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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