diff --git a/src/Rule.php b/src/Rule.php index 4492004..a724240 100644 --- a/src/Rule.php +++ b/src/Rule.php @@ -27,7 +27,7 @@ abstract class Rule /** @var string */ protected $message = "The :attribute is invalid"; - abstract public function check($value); + abstract public function check($value): bool; /** * Set Validation class instance diff --git a/src/Rules/Defaults.php b/src/Rules/Defaults.php index bbf81b5..f182077 100644 --- a/src/Rules/Defaults.php +++ b/src/Rules/Defaults.php @@ -17,13 +17,13 @@ class Defaults extends Rule * Check the $value is valid * * @param mixed $value - * @return mixed + * @return bool */ - public function check($value) + public function check($value): bool { $this->requireParameters($this->fillableParams); $default = $this->parameter('default'); - return $default; + return true; } } diff --git a/src/Validation.php b/src/Validation.php index 7d724f8..9e37aaa 100644 --- a/src/Validation.php +++ b/src/Validation.php @@ -134,7 +134,7 @@ protected function validateAttribute(Attribute $attribute) $ruleValidator->setAttribute($attribute); if ($isEmptyValue && $ruleValidator instanceof Defaults) { - $value = $ruleValidator->check(null); + $value = $ruleValidator->parameter('default'); $isEmptyValue = $this->isEmptyValue($value); continue; } diff --git a/tests/Fixtures/Even.php b/tests/Fixtures/Even.php index 74fcb5a..b556695 100644 --- a/tests/Fixtures/Even.php +++ b/tests/Fixtures/Even.php @@ -9,7 +9,7 @@ class Even extends Rule protected $message = "The :attribute must be even"; - public function check($value) + public function check($value): bool { if (! is_numeric($value)) { return false; diff --git a/tests/Fixtures/Required.php b/tests/Fixtures/Required.php index 87f777b..ebd8f07 100644 --- a/tests/Fixtures/Required.php +++ b/tests/Fixtures/Required.php @@ -7,7 +7,7 @@ class Required extends Rule { - public function check($value) + public function check($value): bool { return true; } diff --git a/tests/Rules/DefaultsTest.php b/tests/Rules/DefaultsTest.php index 72715c0..e3b637c 100644 --- a/tests/Rules/DefaultsTest.php +++ b/tests/Rules/DefaultsTest.php @@ -7,7 +7,6 @@ class DefaultsTest extends TestCase { - public function setUp() { $this->rule = new Defaults; @@ -15,8 +14,9 @@ public function setUp() public function testDefaults() { - $this->assertEquals($this->rule->fillParameters([10])->check(null), 10); - $this->assertEquals($this->rule->fillParameters(['something'])->check(null), 'something'); - $this->assertEquals($this->rule->fillParameters([[1,2,3]])->check('anything'), [1,2,3]); + $this->assertTrue($this->rule->fillParameters([10])->check(0)); + $this->assertTrue($this->rule->fillParameters(['something'])->check(null)); + $this->assertTrue($this->rule->fillParameters([[1,2,3]])->check(false)); + $this->assertTrue($this->rule->fillParameters([[1,2,3]])->check([])); } }