MissingTheKey   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 22
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A inTheInput() 0 12 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\Hydration\Mapping;
5
6
use InvalidArgumentException;
7
use Stratadox\HydrationMapping\Mapping;
8
use Stratadox\HydrationMapping\MappingFailure;
9
use function get_class;
10
use function json_encode;
11
use function sprintf;
12
13
/**
14
 * Notifies the client code when the input key was not found.
15
 *
16
 * @author Stratadox
17
 */
18
final class MissingTheKey extends InvalidArgumentException implements MappingFailure
19
{
20
    /**
21
     * Notifies the client code about a missing input key.
22
     *
23
     * @param array    $data    The data that was provided.
24
     * @param Mapping  $mapping The mapping that was expecting a key.
25
     * @param string   $key     The key that was expected.
26
     * @return MappingFailure   The exception to throw.
27
     */
28
    public static function inTheInput(
29
        array $data,
30
        Mapping $mapping,
31
        string $key
32
    ): MappingFailure {
33
        return new self(sprintf(
34
            'Missing the key `%s` for property `%s` in the input data: %s; ' .
35
            'Mapper: %s',
36
            $key,
37
            $mapping->name(),
38
            json_encode($data),
39
            get_class($mapping)
40
        ));
41
    }
42
}
43