Stratadox/TableLoader

View on GitHub
src/Loader/MissingIdentifyingColumn.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php
declare(strict_types=1);

namespace Stratadox\TableLoader\Loader;

use InvalidArgumentException as InvalidArgument;
use function json_encode as encodeAsJson;
use function sprintf as withMessage;

/**
 * Notifies the client code that a required identifier is missing.
 *
 * @author Stratadox
 */
final class MissingIdentifyingColumn extends InvalidArgument implements CannotIdentifyEntity
{
    /**
     * Produces an exception for when the input data is missing a required
     * identifier column.
     *
     * @param array  $inputData     The data that lacks an identifier.
     * @param string $identifier    The identifier that is missing.
     * @return CannotIdentifyEntity The exception to throw.
     */
    public static function inThe(
        array $inputData,
        string $identifier
    ): CannotIdentifyEntity {
        return new MissingIdentifyingColumn(withMessage(
            'Missing the identifying column `%s` in the input data: %s',
            $identifier,
            encodeAsJson($inputData)
        ));
    }
}