Skip to content

Commit 0f233c6

Browse files
committed
Fixed pull request requirements
1 parent c5ca362 commit 0f233c6

File tree

3 files changed

+9
-38
lines changed

3 files changed

+9
-38
lines changed

src/Rule/Length.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Morebec\Validator\Rule;
44

55

6+
use InvalidArgumentException;
67
use Morebec\Validator\ValidationRuleInterface;
78

89
class Length implements ValidationRuleInterface
@@ -26,6 +27,8 @@ public function __construct(
2627
?string $message = null
2728
)
2829
{
30+
if ($length<0)
31+
throw new InvalidArgumentException();
2932
$this->length = $length;
3033
$this->message = $message;
3134
}
@@ -37,7 +40,7 @@ public function __construct(
3740
*/
3841
public function validate($v): bool
3942
{
40-
return strlen($v) == $this->length;
43+
return strlen($v) === $this->length;
4144
}
4245

4346
/**
@@ -47,6 +50,6 @@ public function validate($v): bool
4750
*/
4851
public function getMessage($v): string
4952
{
50-
return $this->message?:"'${$v}' is supposed to be exactly ".$this->length." characters long";
53+
return $this->message?:"'${$v}' is expected to be exactly ".$this->length." characters long";
5154
}
5255
}

src/Rule/MaxLength.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

tests/Rule/LengthTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Tests\Morebec\Validator\Rule;
44

55

6+
use InvalidArgumentException;
67
use Morebec\Validator\Rule\Length;
78
use PHPUnit\Framework\TestCase;
89

@@ -15,5 +16,8 @@ public function testValidate(){
1516
$this->assertTrue($ruleFirst->validate("test"));
1617
$this->assertFalse($ruleFirst->validate("test message"));
1718
$this->assertEquals("Custom message",$ruleSecond->getMessage("test"));
19+
20+
$this->expectException(InvalidArgumentException::class);
21+
$ruleThird = new Length(-1);
1822
}
1923
}

0 commit comments

Comments
 (0)