returns . ' can not be matched because the matching conditions are empty'); } if (count($conditions) > $this->maxConditions) { throw new \Exception($this->returns . " can not be matched because multiple matching conditions are specified. Only {this->maxConditions} condition(s) are supported"); } foreach ($conditions as $key => $value) { if (!in_array((string)$key, $this->allowedConditions)) { throw new \Exception($this->returns . " can not be matched because matching condition '$key' is not supported. Supported conditions are: " . implode(', ', $this->allowedConditions)); } } } public function matchOne(array $conditions) { $results = $this->match($conditions); $count = count($results); if ($count !== 1) { throw new \Exception("Found $count " . $this->returns . " when expected exactly only one to match the conditions"); } return reset($results); } abstract public function match(array $conditions); }