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
ColumnOperator 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 comparison operators a column-to-column comparison can use — the
9 * `whereColumn()` and join-condition operators.
10 */
11enum ColumnOperator: string
12{
13    /** Equality (`=`). */
14    case Eq = '=';
15
16    /** Inequality (`!=`). */
17    case NotEq = '!=';
18
19    /** Less than (`<`). */
20    case Lt = '<';
21
22    /** Less than or equal (`<=`). */
23    case LtEq = '<=';
24
25    /** Greater than (`>`). */
26    case Gt = '>';
27
28    /** Greater than or equal (`>=`). */
29    case GtEq = '>=';
30
31    /**
32     * Resolve a string to a case, failing fast on anything else.
33     *
34     * @param  string  $operator
35     * @return self
36     * @throws \InvalidArgumentException
37     */
38    public static function fromChecked(string $operator): self
39    {
40        return self::tryFrom($operator)
41            ?? self::tryFrom(strtoupper($operator))
42            ?? throw new \InvalidArgumentException(
43                "Invalid column comparison operator [{$operator}]. Expected one of: =, !=, <, <=, >, >=."
44            );
45    }
46}