Skip to content

Commit 86b3fdf

Browse files
committed
Rename isFailed to fails and isSuccess to success
1 parent 3bc9eef commit 86b3fdf

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ if (empty($data['password'])) {
8989
}
9090

9191
// Check validation result
92-
if ($validation->isFailed()) {
92+
if ($validation->fails()) {
9393
// Trigger error response (see validation middleware)
9494
throw new ValidationException('Please check your input', $validation);
9595
}
@@ -210,7 +210,7 @@ if (empty($data->username)) {
210210
}
211211

212212
// Check validation result
213-
if ($validation->isFailed()) {
213+
if ($validation->fails()) {
214214
// Trigger the validation middleware
215215
throw new ValidationException('Please check your input', $validation);
216216
}
@@ -341,7 +341,7 @@ if ($this->existsUsername($formData['username'])) {
341341
$validationResult->addError('username', 'Username is already taken');
342342
}
343343

344-
if ($validationResult->isFailed()) {
344+
if ($validationResult->fails()) {
345345
throw new ValidationException(__('Please check your input'), $validationResult);
346346
}
347347
```

src/ValidationResult.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ public function getFirstError(): ?ValidationError
3939
}
4040

4141
/**
42-
* Returns the success of the validation.
42+
* Determine if the data passes the validation rules.
4343
*
4444
* @return bool true if validation was successful; otherwise, false
4545
*/
46-
public function isSuccess(): bool
46+
public function success(): bool
4747
{
4848
return empty($this->errors);
4949
}
@@ -53,9 +53,9 @@ public function isSuccess(): bool
5353
*
5454
* @return bool Status
5555
*/
56-
public function isFailed(): bool
56+
public function fails(): bool
5757
{
58-
return !$this->isSuccess();
58+
return !$this->success();
5959
}
6060

6161
/**

tests/Converter/SymfonyValidationConverterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testCreateValidationResult(): void
2222

2323
$result = SymfonyValidationConverter::createValidationResult($violations);
2424

25-
$this->assertEquals(true, $result->isFailed());
25+
$this->assertEquals(true, $result->fails());
2626
$this->assertEquals('Email required', $result->getErrors()[0]->getMessage());
2727
$this->assertEquals('email', $result->getErrors()[0]->getField());
2828
$this->assertEquals(null, $result->getErrors()[0]->getCode());

tests/TestService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function process(int $id): array
2727
$validation->addError('id', 'invalid');
2828
}
2929

30-
if ($validation->isFailed()) {
30+
if ($validation->fails()) {
3131
throw new ValidationException('Please check your input', $validation);
3232
}
3333

tests/ValidationResultTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testErrors(): void
3030
{
3131
$val = new ValidationResult();
3232
$val->addError('error1', 'failed');
33-
$result = $val->isFailed();
33+
$result = $val->fails();
3434
$this->assertTrue($result);
3535
}
3636

@@ -42,7 +42,7 @@ public function testErrorsEmptyFieldOne(): void
4242
{
4343
$val = new ValidationResult();
4444
$val->addError('', 'invalid');
45-
$result = $val->isFailed();
45+
$result = $val->fails();
4646
$this->assertTrue($result);
4747
}
4848

@@ -54,7 +54,7 @@ public function testErrorsWithField(): void
5454
{
5555
$val = new ValidationResult();
5656
$val->addError('field', 'message');
57-
$result = $val->isFailed();
57+
$result = $val->fails();
5858
$this->assertTrue($result);
5959
}
6060

@@ -66,7 +66,7 @@ public function testErrorsWithMessage(): void
6666
{
6767
$val = new ValidationResult();
6868
$val->addError('email', 'required', '5000');
69-
$result = $val->isFailed();
69+
$result = $val->fails();
7070
$this->assertTrue($result);
7171

7272
$firstError = $val->getFirstError();
@@ -83,7 +83,7 @@ public function testErrorsWithMessage(): void
8383
public function testNoErrors(): void
8484
{
8585
$val = new ValidationResult();
86-
$result = $val->isFailed();
86+
$result = $val->fails();
8787
$this->assertFalse($result);
8888
}
8989

@@ -95,7 +95,7 @@ public function testClear(): void
9595
$val = new ValidationResult();
9696
$val->addError('email', 'required');
9797
$val->clear();
98-
$result = $val->isFailed();
98+
$result = $val->fails();
9999
$this->assertFalse($result);
100100
}
101101

0 commit comments

Comments
 (0)