From c0fdb566831b7ebf34a15bbdfec81dd0039c76f0 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 27 Dec 2019 09:41:41 -0600 Subject: [PATCH] formatting and cleaning --- src/Illuminate/Validation/Validator.php | 47 ++++++++++++++----------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index df5e61a10159..f6b2963b3427 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/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. *