Skip to content

Commit d0bb1f0

Browse files
committed
Convert Relation to Enum.
1 parent 106a6a4 commit d0bb1f0

File tree

4 files changed

+23
-61
lines changed

4 files changed

+23
-61
lines changed

src/Enum/Relation.php

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,16 @@
77
*
88
* Use this in AddRelation method.
99
*/
10-
class Relation
10+
enum Relation
1111
{
12-
13-
/**
14-
* "Equal" relational operator
15-
*/
16-
const EQUAL = 0;
17-
18-
/**
19-
* "Less than" relational operator
20-
*/
21-
const LESS_THAN = 1;
22-
23-
/**
24-
* "Greater than" relational operator
25-
*/
26-
const GREATER_THAN = 2;
27-
28-
/**
29-
* "Less or Equal Than" relational operator
30-
*/
31-
const LESS_OR_EQUAL_THAN = 3;
32-
33-
/**
34-
* "Greater or equal than" relational operator
35-
*/
36-
const GREATER_OR_EQUAL_THAN = 4;
37-
38-
/**
39-
* "Not equal" relational operator
40-
*/
41-
const NOT_EQUAL = 5;
42-
43-
/**
44-
* "Starts with" unary comparator
45-
*/
46-
const STARTS_WITH = 6;
47-
48-
/**
49-
* "Contains" unary comparator
50-
*/
51-
const CONTAINS = 7;
52-
53-
/**
54-
* "In" unary comparator
55-
*/
56-
const IN = 8;
57-
58-
/**
59-
* "Not In" unary comparator
60-
*/
61-
const NOT_IN = 9;
62-
}
12+
case EQUAL;
13+
case LESS_THAN;
14+
case GREATER_THAN;
15+
case LESS_OR_EQUAL_THAN;
16+
case GREATER_OR_EQUAL_THAN;
17+
case NOT_EQUAL;
18+
case STARTS_WITH;
19+
case CONTAINS;
20+
case IN;
21+
case NOT_IN;
22+
}

src/IteratorFilter.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,25 @@ private function evalString(Row $singleRow): bool
107107

108108
/**
109109
* @param string $name Field name
110-
* @param int $relation Relation enum
111-
* @param array|string $value Field string value
110+
* @param Relation $relation Relation enum
111+
* @param mixed $value Field string value
112112
* @return static
113113
* @desc Add a single string comparison to filter.
114114
*/
115-
public function addRelation(string $name, int $relation, mixed $value): static
115+
public function addRelation(string $name, Relation $relation, mixed $value): static
116116
{
117117
$this->filters[] = [" and ", $name, $relation, $value];
118118
return $this;
119119
}
120120

121121
/**
122122
* @param string $name Field name
123-
* @param int $relation Relation enum
124-
* @param array|string $value Field string value
123+
* @param Relation $relation Relation enum
124+
* @param mixed $value Field string value
125125
* @return static
126126
* @desc Add a single string comparison to filter. This comparison use the OR operator.
127127
*/
128-
public function addRelationOr(string $name, int $relation, mixed $value): static
128+
public function addRelationOr(string $name, Relation $relation, mixed $value): static
129129
{
130130
$this->filters[] = [" or ", $name, $relation, $value];
131131
return $this;

src/IteratorFilterFormatter.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22

33
namespace ByJG\AnyDataset\Core;
44

5+
use ByJG\AnyDataset\Core\Enum\Relation;
6+
57
abstract class IteratorFilterFormatter
68
{
79

810
/**
911
* Get Relation
1012
*
1113
* @param string $name
12-
* @param string $relation
14+
* @param Relation $relation
1315
* @param array|string $value
1416
* @param array $param
1517
* @return string
1618
*/
17-
abstract public function getRelation(string $name, string $relation, mixed $value, array &$param): string;
19+
abstract public function getRelation(string $name, Relation $relation, mixed $value, array &$param): string;
1820

1921
/**
2022
* Get formatted field

src/IteratorFilterXPathFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function format(array $filters, string $tableName = null, array &$params
2424
/**
2525
* @inheritDoc
2626
*/
27-
public function getRelation(string $name, string $relation, mixed $value, array &$param): string
27+
public function getRelation(string $name, Relation $relation, mixed $value, array &$param): string
2828
{
2929
$str = is_numeric($value) ? "" : "'";
3030
$field = "field[@name='" . $name . "'] ";

0 commit comments

Comments
 (0)