src/Serializer/JsonDeserializer.php
private function deserializeRule(array $decodedRule): RuleInterface
    {
        $requiredKeyIsMissing = !(
            array_key_exists('id', $decodedRule)
            && array_key_exists('field', $decodedRule)
            && array_key_exists('type', $decodedRule)
            && array_key_exists('operator', $decodedRule)
            && array_key_exists('value', $decodedRule)
        );
        if ($requiredKeyIsMissing) {
            $keysGiven = implode(', ', array_keys($decodedRule));

            throw new JsonDeserializerRuleKeyException('Keys given: '.$keysGiven.'. Expected id, field, type, operator, value');
        }

        $id = $decodedRule['id'];
        $field = $decodedRule['field'];
        $type = $decodedRule['type'];
        $operator = $decodedRule['operator'];
        $value = $decodedRule['value'];

        // operators in and not_in require an array, ensure that single values are converted to an array
        if (in_array($operator, ['in', 'not_in']) && !is_array($value)) {
            $value = [$value];
        }

        // some operators require a single value, ensure that arrays are converted to a single value
        if (
            in_array($operator, ['equal', 'not_equal', 'less', 'less_or_equal', 'greater', 'greater_or_equal', 'begins_with', 'not_begins_with', 'contains', 'ends_with', 'not_ends_with'])
            && is_array($value)
        ) {
            $value = array_values($value)[0];
        }

        if (!is_array($value)) {
            $value = $this->convertValueAccordingToType($type, $value);

            return new Rule($id, $field, $type, $operator, $value);
        } else {
            $valuesArray = $value;
            foreach ($valuesArray as $key => $value) {
                $valuesArray[$key] = $this->convertValueAccordingToType($type, $value);
            }

            return new Rule($id, $field, $type, $operator, $valuesArray);
        }
    }
private function deserializeRule(array $decodedRule): RuleInterface
    {
        $requiredKeyIsMissing = !(
            array_key_exists('id', $decodedRule)
            && array_key_exists('field', $decodedRule)
            && array_key_exists('type', $decodedRule)
            && array_key_exists('operator', $decodedRule)
            && array_key_exists('value', $decodedRule)
        );
        if ($requiredKeyIsMissing) {
            $keysGiven = implode(', ', array_keys($decodedRule));

            throw new JsonDeserializerRuleKeyException('Keys given: '.$keysGiven.'. Expected id, field, type, operator, value');
        }

        $id = $decodedRule['id'];
        $field = $decodedRule['field'];
        $type = $decodedRule['type'];
        $operator = $decodedRule['operator'];
        $value = $decodedRule['value'];

        // operators in and not_in require an array, ensure that single values are converted to an array
        if (in_array($operator, ['in', 'not_in']) && !is_array($value)) {
            $value = [$value];
        }

        // some operators require a single value, ensure that arrays are converted to a single value
        if (
            in_array($operator, ['equal', 'not_equal', 'less', 'less_or_equal', 'greater', 'greater_or_equal', 'begins_with', 'not_begins_with', 'contains', 'ends_with', 'not_ends_with'])
            && is_array($value)
        ) {
            $value = array_values($value)[0];
        }

        if (!is_array($value)) {
            $value = $this->convertValueAccordingToType($type, $value);

            return new Rule($id, $field, $type, $operator, $value);
        } else {
            $valuesArray = $value;
            foreach ($valuesArray as $key => $value) {
                $valuesArray[$key] = $this->convertValueAccordingToType($type, $value);
            }

            return new Rule($id, $field, $type, $operator, $valuesArray);
        }
    }
@param array $decodedRule

@return RuleInterface

@throws \Exception