Skip to content

Commit c0fdb56

Browse files
committed
formatting and cleaning
1 parent 4703e39 commit c0fdb56

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

src/Illuminate/Validation/Validator.php

+26-21
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,6 @@ public function passes()
287287
foreach ($this->rules as $attribute => $rules) {
288288
$attribute = str_replace('\.', '->', $attribute);
289289

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

@@ -320,21 +318,27 @@ public function passes()
320318
return $this->messages->isEmpty();
321319
}
322320

321+
/**
322+
* Determine if the data fails the validation rules.
323+
*
324+
* @return bool
325+
*/
326+
public function fails()
327+
{
328+
return ! $this->passes();
329+
}
330+
323331
/**
324332
* Determine if the attribute should be excluded.
325333
*
326334
* @param string $attribute
327-
*
328335
* @return bool
329336
*/
330337
protected function shouldBeExcluded($attribute)
331338
{
332339
foreach ($this->excludeAttributes as $excludeAttribute) {
333-
if ($attribute === $excludeAttribute) {
334-
return true;
335-
}
336-
337-
if (Str::startsWith($attribute, $excludeAttribute.'.')) {
340+
if ($attribute === $excludeAttribute ||
341+
Str::startsWith($attribute, $excludeAttribute.'.')) {
338342
return true;
339343
}
340344
}
@@ -354,16 +358,6 @@ protected function removeAttribute($attribute)
354358
unset($this->data[$attribute], $this->rules[$attribute]);
355359
}
356360

357-
/**
358-
* Determine if the data fails the validation rules.
359-
*
360-
* @return bool
361-
*/
362-
public function fails()
363-
{
364-
return ! $this->passes();
365-
}
366-
367361
/**
368362
* Run the validator's rules against its data.
369363
*
@@ -688,9 +682,7 @@ public function addFailure($attribute, $rule, $parameters = [])
688682
}
689683

690684
if (in_array($rule, $this->excludeRules)) {
691-
$this->excludeAttributes[] = $attribute;
692-
693-
return;
685+
return $this->excludeAttribute($attribute);
694686
}
695687

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

695+
/**
696+
* Add the given attribute to the list of excluded attributes.
697+
*
698+
* @param string $attribute
699+
* @return void
700+
*/
701+
protected function excludeAttribute(string $attribute)
702+
{
703+
$this->excludeAttributes[] = $attribute;
704+
705+
$this->excludeAttributes = array_unique($this->excludeAttributes);
706+
}
707+
703708
/**
704709
* Returns the data which was valid.
705710
*

0 commit comments

Comments
 (0)