Lines 100.00% 5 / 5
Functions and Methods 100.00% 1 / 1
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
SortDirection 100.00% 5 / 5 100.00% 1 / 1 1 100.00% 1 / 1
 fromChecked 100.00% 5 / 5 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace BlueprintAU\Radiant\Database\Query\Enums;
6
7/**
8 * The sort direction an `ORDER BY` clause can use.
9 */
10enum SortDirection: string
11{
12    /** Ascending order. */
13    case Asc = 'ASC';
14
15    /** Descending order. */
16    case Desc = 'DESC';
17
18    /**
19     * Resolve a string to a case, failing fast on anything else.
20     *
21     * @param  string  $direction
22     * @return self
23     * @throws \InvalidArgumentException
24     */
25    public static function fromChecked(string $direction): self
26    {
27        return self::tryFrom(strtoupper($direction))
28            ?? throw new \InvalidArgumentException(
29                "Order direction must be ASC or DESC; got [{$direction}]. "
30                . 'For anything else, pass a pre-validated Expression to orderBy().'
31            );
32    }
33}