Completed
Push — master ( e0b963...10913a )
by Jesse
02:36
created

UnsatisfiedConstraint::itIsNotConsideredValid()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 2
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\Hydration\Mapping\Property;
5
6
use function get_class;
7
use function is_object;
8
use function sprintf;
9
use InvalidArgumentException as InvalidArgument;
10
use Stratadox\HydrationMapping\MapsProperty;
11
use Stratadox\HydrationMapping\UnmappableInput;
12
13
/**
14
 * Notifies the client code when the input is not accepted by the constraint.
15
 *
16
 * @package Stratadox\Hydrate
17
 * @author  Stratadox
18
 */
19
final class UnsatisfiedConstraint extends InvalidArgument implements UnmappableInput
20
{
21
    /**
22
     * Notifies the client code when the input is not accepted by the constraint.
23
     *
24
     * @param MapsProperty $property
25
     * @param              $value
26
     * @return UnsatisfiedConstraint The exception to throw.
27
     */
28
    public static function itIsNotConsideredValid(
29
        MapsProperty $property,
30
        $value
31
    ): self {
32
        if (is_object($value)) {
33
            return new self(sprintf(
34
                'Cannot assign the `%s` to property `%s`: ' .
35
                'The value did not satisfy the specifications.',
36
                get_class($value),
37
                $property->name()
38
            ));
39
        }
40
        return new self(sprintf(
41
            'Cannot assign `%s` to property `%s`: ' .
42
            'The value did not satisfy the specifications.',
43
            $value,
44
            $property->name()
45
        ));
46
    }
47
}
48