UnmappableRelationship   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A encountered() 0 13 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\TableLoader\Loader;
5
6
use RuntimeException;
7
use function sprintf as withMessage;
8
use Throwable;
9
10
/**
11
 * Notifies the client code that the relationship could not be mapped.
12
 *
13
 * @author Stratadox
14
 */
15
final class UnmappableRelationship extends RuntimeException implements CannotLoadTable
16
{
17
    /**
18
     * Produces an exception for when the relationship could not be mapped.
19
     *
20
     * @param Throwable $exception The exception that was encountered.
21
     * @param string    $property  The property of the relationship.
22
     * @param string    $owner     The label of the owning side.
23
     * @param string    $id        The id of the owning side.
24
     * @return CannotLoadTable     The exception to throw.
25
     */
26
    public static function encountered(
27
        Throwable $exception,
28
        string $property,
29
        string $owner,
30
        string $id
31
    ): CannotLoadTable {
32
        return new UnmappableRelationship(withMessage(
33
            'Could not map the `%s` in the `%s` `%s`: %s',
34
            $property,
35
            $owner,
36
            $id,
37
            $exception->getMessage()
38
        ), 0, $exception);
39
    }
40
}
41