Skip to content

Commit

Permalink
update file Validator.php
Browse files Browse the repository at this point in the history
  • Loading branch information
juancristobalgd1 committed Mar 1, 2024
1 parent ade5a50 commit 667f526
Showing 1 changed file with 2 additions and 29 deletions.
31 changes: 2 additions & 29 deletions src/libraries/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public function resetCountErrors(array $rules)
* @param string $field The name of the field where the error occurred.
* @param string $rule The name of the validation rule that failed.
* @param string $message (Optional) Custom error message. If not provided, the default message for the rule will be used.
*
* @return void
*/
public function addError(string $field, string $rule, string $message = '')
Expand Down Expand Up @@ -153,7 +152,6 @@ public function addRules(array $rules): self

/**
* Get the validation rules defined for this validator.
*
* @return array The validation rules as an associative array.
*/
public function getRules(): array
Expand All @@ -170,7 +168,7 @@ public function getRules(): array
* @param int|null $code An optional error code for more advanced error handling.
* @return array
*/
public function setError(string $field, string $rule, string $message): array
public function setError(string $field, string $rule, string $message): void
{
$this->errors[$field] = [];
$addError = [
Expand Down Expand Up @@ -301,8 +299,6 @@ public function validate(): bool

/**
* Check if the validation process has failed.
*
* This method checks whether the validation process has failed by invoking the "startValidation" method.
* @return bool True if the validation process has failed, false otherwise.
*/
public function fails(): bool
Expand Down Expand Up @@ -364,19 +360,15 @@ private function parseValidationRules(string $rulesString): array
/**
* Apply a custom validation rule to a specific field.
*
* This function checks if the provided validation rule is an instance of the
* `Validation\Rules\CustomRule` class, and if so, it executes it on the specified field.
* @param mixed $ruleItem The validation rule to apply. It should be an instance of `Validation\Rules\CustomRule`.
* @param string $field The name of the field to which the custom validation rule will be applied.
* @return void
*/
private function applyCustomValidation($ruleItem, string $field)
{
if ($ruleItem instanceof Validation\Rules\CustomRule) {
if ($ruleItem instanceof \Validation\Rules\CustomRule) {
// Prepare the parameters before executing the custom validation rule.
$updatedParameters = $this->prepareParametersBeforeExecution('custom_rule', $field, []);

// Execute the custom validation rule.
$this->executeRule($updatedParameters);
}
}
Expand Down Expand Up @@ -442,8 +434,6 @@ private function prepareParametersBeforeExecution(string $rule, string $field, a
/**
* Parses a validation rule and extracts its components.
*
* This method splits a validation rule into its rule name, field name, and values.
* It handles special cases for 'same' and 'unique' rules.
* @param string $ruleItem The validation rule to parse (e.g., 'ruleName:parameter').
* @param string $field The name of the field being validated.
* @return array An array with the parsed rule, field name, and values.
Expand Down Expand Up @@ -560,8 +550,6 @@ private function compileDateRule($rule, $parameters)
/**
* Compile a conditional rule for validation.
*
* This function takes a conditional rule in the form of parameters and splits it into fields and values
* based on a list of allowed comparison operators.
* @param string $rule The name of the rule.
* @param array $parameters The parameters of the conditional rule.
* @throws RuntimeException If a valid parameter is not provided.
Expand Down Expand Up @@ -731,7 +719,6 @@ private function instantiateClass(string $classRuleName, string $nameSpace = 'Ax
throw new RuntimeException('The class name cannot be empty.');
}


if (!class_exists($class)) {
throw new RuntimeException(sprintf('Validation class [ %s ] does not exist.', $class));
}
Expand All @@ -744,20 +731,6 @@ private function instantiateClass(string $classRuleName, string $nameSpace = 'Ax
return $instance;
}

// private function instantiateClass(string $classRuleName, string $nameSpace = 'Axm\\Validation\\Rules\\', string $method = 'validate'): object
// {
// $class = $nameSpace . ucfirst($classRuleName);

// return match (true) {
// empty($classRuleName) => throw new RuntimeException('The class name cannot be empty.'),
// !class_exists($class) => throw new RuntimeException(sprintf('Validation class [ %s ] does not exist.', $class)),
// !method_exists($instance = $this->getOrCreateInstance($class), $method) => throw new RuntimeException(sprintf('Method [ %s ] does not exist in class [ %s ] .', $method, $class)),

// default => $instance,
// };
// }


/**
* Get an existing instance of the class or create a new one.
*
Expand Down

0 comments on commit 667f526

Please sign in to comment.