@@ -21,8 +21,11 @@ discard block |
||
| 21 | 21 | foreach ($fields as $key => $val) { |
| 22 | 22 | $currentFieldResult = $this->getIfFieldMatches($key, $val, $data, $mode); |
| 23 | 23 | |
| 24 | - if (Maphper::FIND_OR & $mode && $currentFieldResult === true) return true; |
|
| 25 | - else if (Maphper::FIND_OR ^ $mode && $currentFieldResult === false) return false; |
|
| 24 | + if (Maphper::FIND_OR & $mode && $currentFieldResult === true) { |
|
| 25 | + return true; |
|
| 26 | + } else if (Maphper::FIND_OR ^ $mode && $currentFieldResult === false) { |
|
| 27 | + return false; |
|
| 28 | + } |
|
| 26 | 29 | } |
| 27 | 30 | return (bool)(Maphper::FIND_OR ^ $mode); |
| 28 | 31 | }; |
@@ -31,12 +34,13 @@ discard block |
||
| 31 | 34 | private function getIfFieldMatches($key, $val, $data, $mode) { |
| 32 | 35 | if ($this->shouldRunDeepSearch($key, $val)) { |
| 33 | 36 | return $this->getSearchFieldFunction($val, $key)($data); |
| 37 | + } else if (!isset($data->$key)) { |
|
| 38 | + return false; |
|
| 39 | + } else if ($this->isInArraySearch($mode, $key, $val)) { |
|
| 40 | + return in_array($data->$key, $val); |
|
| 41 | + } else { |
|
| 42 | + return $this->processFilter($mode, $val, $data->$key); |
|
| 34 | 43 | } |
| 35 | - else if (!isset($data->$key)) return false; |
|
| 36 | - else if ($this->isInArraySearch($mode, $key, $val)) |
|
| 37 | - return in_array($data->$key, $val); |
|
| 38 | - else |
|
| 39 | - return $this->processFilter($mode, $val, $data->$key); |
|
| 40 | 44 | } |
| 41 | 45 | |
| 42 | 46 | private function shouldRunDeepSearch($key, $val) { |
@@ -48,13 +52,21 @@ discard block |
||
| 48 | 52 | } |
| 49 | 53 | |
| 50 | 54 | private function processFilter($mode, $expected, $actual) { |
| 51 | - if (Maphper::FIND_NOT & $mode) return $expected != $actual; |
|
| 52 | - else if ((Maphper::FIND_GREATER | Maphper::FIND_EXACT) === $mode) return $expected <= $actual; |
|
| 53 | - else if ((Maphper::FIND_LESS | Maphper::FIND_EXACT) === $mode) return $expected >= $actual; |
|
| 54 | - else if (Maphper::FIND_GREATER & $mode) return $expected < $actual; |
|
| 55 | - else if (Maphper::FIND_LESS & $mode) return $expected > $actual; |
|
| 56 | - else if (Maphper::FIND_BETWEEN & $mode) return $expected[0] <= $actual && $actual <= $expected[1]; |
|
| 57 | - else if (Maphper::FIND_NOCASE & $mode) return strtolower($expected) == strtolower($actual); |
|
| 55 | + if (Maphper::FIND_NOT & $mode) { |
|
| 56 | + return $expected != $actual; |
|
| 57 | + } else if ((Maphper::FIND_GREATER | Maphper::FIND_EXACT) === $mode) { |
|
| 58 | + return $expected <= $actual; |
|
| 59 | + } else if ((Maphper::FIND_LESS | Maphper::FIND_EXACT) === $mode) { |
|
| 60 | + return $expected >= $actual; |
|
| 61 | + } else if (Maphper::FIND_GREATER & $mode) { |
|
| 62 | + return $expected < $actual; |
|
| 63 | + } else if (Maphper::FIND_LESS & $mode) { |
|
| 64 | + return $expected > $actual; |
|
| 65 | + } else if (Maphper::FIND_BETWEEN & $mode) { |
|
| 66 | + return $expected[0] <= $actual && $actual <= $expected[1]; |
|
| 67 | + } else if (Maphper::FIND_NOCASE & $mode) { |
|
| 68 | + return strtolower($expected) == strtolower($actual); |
|
| 69 | + } |
|
| 58 | 70 | return $expected == $actual; |
| 59 | 71 | } |
| 60 | 72 | } |