Skip to content

Commit

Permalink
Fixed pull request requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
mboiev committed Mar 7, 2020
1 parent c5ca362 commit 0f233c6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 38 deletions.
7 changes: 5 additions & 2 deletions src/Rule/Length.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Morebec\Validator\Rule;


use InvalidArgumentException;
use Morebec\Validator\ValidationRuleInterface;

class Length implements ValidationRuleInterface
Expand All @@ -26,6 +27,8 @@ public function __construct(
?string $message = null
)
{
if ($length<0)
throw new InvalidArgumentException();
$this->length = $length;
$this->message = $message;
}
Expand All @@ -37,7 +40,7 @@ public function __construct(
*/
public function validate($v): bool
{
return strlen($v) == $this->length;
return strlen($v) === $this->length;
}

/**
Expand All @@ -47,6 +50,6 @@ public function validate($v): bool
*/
public function getMessage($v): string
{
return $this->message?:"'${$v}' is supposed to be exactly ".$this->length." characters long";
return $this->message?:"'${$v}' is expected to be exactly ".$this->length." characters long";
}
}
36 changes: 0 additions & 36 deletions src/Rule/MaxLength.php

This file was deleted.

4 changes: 4 additions & 0 deletions tests/Rule/LengthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Morebec\Validator\Rule;


use InvalidArgumentException;
use Morebec\Validator\Rule\Length;
use PHPUnit\Framework\TestCase;

Expand All @@ -15,5 +16,8 @@ public function testValidate(){
$this->assertTrue($ruleFirst->validate("test"));
$this->assertFalse($ruleFirst->validate("test message"));
$this->assertEquals("Custom message",$ruleSecond->getMessage("test"));

$this->expectException(InvalidArgumentException::class);
$ruleThird = new Length(-1);
}
}

0 comments on commit 0f233c6

Please sign in to comment.