Skip to content

Commit bef0bf7

Browse files
committed
[Validator] Add PHPDoc void return types
1 parent b5bc601 commit bef0bf7

11 files changed

+28
-8
lines changed

ConstraintValidatorInterface.php

+4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ interface ConstraintValidatorInterface
2020
{
2121
/**
2222
* Initializes the constraint validator.
23+
*
24+
* @return void
2325
*/
2426
public function initialize(ExecutionContextInterface $context);
2527

2628
/**
2729
* Checks if the passed value is valid.
30+
*
31+
* @return void
2832
*/
2933
public function validate(mixed $value, Constraint $constraint);
3034
}

ConstraintViolationListInterface.php

+8
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ interface ConstraintViolationListInterface extends \Traversable, \Countable, \Ar
2525
{
2626
/**
2727
* Adds a constraint violation to this list.
28+
*
29+
* @return void
2830
*/
2931
public function add(ConstraintViolationInterface $violation);
3032

3133
/**
3234
* Merges an existing violation list into this list.
35+
*
36+
* @return void
3337
*/
3438
public function addAll(self $otherList);
3539

@@ -53,13 +57,17 @@ public function has(int $offset): bool;
5357
* Sets a violation at a given offset.
5458
*
5559
* @param int $offset The violation offset
60+
*
61+
* @return void
5662
*/
5763
public function set(int $offset, ConstraintViolationInterface $violation);
5864

5965
/**
6066
* Removes a violation at a given offset.
6167
*
6268
* @param int $offset The offset to remove
69+
*
70+
* @return void
6371
*/
6472
public function remove(int $offset);
6573
}

Constraints/NoSuspiciousCharactersValidator.php

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public function __construct(private readonly array $defaultLocales = [])
5656
{
5757
}
5858

59+
/**
60+
* @return void
61+
*/
5962
public function validate(mixed $value, Constraint $constraint)
6063
{
6164
if (!$constraint instanceof NoSuspiciousCharacters) {

Context/ExecutionContextInterface.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* When you make another call to the validator, while the validation is in
3030
* progress, the violations will be isolated from each other:
3131
*
32-
* public function validate(mixed $value, Constraint $constraint)
32+
* public function validate(mixed $value, Constraint $constraint): void
3333
* {
3434
* $validator = $this->context->getValidator();
3535
*
@@ -40,7 +40,7 @@
4040
* However, if you want to add the violations to the current context, use the
4141
* {@link ValidatorInterface::inContext()} method:
4242
*
43-
* public function validate(mixed $value, Constraint $constraint)
43+
* public function validate(mixed $value, Constraint $constraint): void
4444
* {
4545
* $validator = $this->context->getValidator();
4646
*
@@ -93,7 +93,7 @@ public function buildViolation(string $message, array $parameters = []): Constra
9393
*
9494
* Useful if you want to validate additional constraints:
9595
*
96-
* public function validate(mixed $value, Constraint $constraint)
96+
* public function validate(mixed $value, Constraint $constraint): void
9797
* {
9898
* $validator = $this->context->getValidator();
9999
*

ObjectInitializerInterface.php

+3
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@
2222
*/
2323
interface ObjectInitializerInterface
2424
{
25+
/**
26+
* @return void
27+
*/
2528
public function initialize(object $object);
2629
}

Tests/ConstraintValidatorTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static function formatValueProvider()
5656

5757
final class TestFormatValueConstraintValidator extends ConstraintValidator
5858
{
59-
public function validate($value, Constraint $constraint)
59+
public function validate($value, Constraint $constraint): void
6060
{
6161
}
6262

Tests/Fixtures/DummyConstraintValidator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class DummyConstraintValidator extends ConstraintValidator
1818
{
19-
public function validate($value, Constraint $constraint)
19+
public function validate($value, Constraint $constraint): void
2020
{
2121
}
2222
}

Tests/Fixtures/FailingConstraintValidator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class FailingConstraintValidator extends ConstraintValidator
1818
{
19-
public function validate($value, Constraint $constraint)
19+
public function validate($value, Constraint $constraint): void
2020
{
2121
$this->context->addViolation($constraint->message, []);
2222
}

Tests/Test/ConstraintValidatorTestCaseTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function testAssertingContextualValidatorRemainingExpectationsThrow()
5555

5656
class TestCustomValidator extends ConstraintValidator
5757
{
58-
public function validate($value, Constraint $constraint)
58+
public function validate($value, Constraint $constraint): void
5959
{
6060
$validator = $this->context
6161
->getValidator()

Tests/Validator/RecursiveValidatorTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2362,7 +2362,7 @@ final class TestConstraintHashesDoNotCollide extends Constraint
23622362

23632363
final class TestConstraintHashesDoNotCollideValidator extends ConstraintValidator
23642364
{
2365-
public function validate($value, Constraint $constraint)
2365+
public function validate($value, Constraint $constraint): void
23662366
{
23672367
if (!$value instanceof Entity) {
23682368
throw new \LogicException();

Violation/ConstraintViolationBuilderInterface.php

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public function setCause(mixed $cause): static;
107107

108108
/**
109109
* Adds the violation to the current execution context.
110+
*
111+
* @return void
110112
*/
111113
public function addViolation();
112114
}

0 commit comments

Comments
 (0)