MissingIdentifyingColumn::inThe()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 8
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
10
/**
11
 * Notifies the client code that a required identifier is missing.
12
 *
13
 * @author Stratadox
14
 */
15
final class MissingIdentifyingColumn extends InvalidArgument implements CannotIdentifyEntity
16
{
17
    /**
18
     * Produces an exception for when the input data is missing a required
19
     * identifier column.
20
     *
21
     * @param array  $inputData     The data that lacks an identifier.
22
     * @param string $identifier    The identifier that is missing.
23
     * @return CannotIdentifyEntity The exception to throw.
24
     */
25
    public static function inThe(
26
        array $inputData,
27
        string $identifier
28
    ): CannotIdentifyEntity {
29
        return new MissingIdentifyingColumn(withMessage(
30
            'Missing the identifying column `%s` in the input data: %s',
31
            $identifier,
32
            encodeAsJson($inputData)
33
        ));
34
    }
35
}
36