Skip to content

Commit

Permalink
ensure all constraints work
Browse files Browse the repository at this point in the history
  • Loading branch information
OriHoch committed Jul 13, 2017
1 parent b38ee54 commit 54cab6b
Show file tree
Hide file tree
Showing 2 changed files with 212 additions and 152 deletions.
25 changes: 11 additions & 14 deletions src/Fields/BaseField.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,30 +292,27 @@ protected function checkMaximumConstraint($val, $maxConstraint)
return $val <= $maxConstraint;
}

protected function checkMinLengthConstraint($val, $minLength)
protected function getLengthForConstraint($val)
{
if (is_string($val)) {
return strlen($val) >= $minLength;
return strlen($val);
} elseif (is_array($val)) {
return count($val) >= $minLength;
return count($val);
} elseif (is_object($val)) {
return count($val) >= $minLength;
return count((array)$val);
} else {
throw $this->getValidationException('invalid value for minLength constraint', $val);
throw $this->getValidationException('invalid value for length constraint', $val);
}
}

protected function checkMinLengthConstraint($val, $minLength)
{
return $this->getLengthForConstraint($val) >= $minLength;
}

protected function checkMaxLengthConstraint($val, $maxLength)
{
if (is_string($val)) {
return strlen($val) <= $maxLength;
} elseif (is_array($val)) {
return count($val) <= $maxLength;
} elseif (is_object($val)) {
return count($val) <= $maxLength;
} else {
throw $this->getValidationException('invalid value for maxLength constraint', $val);
}
return $this->getLengthForConstraint($val) <= $maxLength;
}

protected function getAllowedValues()
Expand Down
Loading

0 comments on commit 54cab6b

Please sign in to comment.