Skip to content
Permalink
Browse files

formatting and cleaning

  • Loading branch information
taylorotwell committed Dec 27, 2019
1 parent 4703e39 commit c0fdb566831b7ebf34a15bbdfec81dd0039c76f0
Showing with 26 additions and 21 deletions.
  1. +26 −21 src/Illuminate/Validation/Validator.php
@@ -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);

@@ -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;
}
}
@@ -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.
*
@@ -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(
@@ -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.
*

0 comments on commit c0fdb56

Please sign in to comment.
You can’t perform that action at this time.