Completed
Push — master ( 9d457f...574e8f )
by Jesse
02:48
created

CannotDecideOnAHydrator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A withThis() 0 5 1
A without() 0 5 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Stratadox\Hydrator;
6
7
use InvalidArgumentException;
8
9
/**
10
 * Notifies the client code that the class decision could not be made.
11
 *
12
 * @package Stratadox\Hydrate
13
 * @author Stratadox
14
 */
15
final class CannotDecideOnAHydrator extends InvalidArgumentException implements CouldNotHydrate
16
{
17
    /**
18
     * Notifies the client code that the decision key found in the input data is
19
     * not a key that was registered with the class mapping.
20
     *
21
     * @param string $hydratorKey The key that was found in the input data.
22
     * @return self               The exception object.
23
     */
24
    public static function withThis(string $hydratorKey) : self
25
    {
26
        return new self(sprintf(
27
            'Invalid class decision key: `%s`.',
28
            $hydratorKey
29
        ));
30
    }
31
32
    /**
33
     * Notifies the client code that the field in which the decision key was
34
     * expected, does not exist in the input data.
35
     *
36
     * @param string $decisionKey The key that should contain the decision key.
37
     * @return self               The exception object.
38
     */
39
    public static function without(string $decisionKey) : self
40
    {
41
        return new self(sprintf(
42
            'Missing class decision key: `%s`.',
43
            $decisionKey
44
        ));
45
    }
46
}
47