Skip to content

Commit

Permalink
formatting and cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Dec 27, 2019
1 parent 4703e39 commit c0fdb56
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions src/Illuminate/Validation/Validator.php
Expand Up @@ -287,8 +287,6 @@ public function passes()
foreach ($this->rules as $attribute => $rules) {
$attribute = str_replace('\.', '->', $attribute);

// If this attribute is a nested rule, its parent might have already
// been excluded. If so, we have to remove the attribute.
if ($this->shouldBeExcluded($attribute)) {
$this->removeAttribute($attribute);

Expand Down Expand Up @@ -320,21 +318,27 @@ public function passes()
return $this->messages->isEmpty();
}

/**
* Determine if the data fails the validation rules.
*
* @return bool
*/
public function fails()
{
return ! $this->passes();
}

/**
* Determine if the attribute should be excluded.
*
* @param string $attribute
*
* @return bool
*/
protected function shouldBeExcluded($attribute)
{
foreach ($this->excludeAttributes as $excludeAttribute) {
if ($attribute === $excludeAttribute) {
return true;
}

if (Str::startsWith($attribute, $excludeAttribute.'.')) {
if ($attribute === $excludeAttribute ||
Str::startsWith($attribute, $excludeAttribute.'.')) {
return true;
}
}
Expand All @@ -354,16 +358,6 @@ protected function removeAttribute($attribute)
unset($this->data[$attribute], $this->rules[$attribute]);
}

/**
* Determine if the data fails the validation rules.
*
* @return bool
*/
public function fails()
{
return ! $this->passes();
}

/**
* Run the validator's rules against its data.
*
Expand Down Expand Up @@ -688,9 +682,7 @@ public function addFailure($attribute, $rule, $parameters = [])
}

if (in_array($rule, $this->excludeRules)) {
$this->excludeAttributes[] = $attribute;

return;
return $this->excludeAttribute($attribute);
}

$this->messages->add($attribute, $this->makeReplacements(
Expand All @@ -700,6 +692,19 @@ public function addFailure($attribute, $rule, $parameters = [])
$this->failedRules[$attribute][$rule] = $parameters;
}

/**
* Add the given attribute to the list of excluded attributes.
*
* @param string $attribute
* @return void
*/
protected function excludeAttribute(string $attribute)
{
$this->excludeAttributes[] = $attribute;

$this->excludeAttributes = array_unique($this->excludeAttributes);
}

/**
* Returns the data which was valid.
*
Expand Down

0 comments on commit c0fdb56

Please sign in to comment.