Lines 100.00% 5 / 5
Methods 100.00% 1 / 1
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 fromChecked 100.00% 5 / 5 100.00% 1 / 1 1
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}