Skip to content

Commit 12d06ff

Browse files
authored
Merge pull request #68 from rakit/improve-rules-check-method
Rule::check must return bool
2 parents 4dc604c + a2076fc commit 12d06ff

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

src/Rule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ abstract class Rule
2727
/** @var string */
2828
protected $message = "The :attribute is invalid";
2929

30-
abstract public function check($value);
30+
abstract public function check($value): bool;
3131

3232
/**
3333
* Set Validation class instance

src/Rules/Defaults.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ class Defaults extends Rule
1717
* Check the $value is valid
1818
*
1919
* @param mixed $value
20-
* @return mixed
20+
* @return bool
2121
*/
22-
public function check($value)
22+
public function check($value): bool
2323
{
2424
$this->requireParameters($this->fillableParams);
2525

2626
$default = $this->parameter('default');
27-
return $default;
27+
return true;
2828
}
2929
}

src/Validation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ protected function validateAttribute(Attribute $attribute)
134134
$ruleValidator->setAttribute($attribute);
135135

136136
if ($isEmptyValue && $ruleValidator instanceof Defaults) {
137-
$value = $ruleValidator->check(null);
137+
$value = $ruleValidator->parameter('default');
138138
$isEmptyValue = $this->isEmptyValue($value);
139139
continue;
140140
}

tests/Fixtures/Even.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Even extends Rule
99

1010
protected $message = "The :attribute must be even";
1111

12-
public function check($value)
12+
public function check($value): bool
1313
{
1414
if (! is_numeric($value)) {
1515
return false;

tests/Fixtures/Required.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class Required extends Rule
88
{
99

10-
public function check($value)
10+
public function check($value): bool
1111
{
1212
return true;
1313
}

tests/Rules/DefaultsTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77

88
class DefaultsTest extends TestCase
99
{
10-
1110
public function setUp()
1211
{
1312
$this->rule = new Defaults;
1413
}
1514

1615
public function testDefaults()
1716
{
18-
$this->assertEquals($this->rule->fillParameters([10])->check(null), 10);
19-
$this->assertEquals($this->rule->fillParameters(['something'])->check(null), 'something');
20-
$this->assertEquals($this->rule->fillParameters([[1,2,3]])->check('anything'), [1,2,3]);
17+
$this->assertTrue($this->rule->fillParameters([10])->check(0));
18+
$this->assertTrue($this->rule->fillParameters(['something'])->check(null));
19+
$this->assertTrue($this->rule->fillParameters([[1,2,3]])->check(false));
20+
$this->assertTrue($this->rule->fillParameters([[1,2,3]])->check([]));
2121
}
2222
}

0 commit comments

Comments
 (0)