HydrationFailed   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A encountered() 0 9 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\Hydrator;
5
6
use function get_class;
7
use RuntimeException;
8
use function sprintf;
9
use Throwable;
10
11
/**
12
 * Notifies the client code that the hydration of an object failed.
13
 *
14
 * @author  Stratadox
15
 */
16
final class HydrationFailed extends RuntimeException implements HydrationFailure
17
{
18
    /**
19
     * Notifies the client code that an exception was encountered during the
20
     * hydration process.
21
     *
22
     * @param Throwable $exception The exception that was thrown.
23
     * @param object    $target    The object that was being hydrated.
24
     * @return HydrationFailure    The exception to throw.
25
     */
26
    public static function encountered(
27
        Throwable $exception,
28
        object $target
29
    ): HydrationFailure {
30
        return new self(sprintf(
31
            'Could not hydrate the `%s`: %s',
32
            get_class($target),
33
            $exception->getMessage()
34
        ), 0, $exception);
35
    }
36
}
37