appliesToPosition($position)) { $categoryId = $rule->getCategoryId(); break; } } return $categoryId; } // ImportRule as returned by the ImportRuleService class ImportRule { /** @var int */ private $categoryId; /** @var string */ private $categoryName; /** @var array */ private $rules; public function __construct(int $categoryId, string $categoryName, array $rules) { $this->categoryId = $categoryId; $this->categoryName = $categoryName; $this->rules = $rules; } public function getCategoryId(): int { return $this->categoryId; } public function getCategoryName(): string { return $this->categoryName; } public function getRules(): array { return $this->rules; } public function setRules(array $rules) { $this->rules = $rules; } public function appliesToPosition(array $position) { foreach ($this->rules as $rule) { if (array_key_exists($rule->field, $position)) { if (property_exists($rule, 'regex') && !preg_match($rule->regex, $position[$rule->field])) { return false; } else if (property_exists($rule, 'value') && (trim($position[$rule->field]) != trim($rule->value))) { return false; } } else { // Field does not exist, so we skip this rule return false; } } return true; } }