Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 7a3971a

Browse files
committed
chore: improved interfaces methods return value type
1 parent 254934a commit 7a3971a

File tree

2 files changed

+28
-33
lines changed

2 files changed

+28
-33
lines changed

src/ChainedValidatorInterface.php

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@
77

88
interface ChainedValidatorInterface
99
{
10-
/**
11-
* @throws ValidationException
12-
*/
13-
public function assert(mixed $value, string $name): void;
14-
15-
public function validate(mixed $value): bool;
16-
17-
// --- Rules ---
18-
1910
public function choice(
2011
array $constraints,
2112
bool $multiple = false,
@@ -25,59 +16,61 @@ public function choice(
2516
string $multipleMessage = 'The "{{ name }}" value has one or more invalid choices, "{{ value }}" given. Accepted values are: "{{ constraints }}".',
2617
string $minMessage = 'The "{{ name }}" value must have at least {{ minConstraint }} choices, {{ numValues }} choices given.',
2718
string $maxMessage = 'The "{{ name }}" value must have at most {{ maxConstraint }} choices, {{ numValues }} choices given.'
28-
): ChainedValidatorInterface;
19+
): ChainedValidatorInterface&Validator;
2920

3021
public function country(
3122
string $code = 'alpha-2',
3223
string $message = 'The "{{ name }}" value is not a valid "{{ code }}" country code, "{{ value }}" given.'
33-
): ChainedValidatorInterface;
24+
): ChainedValidatorInterface&Validator;
3425

3526
public function eachValue(
3627
Validator $validator,
3728
string $message = 'At key "{{ key }}": {{ message }}'
38-
): ChainedValidatorInterface;
29+
): ChainedValidatorInterface&Validator;
3930

4031
public function greaterThan(
4132
mixed $constraint,
4233
string $message = 'The "{{ name }}" value should be greater than "{{ constraint }}", "{{ value }}" given.'
43-
): ChainedValidatorInterface;
34+
): ChainedValidatorInterface&Validator;
4435

4536
public function greaterThanOrEqual(
4637
mixed $constraint,
4738
string $message = 'The "{{ name }}" value should be greater than or equal to "{{ constraint }}", "{{ value }}" given.'
48-
): ChainedValidatorInterface;
39+
): ChainedValidatorInterface&Validator;
4940

5041
public function lessThan(
5142
mixed $constraint,
5243
string $message = 'The "{{ name }}" value should be less than "{{ constraint }}", "{{ value }}" given.'
53-
): ChainedValidatorInterface;
44+
): ChainedValidatorInterface&Validator;
5445

5546
public function lessThanOrEqual(
5647
mixed $constraint,
5748
string $message = 'The "{{ name }}" value should be less than or equal to "{{ constraint }}", "{{ value }}" given.'
58-
): ChainedValidatorInterface;
49+
): ChainedValidatorInterface&Validator;
5950

6051
public function notBlank(
6152
?callable $normalizer = null,
6253
string $message = 'The "{{ name }}" value should not be blank, "{{ value }}" given.'
63-
): ChainedValidatorInterface;
54+
): ChainedValidatorInterface&Validator;
6455

6556
public function range(
6657
mixed $minConstraint,
6758
mixed $maxConstraint,
6859
string $message = 'The "{{ name }}" value should be between "{{ minConstraint }}" and "{{ maxConstraint }}", "{{ value }}" given.'
69-
): ChainedValidatorInterface;
60+
): ChainedValidatorInterface&Validator;
7061

71-
public function rule(RuleInterface $constraint): ChainedValidatorInterface;
62+
public function rule(
63+
RuleInterface $constraint
64+
): ChainedValidatorInterface&Validator;
7265

7366
public function timezone(
7467
int $timezoneGroup = \DateTimeZone::ALL,
7568
?string $countryCode = null,
7669
string $message = 'The "{{ name }}" value is not a valid timezone, "{{ value }}" given.'
77-
): ChainedValidatorInterface;
70+
): ChainedValidatorInterface&Validator;
7871

