AssertKey::exists()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 4
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Hydration\Mapping;
4
5
use Stratadox\HydrationMapping\Mapping;
6
use Stratadox\HydrationMapping\MappingFailure;
7
use function array_key_exists;
8
9
// In php, functions cannot be auto-loaded, hence the static class wrapping
10
final class AssertKey
11
{
12
    /** @throws MappingFailure */
13
    public static function exists(Mapping $mapping, array $data, string $key): void
14
    {
15
        if (!array_key_exists($key, $data)) {
16
            throw MissingTheKey::inTheInput($data, $mapping, $key);
17
        }
18
    }
19
}
20