| Total Complexity | 9 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | 1 | final class Filter { |
|
| 15 | 1 | use \Nette\StaticClass; |
|
| 16 | |||
| 17 | public const OPERATORS = ["==", ">=", ">", "<=", "<", "!=",]; |
||
| 18 | |||
| 19 | public static function getOperator(string $input): string { |
||
| 26 | } |
||
| 27 | |||
| 28 | public static function matches(object $item, array $filter): bool { |
||
| 29 | /** @var string $key */ |
||
| 30 | 1 | foreach($filter as $key => $value) { |
|
| 31 | 1 | $operator = static::getOperator($key); |
|
| 32 | 1 | $key = Strings::endsWith($key, $operator) ? Strings::before($key, $operator) : $key; |
|
| 33 | 1 | if(!eval("return \"{$item->$key}\" $operator \"$value\";")) { |
|
| 34 | 1 | return false; |
|
| 35 | } |
||
| 36 | } |
||
| 37 | 1 | return true; |
|
| 38 | } |
||
| 39 | |||
| 40 | public static function applyFilter(array $input, array $filter = []): array { |
||
| 46 | 1 | })); |
|
| 47 | } |
||
| 49 | ?> |