@@ -10,7 +10,7 @@ class IteratorFilter
1010 /**
1111 * @var array
1212 */
13- private $ filters ;
13+ private array $ filters ;
1414
1515 /**
1616 * IteratorFilter Constructor
@@ -23,7 +23,7 @@ public function __construct()
2323 /**
2424 * @return IteratorFilter
2525 */
26- public static function getInstance ()
26+ public static function getInstance (): IteratorFilter
2727 {
2828 return new IteratorFilter ();
2929 }
@@ -32,7 +32,7 @@ public static function getInstance()
3232 * @param array $array
3333 * @return Row[]
3434 */
35- public function match ($ array )
35+ public function match (array $ array ): array
3636 {
3737 $ returnArray = [];
3838
@@ -49,12 +49,12 @@ public function match($array)
4949 * Get the filter
5050 *
5151 * @param IteratorFilterFormatter $formatter
52- * @param string $tableName
52+ * @param string|null $tableName
5353 * @param array $params
5454 * @param string $returnFields
5555 * @return string
5656 */
57- public function format (IteratorFilterFormatter $ formatter , $ tableName = null , &$ params = [], $ returnFields = "* " )
57+ public function format (IteratorFilterFormatter $ formatter , string $ tableName = null , array &$ params = [], string $ returnFields = "* " ): string
5858 {
5959 return $ formatter ->format ($ this ->filters , $ tableName , $ params , $ returnFields );
6060 }
@@ -64,7 +64,7 @@ public function format(IteratorFilterFormatter $formatter, $tableName = null, &$
6464 * @param Row $singleRow
6565 * @return bool
6666 */
67- private function evalString (Row $ singleRow )
67+ private function evalString (Row $ singleRow ): bool
6868 {
6969 $ result = [];
7070 $ finalResult = false ;
@@ -85,47 +85,18 @@ private function evalString(Row $singleRow)
8585 $ field = [$ singleRow ->get ($ name )];
8686
8787 foreach ($ field as $ valueparam ) {
88- switch ($ relation ) {
89- case Relation::EQUAL :
90- $ result [$ pos ] = $ result [$ pos ] && ($ valueparam == $ value );
91- break ;
92-
93- case Relation::GREATER_THAN :
94- $ result [$ pos ] = $ result [$ pos ] && ($ valueparam > $ value );
95- break ;
96-
97- case Relation::LESS_THAN :
98- $ result [$ pos ] = $ result [$ pos ] && ($ valueparam < $ value );
99- break ;
100-
101- case Relation::GREATER_OR_EQUAL_THAN :
102- $ result [$ pos ] = $ result [$ pos ] && ($ valueparam >= $ value );
103- break ;
104-
105- case Relation::LESS_OR_EQUAL_THAN :
106- $ result [$ pos ] = $ result [$ pos ] && ($ valueparam <= $ value );
107- break ;
108-
109- case Relation::NOT_EQUAL :
110- $ result [$ pos ] = $ result [$ pos ] && ($ valueparam != $ value );
111- break ;
112-
113- case Relation::STARTS_WITH :
114- $ result [$ pos ] = $ result [$ pos ] && (strpos (is_null ($ valueparam ) ? "" : $ valueparam , $ value ) === 0 );
115- break ;
116-
117- case Relation::IN :
118- $ result [$ pos ] = $ result [$ pos ] && in_array ($ valueparam , $ value );
119- break ;
120-
121- case Relation::NOT_IN :
122- $ result [$ pos ] = $ result [$ pos ] && !in_array ($ valueparam , $ value );
123- break ;
124-
125- default : // Relation::CONTAINS:
126- $ result [$ pos ] = $ result [$ pos ] && (strpos (is_null ($ valueparam ) ? "" : $ valueparam , $ value ) !== false );
127- break ;
128- }
88+ $ result [$ pos ] = match ($ relation ) {
89+ Relation::EQUAL => $ result [$ pos ] && ($ valueparam == $ value ),
90+ Relation::GREATER_THAN => $ result [$ pos ] && ($ valueparam > $ value ),
91+ Relation::LESS_THAN => $ result [$ pos ] && ($ valueparam < $ value ),
92+ Relation::GREATER_OR_EQUAL_THAN => $ result [$ pos ] && ($ valueparam >= $ value ),
93+ Relation::LESS_OR_EQUAL_THAN => $ result [$ pos ] && ($ valueparam <= $ value ),
94+ Relation::NOT_EQUAL => $ result [$ pos ] && ($ valueparam != $ value ),
95+ Relation::STARTS_WITH => $ result [$ pos ] && (str_starts_with (is_null ($ valueparam ) ? "" : $ valueparam , $ value )),
96+ Relation::IN => $ result [$ pos ] && in_array ($ valueparam , $ value ),
97+ Relation::NOT_IN => $ result [$ pos ] && !in_array ($ valueparam , $ value ),
98+ default => $ result [$ pos ] && (str_contains (is_null ($ valueparam ) ? "" : $ valueparam , $ value )),
99+ };
129100 }
130101 }
131102
@@ -137,11 +108,11 @@ private function evalString(Row $singleRow)
137108 /**
138109 * @param string $name Field name
139110 * @param int $relation Relation enum
140- * @param string| array $value Field string value
141- * @return IteratorFilter
111+ * @param array|string $value Field string value
112+ * @return static
142113 * @desc Add a single string comparison to filter.
143114 */
144- public function addRelation ($ name , $ relation , $ value )
115+ public function addRelation (string $ name , int $ relation , array | string $ value ): static
145116 {
146117 $ this ->filters [] = [" and " , $ name , $ relation , $ value ];
147118 return $ this ;
@@ -150,31 +121,31 @@ public function addRelation($name, $relation, $value)
150121 /**
151122 * @param string $name Field name
152123 * @param int $relation Relation enum
153- * @param string $value Field string value
154- * @return IteratorFilter
124+ * @param array| string $value Field string value
125+ * @return static
155126 * @desc Add a single string comparison to filter. This comparison use the OR operator.
156127 */
157- public function addRelationOr ($ name , $ relation , $ value )
128+ public function addRelationOr (string $ name , int $ relation , array | string $ value ): static
158129 {
159130 $ this ->filters [] = [" or " , $ name , $ relation , $ value ];
160131 return $ this ;
161132 }
162133
163134 /**
164135 * Add a "("
165- * @return IteratorFilter
136+ * @return static
166137 */
167- public function startGroup ()
138+ public function startGroup (): static
168139 {
169140 $ this ->filters [] = ["( " , "" , "" , "" ];
170141 return $ this ;
171142 }
172143
173144 /**
174145 * Add a ")"
175- * @return IteratorFilter
146+ * @return static
176147 */
177- public function endGroup ()
148+ public function endGroup (): static
178149 {
179150 $ this ->filters [] = [") " , "" , "" , "" ];
180151 return $ this ;
@@ -183,7 +154,7 @@ public function endGroup()
183154 /**
184155 * @return array
185156 */
186- public function getRawFilters ()
157+ public function getRawFilters (): array
187158 {
188159 return $ this ->filters ;
189160 }
0 commit comments