UnmappableRow::encountered()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 3
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\TableLoader\Loader;
5
6
use InvalidArgumentException as InvalidArgument;
7
use function json_encode as encodeAsJson;
8
use function sprintf as withMessage;
9
use Throwable;
10
11
/**
12
 * Notifies the client code that the row could not be mapped.
13
 *
14
 * @author Stratadox
15
 */
16
final class UnmappableRow extends InvalidArgument implements CannotLoadTable
17
{
18
    /**
19
     * Produces an exception for when the row could not be mapped.
20
     *
21
     * @param Throwable $exception The exception that was encountered.
22
     * @param string    $label     The label for the failed entity type.
23
     * @param array     $input     The input data that could not be mapped.
24
     * @return CannotLoadTable     The exception to throw.
25
     */
26
    public static function encountered(
27
        Throwable $exception,
28
        string $label,
29
        array $input
30
    ): CannotLoadTable {
31
        return new UnmappableRow(withMessage(
32
            'Could not map the `%s` from `%s`: %s',
33
            $label,
34
            encodeAsJson($input),
35
            $exception->getMessage()
36
        ), 0, $exception);
37
    }
38
}
39