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

HydrationFailed::encountered()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Stratadox\Hydrator;
6
7
use ReflectionClass;
8
use RuntimeException;
9
use function sprintf;
10
use Throwable;
11
12
/**
13
 * Notifies the client code that the hydration of an object failed.
14
 *
15
 * @package Stratadox\Hydrate
16
 * @author Stratadox
17
 */
18
final class HydrationFailed extends RuntimeException implements CouldNotHydrate
19
{
20
    /**
21
     * Notifies the client code that an exception was encountered during the
22
     * hydration process.
23
     *
24
     * @param Throwable       $exception The exception that was thrown.
25
     * @param ReflectionClass $class     The class that was being hydrated.
26
     * @return self                      The new exception to throw.
27
     */
28
    public static function encountered(
29
        Throwable $exception,
30
        ReflectionClass $class
31
    ) : self
32
    {
33
        return new self(
34
            sprintf('Could not load the class `%s`: %s',
35
                $class->getName(),
36
                $exception->getMessage()
37
            ),
38
            0,
39
            $exception
40
        );
41
    }
42
}
43