Skip to content

Commit f138490

Browse files
committed
Add has methods
1 parent db0a3c0 commit f138490

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

src/AbstractValidator.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,36 @@ public function getResults(): mixed
109109
return $this->results;
110110
}
111111

112+
/**
113+
* Has validator value
114+
*
115+
* @return bool
116+
*/
117+
public function hasValue(): bool
118+
{
119+
return ($this->value !== null);
120+
}
121+
122+
/**
123+
* Has validator message
124+
*
125+
* @return bool
126+
*/
127+
public function hasMessage(): bool
128+
{
129+
return ($this->message !== null);
130+
}
131+
132+
/**
133+
* Has validator input
134+
*
135+
* @return bool
136+
*/
137+
public function hasInput(): bool
138+
{
139+
return ($this->input !== null);
140+
}
141+
112142
/**
113143
* Has validator results
114144
*

src/ValidatorInterface.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,27 @@ public function getInput(): mixed;
5454
*/
5555
public function getResults(): mixed;
5656

57+
/**
58+
* Has validator value
59+
*
60+
* @return bool
61+
*/
62+
public function hasValue(): bool;
63+
64+
/**
65+
* Has validator message
66+
*
67+
* @return bool
68+
*/
69+
public function hasMessage(): bool;
70+
71+
/**
72+
* Has validator input
73+
*
74+
* @return bool
75+
*/
76+
public function hasInput(): bool;
77+
5778
/**
5879
* Has validator results
5980
*

tests/ValidatorTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ public function testAlpha()
1515
$this->assertTrue($validator->evaluate('hello'));
1616
$this->assertFalse($validator->evaluate(123456));
1717
$this->assertEquals('This is not a alphabetical string.', $validator->getMessage());
18-
18+
$this->assertTrue($validator->hasInput());
19+
$this->assertFalse($validator->hasValue());
20+
$this->assertTrue($validator->hasMessage());
1921

2022
$validator = new Validator\Alpha();
2123
$this->assertFalse($validator->evaluate(123456));

0 commit comments

Comments
 (0)