7972
public function type(
8073
string|array $constraint,
8174
string $message = 'The "{{ name }}" value should be of type "{{ constraint }}", "{{ value }}" given.'
82-
): ChainedValidatorInterface;
75+
): ChainedValidatorInterface&Validator;
8376
}

src/StaticValidatorInterface.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,59 +15,61 @@ public static function choice(
1515
string $multipleMessage = 'The "{{ name }}" value has one or more invalid choices, "{{ value }}" given. Accepted values are: "{{ constraints }}".',
1616
string $minMessage = 'The "{{ name }}" value must have at least {{ minConstraint }} choices, {{ numValues }} choices given.',
1717
string $maxMessage = 'The "{{ name }}" value must have at most {{ maxConstraint }} choices, {{ numValues }} choices given.'
18-
): ChainedValidatorInterface;
18+
): ChainedValidatorInterface&Validator;
1919

2020
public static function country(
2121
string $code = 'alpha-2',
2222
string $message = 'The "{{ name }}" value is not a valid "{{ code }}" country code, "{{ value }}" given.'
23-
): ChainedValidatorInterface;
23+
): ChainedValidatorInterface&Validator;
2424

2525
public static function eachValue(
2626
Validator $validator,
2727
string $message = 'At key "{{ key }}": {{ message }}'
28-
): ChainedValidatorInterface;
28+
): ChainedValidatorInterface&Validator;
2929

3030
public static function greaterThan(
3131
mixed $constraint,
3232
string $message = 'The "{{ name }}" value should be greater than "{{ constraint }}", "{{ value }}" given.'
33-
): ChainedValidatorInterface;
33+
): ChainedValidatorInterface&Validator;
3434

3535
public static function greaterThanOrEqual(
3636
mixed $constraint,
3737
string $message = 'The "{{ name }}" value should be greater than or equal to "{{ constraint }}", "{{ value }}" given.'
38-
): ChainedValidatorInterface;
38+
): ChainedValidatorInterface&Validator;
3939

4040
public static function lessThan(
4141
mixed $constraint,
4242
string $message = 'The "{{ name }}" value should be less than "{{ constraint }}", "{{ value }}" given.'
43-
): ChainedValidatorInterface;
43+
): ChainedValidatorInterface&Validator;
4444

4545
public static function lessThanOrEqual(
4646
mixed $constraint,
4747
string $message = 'The "{{ name }}" value should be less than or equal to "{{ constraint }}", "{{ value }}" given.'
48-
): ChainedValidatorInterface;
48+
): ChainedValidatorInterface&Validator;
4949

5050
public static function notBlank(
5151
?callable $normalizer = null,
5252
string $message = 'The "{{ name }}" value should not be blank, "{{ value }}" given.'
53-
): ChainedValidatorInterface;
53+
): ChainedValidatorInterface&Validator;
5454

5555
public static function range(
5656
mixed $minConstraint,
5757
mixed $maxConstraint,
5858
string $message = 'The "{{ name }}" value should be between "{{ minConstraint }}" and "{{ maxConstraint }}", "{{ value }}" given.'
59-
): ChainedValidatorInterface;
59+
): ChainedValidatorInterface&Validator;
6060

61-
public static function rule(RuleInterface $constraint): ChainedValidatorInterface;
61+
public static function rule(
62+
RuleInterface $constraint
63+
): ChainedValidatorInterface&Validator;
6264

6365
public static function timezone(
6466
int $timezoneGroup = \DateTimeZone::ALL,
6567
?string $countryCode = null,
6668
string $message = 'The "{{ name }}" value is not a valid timezone, "{{ value }}" given.'
67-
): ChainedValidatorInterface;
69+
): ChainedValidatorInterface&Validator;
6870

6971
public static function type(
7072
string|array $constraint,
7173
string $message = 'The "{{ name }}" value should be of type "{{ constraint }}", "{{ value }}" given.'
72-
): ChainedValidatorInterface;
74+
): ChainedValidatorInterface&Validator;
7375
}

0 commit comments

Comments
 (0)