Skip to content

Commit

Permalink
Improve code style
Browse files Browse the repository at this point in the history
  • Loading branch information
ilijastuden committed Mar 8, 2024
1 parent 9926cee commit 2ee0333
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,32 @@ public function __construct(
public function present(string $field_name): bool
{
if (empty($field_name)) {
throw new InvalidArgumentException("Value '$field_name' is not a valid field name");
throw new InvalidArgumentException(
sprintf("Value '%s' is not a valid field name", $field_name),
);
}

if (array_key_exists($field_name, $this->field_values)) {
if (is_string($this->field_values[$field_name])) {
if (mb_strlen(trim($this->field_values[$field_name])) > 0) {
return true;
} else {
return $this->failPresenceValidation($field_name);
}
} elseif (is_bool($this->field_values[$field_name])) {
if (!array_key_exists($field_name, $this->field_values)) {
return $this->failPresenceValidation($field_name);
}

if (is_string($this->field_values[$field_name])) {
if (mb_strlen(trim($this->field_values[$field_name])) > 0) {
return true;
} else {
if (empty($this->field_values[$field_name])) {
return $this->failPresenceValidation($field_name);
} else {
return true;
}
}
} else {

return $this->failPresenceValidation($field_name);
}

if (is_bool($this->field_values[$field_name])) {
return true;
}

if (empty($this->field_values[$field_name])) {
return $this->failPresenceValidation($field_name);
}

return true;
}

/**
Expand Down

0 comments on commit 2ee0333

Please sign in to comment.