| Total Complexity | 12 |
| Total Lines | 63 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | class CriteriaMatcher |
||
| 10 | { |
||
| 11 | /** @var mixed[] */ |
||
| 12 | private $criteria; |
||
| 13 | |||
| 14 | /** @var mixed[] */ |
||
| 15 | private $row; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @param mixed[] $criteria |
||
| 19 | * @param mixed[] $row |
||
| 20 | */ |
||
| 21 | 9 | public function __construct(array $criteria, array $row) |
|
| 22 | { |
||
| 23 | 9 | $this->criteria = $criteria; |
|
| 24 | 9 | $this->row = $row; |
|
| 25 | 9 | } |
|
| 26 | |||
| 27 | 9 | public function matches() : bool |
|
| 28 | { |
||
| 29 | 9 | $matches = true; |
|
| 30 | |||
| 31 | 9 | foreach ($this->criteria as $key => $value) { |
|
| 32 | 5 | if ($this->criteriaElementMatches($key, $value)) { |
|
| 33 | 3 | continue; |
|
| 34 | } |
||
| 35 | |||
| 36 | 3 | $matches = false; |
|
| 37 | } |
||
| 38 | |||
| 39 | 9 | return $matches; |
|
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param mixed $value |
||
| 44 | */ |
||
| 45 | 5 | private function criteriaElementMatches(string $key, $value) : bool |
|
| 46 | { |
||
| 47 | 5 | if (isset($value['$contains'])) { |
|
| 48 | 2 | if ($this->contains($key, $value)) { |
|
| 49 | 2 | return true; |
|
| 50 | } |
||
| 51 | 3 | } elseif ($this->equals($key, $value)) { |
|
| 52 | 2 | return true; |
|
| 53 | } |
||
| 54 | |||
| 55 | 3 | return false; |
|
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @param mixed[] $value |
||
| 60 | */ |
||
| 61 | 2 | private function contains(string $key, array $value) : bool |
|
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param mixed $value |
||
| 68 | */ |
||
| 69 | 3 | private function equals(string $key, $value) : bool |
|
| 74 |