Skip to content

Commit 3657d66

Browse files
committed
formatting
1 parent 5fb5258 commit 3657d66

2 files changed

Lines changed: 9 additions & 33 deletions

File tree

src/Illuminate/Validation/Validator.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,11 @@ public function validate()
306306
throw new ValidationException($this);
307307
}
308308

309-
return $this->getDataForRules();
309+
$data = collect($this->getData());
310+
311+
return $data->only(collect($this->getRules())->keys()->map(function ($rule) {
312+
return Str::contains($rule, '.') ? explode('.', $rule)[0] : $rule;
313+
}))->unique()->toArray();
310314
}
311315

312316
/**
@@ -727,20 +731,6 @@ public function getData()
727731
return $this->data;
728732
}
729733

730-
/**
731-
* Get the data under validation only for the loaded rules.
732-
*
733-
* @return array
734-
*/
735-
public function getDataForRules()
736-
{
737-
$ruleKeys = collect($this->getRules())->keys()->map(function ($rule) {
738-
return explode('.', $rule, 2)[0];
739-
})->unique()->toArray();
740-
741-
return collect($this->getData())->only($ruleKeys)->toArray();
742-
}
743-
744734
/**
745735
* Set the data under validation.
746736
*

tests/Validation/ValidationValidatorTest.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3874,28 +3874,14 @@ public function message()
38743874
$this->assertTrue($rule->called);
38753875
}
38763876

3877-
public function testGetDataForRules()
3877+
public function testValidateReturnsValidatedData()
38783878
{
3879-
$post = ['first'=>'john', 'last'=>'doe', 'type' => 'admin'];
3879+
$post = ['first' => 'john', 'last' => 'doe', 'type' => 'admin'];
38803880

38813881
$v = new Validator($this->getIlluminateArrayTranslator(), $post, ['first' => 'required']);
3882-
$data = $v->getDataForRules();
3882+
$data = $v->validate();
38833883

3884-
$this->assertSame($data, ['first'=>'john']);
3885-
3886-
$v->sometimes('last', 'required', function () {
3887-
return true;
3888-
});
3889-
$data = $v->getDataForRules();
3890-
3891-
$this->assertSame($data, ['first'=>'john', 'last'=>'doe']);
3892-
3893-
$v->sometimes('type', 'required', function () {
3894-
return false;
3895-
});
3896-
$data = $v->getDataForRules();
3897-
3898-
$this->assertSame($data, ['first'=>'john', 'last'=>'doe']);
3884+
$this->assertEquals(['first' => 'john'], $data);
38993885
}
39003886

39013887
protected function getTranslator()

0 commit comments

Comments
 (0)