ConstraintNotSatisfied   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A with() 0 11 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Hydration\Mapping\Composite;
4
5
use RuntimeException;
6
use Stratadox\HydrationMapping\Mapping;
7
use Stratadox\HydrationMapping\MappingFailure;
8
use Stratadox\Specification\Contract\Satisfiable;
9
use function get_class;
10
use function sprintf;
11
use function var_export;
12
13
final class ConstraintNotSatisfied extends RuntimeException implements MappingFailure
14
{
15
    /**
16
     * Notifies the client that the mapping constraint was not satisfied.
17
     *
18
     * @param mixed       $result
19
     * @param Mapping     $mapping
20
     * @param Satisfiable $constraint
21
     * @return MappingFailure
22
     */
23
    public static function with(
24
        $result,
25
        Mapping $mapping,
26
        Satisfiable $constraint
27
    ): MappingFailure {
28
        return new self(sprintf(
29
            'The %s was refused by the constraint `%s` on property `%s` for the input value %s.',
30
            get_class($mapping),
31
            get_class($constraint),
32
            $mapping->name(),
33
            var_export($result, true)
34
        ));
35
    }
36
}
37