Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule::check must return bool #68

Merged
merged 2 commits into from
Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Rules/Defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Even.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Required.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Required extends Rule
{

public function check($value)
public function check($value): bool
{
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Rules/DefaultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

class DefaultsTest extends TestCase
{

public function setUp()
{
$this->rule = new Defaults;
}

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([]));
}
}