Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
20 / 20 |
|
100.00% |
17 / 17 |
CRAP | |
100.00% |
1 / 1 |
| Filter | |
100.00% |
20 / 20 |
|
100.00% |
17 / 17 |
18 | |
100.00% |
1 / 1 |
| build | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| list | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| combine | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| eq | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| ne | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| gt | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| gte | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| lt | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| lte | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| like | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| notLike | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| in | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| notIn | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isNull | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isNotNull | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| between | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| notBetween | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Projom\Storage\SQL\Util; |
| 6 | |
| 7 | use Projom\Storage\SQL\Util\LogicalOperator; |
| 8 | use Projom\Storage\SQL\Util\Operator; |
| 9 | use Projom\Storage\Util; |
| 10 | |
| 11 | class Filter |
| 12 | { |
| 13 | public static function build( |
| 14 | string $field, |
| 15 | mixed $value, |
| 16 | Operator $operator = Operator::EQ, |
| 17 | LogicalOperator $logicalOperator = LogicalOperator::AND |
| 18 | ): array { |
| 19 | return [$field, $operator, $value, $logicalOperator]; |
| 20 | } |
| 21 | |
| 22 | public static function list( |
| 23 | array $fieldsWithValues, |
| 24 | Operator $operator = Operator::EQ, |
| 25 | LogicalOperator $logicalOperator = LogicalOperator::AND |
| 26 | ): array { |
| 27 | $filter = []; |
| 28 | foreach ($fieldsWithValues as $field => $value) |
| 29 | $filter[] = static::build($field, $value, $operator, $logicalOperator); |
| 30 | return $filter; |
| 31 | } |
| 32 | |
| 33 | public static function combine(array ...$filters): array |
| 34 | { |
| 35 | return Util::merge($filters); |
| 36 | } |
| 37 | |
| 38 | public static function eq(string $field, mixed $value): array |
| 39 | { |
| 40 | return static::build($field, $value, Operator::EQ); |
| 41 | } |
| 42 | |
| 43 | public static function ne(string $field, mixed $value): array |
| 44 | { |
| 45 | return static::build($field, $value, Operator::NE); |
| 46 | } |
| 47 | |
| 48 | public static function gt(string $field, mixed $value): array |
| 49 | { |
| 50 | return static::build($field, $value, Operator::GT); |
| 51 | } |
| 52 | |
| 53 | public static function gte(string $field, mixed $value): array |
| 54 | { |
| 55 | return static::build($field, $value, Operator::GTE); |
| 56 | } |
| 57 | |
| 58 | public static function lt(string $field, mixed $value): array |
| 59 | { |
| 60 | return static::build($field, $value, Operator::LT); |
| 61 | } |
| 62 | |
| 63 | public static function lte(string $field, mixed $value): array |
| 64 | { |
| 65 | return static::build($field, $value, Operator::LTE); |
| 66 | } |
| 67 | |
| 68 | public static function like(string $field, mixed $value): array |
| 69 | { |
| 70 | return static::build($field, $value, Operator::LIKE); |
| 71 | } |
| 72 | |
| 73 | public static function notLike(string $field, mixed $value): array |
| 74 | { |
| 75 | return static::build($field, $value, Operator::NOT_LIKE); |
| 76 | } |
| 77 | |
| 78 | public static function in(string $field, array $values): array |
| 79 | { |
| 80 | return static::build($field, $values, Operator::IN); |
| 81 | } |
| 82 | |
| 83 | public static function notIn(string $field, array $values): array |
| 84 | { |
| 85 | return static::build($field, $values, Operator::NOT_IN); |
| 86 | } |
| 87 | |
| 88 | public static function isNull(string $field): array |
| 89 | { |
| 90 | return static::build($field, null, Operator::IS_NULL); |
| 91 | } |
| 92 | |
| 93 | public static function isNotNull(string $field): array |
| 94 | { |
| 95 | return static::build($field, null, Operator::IS_NOT_NULL); |
| 96 | } |
| 97 | |
| 98 | public static function between(string $field, mixed $value1, mixed $value2): array |
| 99 | { |
| 100 | return static::build($field, [$value1, $value2], Operator::BETWEEN); |
| 101 | } |
| 102 | |
| 103 | public static function notBetween(string $field, mixed $value1, mixed $value2): array |
| 104 | { |
| 105 | return static::build($field, [$value1, $value2], Operator::NOT_BETWEEN); |
| 106 | } |
| 107 | } |