Skip to content

Commit

Permalink
Merge pull request #4309 from timkelty/fix-array-validator
Browse files Browse the repository at this point in the history
ArrayValidator clean up
  • Loading branch information
brandonkelly authored May 24, 2019
2 parents 88ab1df + cfa788f commit 9d3976c
Showing 1 changed file with 2 additions and 28 deletions.
30 changes: 2 additions & 28 deletions src/validators/ArrayValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,42 +99,16 @@ public function init()
}
}

/**
* @inheritdoc
*/
public function validateAttribute($model, $attribute)
{
$value = $model->$attribute;

if (!$value instanceof \Countable && !is_array($value)) {
$this->addError($model, $attribute, $this->message);

return;
}

$count = count($value);

if ($this->min !== null && $count < $this->min) {
$this->addError($model, $attribute, $this->tooFew, ['min' => $this->min]);
}
if ($this->max !== null && $count > $this->max) {
$this->addError($model, $attribute, $this->tooMany, ['max' => $this->max]);
}
if ($this->count !== null && $count !== $this->count) {
$this->addError($model, $attribute, $this->notEqual, ['count' => $this->count]);
}
}

/**
* @inheritdoc
*/
protected function validateValue($value)
{
if (!is_string($value)) {
if (!$value instanceof \Countable && !is_array($value)) {
return [$this->message, []];
}

$count = count((array)$value);
$count = count($value);

if ($this->min !== null && $count < $this->min) {
return [$this->tooFew, ['min' => $this->min]];
Expand Down

0 comments on commit 9d3976c

Please sign in to comment.