Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 73e8ceb

Browse filesBrowse files
committed
[Validator] Add PHPDoc to validator constraints
1 parent 5f77c3f commit 73e8ceb
Copy full SHA for 73e8ceb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner

70 files changed

+692
-12
lines changed

‎src/Symfony/Component/Validator/Attribute/HasNamedArguments.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Attribute/HasNamedArguments.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
namespace Symfony\Component\Validator\Attribute;
1313

14+
/**
15+
* Hint the loader that some constraint options are required.
16+
*
17+
* @see https://symfony.com/doc/current/validation/custom_constraint.html
18+
*/
1419
#[\Attribute(\Attribute::TARGET_METHOD)]
1520
final class HasNamedArguments
1621
{

‎src/Symfony/Component/Validator/Constraints/All.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/All.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@
1111

1212
namespace Symfony\Component\Validator\Constraints;
1313

14+
use Symfony\Component\Validator\Constraint;
15+
1416
/**
17+
* When applied to an array (or Traversable object), this constraint allows you to apply
18+
* a collection of constraints to each element of the array.
19+
*
1520
* @Annotation
21+
*
1622
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
1723
*
1824
* @author Bernhard Schussek <bschussek@gmail.com>
@@ -22,6 +28,11 @@ class All extends Composite
2228
{
2329
public $constraints = [];
2430

31+
/**
32+
* @param array<Constraint>|array<string,mixed>|null $constraints An array of validation constraints, or this constraint's options as an associative array
33+
* @param string[]|null $groups An array of validation groups
34+
* @param mixed|null $payload Domain-specific data attached to a constraint
35+
*/
2536
public function __construct(mixed $constraints = null, array $groups = null, mixed $payload = null)
2637
{
2738
parent::__construct($constraints ?? [], $groups, $payload);

‎src/Symfony/Component/Validator/Constraints/AtLeastOneOf.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/AtLeastOneOf.php
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@
1111

1212
namespace Symfony\Component\Validator\Constraints;
1313

14+
use Symfony\Component\Validator\Constraint;
15+
1416
/**
17+
* Checks that at least one of the given constraint is satisfied.
18+
*
1519
* @Annotation
20+
*
1621
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
1722
*
1823
* @author Przemysław Bogusz <przemyslaw.bogusz@tubotax.pl>
@@ -36,6 +41,14 @@ class AtLeastOneOf extends Composite
3641
public $messageCollection = 'Each element of this collection should satisfy its own set of constraints.';
3742
public $includeInternalMessages = true;
3843

44+
/**
45+
* @param array<Constraint>|array<string,mixed>|null $constraints An array of validation constraints, or this constraint's options as an associative array
46+
* @param string[]|null $groups An array of validation groups
47+
* @param mixed|null $payload Domain-specific data attached to a constraint
48+
* @param string|null $message Intro of the failure message that will be followed by the failed constraint(s) message(s)
49+
* @param string|null $messageCollection Failure message for All and Collection inner constraints
50+
* @param bool|null $includeInternalMessages Whether to include inner constraint messages
51+
*/
3952
public function __construct(mixed $constraints = null, array $groups = null, mixed $payload = null, string $message = null, string $messageCollection = null, bool $includeInternalMessages = null)
4053
{
4154
parent::__construct($constraints ?? [], $groups, $payload);

‎src/Symfony/Component/Validator/Constraints/Bic.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/Bic.php
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
use Symfony\Component\Validator\Exception\LogicException;
1919

2020
/**
21+
* Ensure that the value is valid against the BIC format.
22+
*
23+
* @see https://en.wikipedia.org/wiki/ISO_9362
24+
*
2125
* @Annotation
26+
*
2227
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
2328
*
2429
* @author Michael Hirschler <michael.vhirsch@gmail.com>
@@ -51,6 +56,15 @@ class Bic extends Constraint
5156
public $iban;
5257
public $ibanPropertyPath;
5358

59+
/**
60+
* @param array<string,mixed>|null $options The options as an associative array
61+
* @param string|null $message The message if the validation fails
62+
* @param string|null $iban An IBAN value to validate that its country code is the same as the BIC's one
63+
* @param string|null $ibanPropertyPath Property path to the IBAN value when validating objects
64+
* @param string|null $ibanMessage Default message when the combined BIC/IBAN check does not pass
65+
* @param string[]|null $groups An array of validation groups
66+
* @param mixed|null $payload Domain-specific data attached to a constraint
67+
*/
5468
public function __construct(array $options = null, string $message = null, string $iban = null, string $ibanPropertyPath = null, string $ibanMessage = null, array $groups = null, mixed $payload = null)
5569
{
5670
if (!class_exists(Countries::class)) {

‎src/Symfony/Component/Validator/Constraints/Blank.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/Blank.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
use Symfony\Component\Validator\Constraint;
1515

1616
/**
17+
* Validate that a value is blank, i.e. an empty string or null.
18+
*
1719
* @Annotation
20+
*
1821
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
1922
*
2023
* @author Bernhard Schussek <bschussek@gmail.com>
@@ -35,6 +38,12 @@ class Blank extends Constraint
3538

3639
public $message = 'This value should be blank.';
3740

41+
/**
42+
* @param array<string,mixed>|null $options The options as an associative array
43+
* @param string|null $message The message if the validation fails
44+
* @param string[]|null $groups An array of validation groups
45+
* @param mixed|null $payload Domain-specific data attached to a constraint
46+
*/
3847
public function __construct(array $options = null, string $message = null, array $groups = null, mixed $payload = null)
3948
{
4049
parent::__construct($options ?? [], $groups, $payload);

‎src/Symfony/Component/Validator/Constraints/Callback.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/Callback.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
use Symfony\Component\Validator\Constraint;
1515

1616
/**
17+
* Define custom validation rules through arbitrary callback methods.
18+
*
1719
* @Annotation
20+
*
1821
* @Target({"CLASS", "PROPERTY", "METHOD", "ANNOTATION"})
1922
*
2023
* @author Bernhard Schussek <bschussek@gmail.com>
@@ -27,6 +30,12 @@ class Callback extends Constraint
2730
*/
2831
public $callback;
2932

33+
/**
34+
* @param string|string[]|callable|array<string,mixed>|null $callback The callback definition, or this constraint's options as an associative array
35+
* @param string[]|null $groups An array of validation groups
36+
* @param mixed|null $payload Domain-specific data attached to a constraint
37+
* @param array $options The options as an associative array
38+
*/
3039
public function __construct(array|string|callable $callback = null, array $groups = null, mixed $payload = null, array $options = [])
3140
{
3241
// Invocation through annotations with an array parameter only

‎src/Symfony/Component/Validator/Constraints/CardScheme.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/CardScheme.php
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
use Symfony\Component\Validator\Constraint;
1515

1616
/**
17-
* Metadata for the CardSchemeValidator.
17+
* Validates a credit card number for a given credit card company.
1818
*
1919
* @Annotation
20+
*
2021
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
2122
*
2223
* @author Tim Nagel <t.nagel@infinite.net.au>
@@ -54,6 +55,13 @@ class CardScheme extends Constraint
5455
public $message = 'Unsupported card type or invalid card number.';
5556
public $schemes;
5657

58+
/**
59+
* @param string|string[]|array<string,mixed>|null $schemes Name(s) of the number scheme(s) used to validate the credit card number, or this constraint's options as an associative array
60+
* @param string|null $message The message if the validation fails
61+
* @param string[]|null $groups An array of validation groups
62+
* @param mixed|null $payload Domain-specific data attached to a constraint
63+
* @param array<string,mixed> $options The options as an associative array
64+
*/
5765
public function __construct(array|string|null $schemes, string $message = null, array $groups = null, mixed $payload = null, array $options = [])
5866
{
5967
if (\is_array($schemes) && \is_string(key($schemes))) {

‎src/Symfony/Component/Validator/Constraints/Cascade.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/Cascade.php
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
1616

1717
/**
18+
* Validates a whole class, including nested objects in properties.
19+
*
1820
* @Annotation
21+
*
1922
* @Target({"CLASS"})
2023
*
2124
* @author Jules Pietri <jules@heahprod.com>
@@ -25,10 +28,14 @@ class Cascade extends Constraint
2528
{
2629
public array $exclude = [];
2730

31+
/**
32+
* @param string[]|string|array<string,mixed>|null $exclude Properties excluded from validation
33+
* @param array<string,mixed>|null $options The options as an associative array
34+
*/
2835
public function __construct(array|string $exclude = null, array $options = null)
2936
{
3037
if (\is_array($exclude) && !array_is_list($exclude)) {
31-
$options = array_merge($exclude, $options);
38+
$options = array_merge($exclude, $options ?? []);
3239
} else {
3340
$this->exclude = array_flip((array) $exclude);
3441
}

‎src/Symfony/Component/Validator/Constraints/Choice.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/Choice.php
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
use Symfony\Component\Validator\Constraint;
1515

1616
/**
17+
* Validates that a value is one of a given set of valid choices.
18+
*
1719
* @Annotation
20+
*
1821
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
1922
*
2023
* @author Bernhard Schussek <bschussek@gmail.com>
@@ -55,6 +58,22 @@ public function getDefaultOption(): ?string
5558
return 'choices';
5659
}
5760

61+
/**
62+
* @param string|array $options The options (as associative array) or the array of choices
63+
* @param array|null $choices An array of choices
64+
* @param callable|string|null $callback Callback method to use instead of the choice option to get the choices
65+
* @param bool|null $multiple Whether to expect the value to be an array of valid choices
66+
* @param bool|null $strict This option defaults to <pre>true</pre> and should not be used
67+
* @param int|null $min Minimum of valid choices if multiple values are expected
68+
* @param int|null $max Maximum of valid choices if multiple values are expected
69+
* @param string|null $message The message if the validation fails
70+
* @param string|null $multipleMessage Message if some of the choices are not valid
71+
* @param string|null $minMessage Message if there are too few choices
72+
* @param string|null $maxMessage Message if there are too many choices
73+
* @param string[]|null $groups An array of validation groups
74+
* @param mixed|null $payload Domain-specific data attached to a constraint
75+
* @param bool|null $match Validate values that are not part of given choices
76+
*/
5877
public function __construct(
5978
string|array $options = [],
6079
array $choices = null,

‎src/Symfony/Component/Validator/Constraints/Cidr.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/Cidr.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
/**
1818
* Validates that a value is a valid CIDR notation.
1919
*
20+
* @see https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
21+
*
2022
* @Annotation
23+
*
2124
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
2225
*
2326
* @author Sorin Pop <popsorin15@gmail.com>
@@ -55,6 +58,15 @@ class Cidr extends Constraint
5558

5659
public $netmaskMax;
5760

61+
/**
62+
* @param array<string,mixed>|null $options The options as an associative array
63+
* @param string|null $version The CIDR version to validate (4, 6 or all)
64+
* @param int|null $netmaskMin The lowest valid for a valid netmask
65+
* @param int|null $netmaskMax The biggest valid for a valid netmask
66+
* @param string|null $message The message if the validation fails
67+
* @param string[]|null $groups An array of validation groups
68+
* @param mixed|null $payload Domain-specific data attached to a constraint
69+
*/
5870
public function __construct(
5971
array $options = null,
6072
string $version = null,

‎src/Symfony/Component/Validator/Constraints/Collection.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/Collection.php
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111

1212
namespace Symfony\Component\Validator\Constraints;
1313

14+
use Symfony\Component\Validator\Constraint;
1415
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
1516

1617
/**
18+
* Validates a collection with constraints defined for specific keys.
19+
*
1720
* @Annotation
21+
*
1822
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
1923
*
2024
* @author Bernhard Schussek <bschussek@gmail.com>
@@ -41,6 +45,15 @@ class Collection extends Composite
4145
public $extraFieldsMessage = 'This field was not expected.';
4246
public $missingFieldsMessage = 'This field is missing.';
4347

48+
/**
49+
* @param array<string,Constraint>|array<string,mixed>|null $fields An associative array defining keys in the collection and their constraints, or this constraint's options as an associative array
50+
* @param string[]|null $groups An array of validation groups
51+
* @param mixed|null $payload Domain-specific data attached to a constraint
52+
* @param bool|null $allowExtraFields Whether to allow additional keys not declared in the configured fields
53+
* @param bool|null $allowMissingFields Whether to allow the collection to lack some fields declared in the configured fields
54+
* @param string|null $extraFieldsMessage The message if extra fields are not allowed and the data contains extra fields
55+
* @param string|null $missingFieldsMessage The message if missing fields are not allowed and the data lacks some fields
56+
*/
4457
public function __construct(mixed $fields = null, array $groups = null, mixed $payload = null, bool $allowExtraFields = null, bool $allowMissingFields = null, string $extraFieldsMessage = null, string $missingFieldsMessage = null)
4558
{
4659
// no known options set? $fields is the fields array

‎src/Symfony/Component/Validator/Constraints/Count.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/Count.php
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
use Symfony\Component\Validator\Exception\MissingOptionsException;
1616

1717
/**
18+
* Validates a collection's element count.
19+
*
1820
* @Annotation
21+
*
1922
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
2023
*
2124
* @author Bernhard Schussek <bschussek@gmail.com>
@@ -48,6 +51,19 @@ class Count extends Constraint
4851
public $max;
4952
public $divisibleBy;
5053

54+
/**
55+
* @param int|array<string,mixed>|null $exactly The exact expected number of elements, or this constraint's options as an associative array
56+
* @param int|null $min Minimum expected number of elements
57+
* @param int|null $max Maximum expected number of elements
58+
* @param int|null $divisibleBy The number the collection count should be divisible by
59+
* @param string|null $exactMessage Message if the collection count should be exactly
60+
* @param string|null $minMessage Message if the collection has fewer values than the min
61+
* @param string|null $maxMessage Message if the collection has more values than the max
62+
* @param string|null $divisibleByMessage Message if the count is not divisible by the divisibleBy value
63+
* @param string[]|null $groups An array of validation groups
64+
* @param mixed|null $payload Domain-specific data attached to a constraint
65+
* @param array<mixed,string> $options The options (as associative array)
66+
*/
5167
public function __construct(
5268
int|array $exactly = null,
5369
int $min = null,

‎src/Symfony/Component/Validator/Constraints/Country.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/Country.php
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
use Symfony\Component\Validator\Exception\LogicException;
1717

1818
/**
19+
* Validates a value is a valid ISO 3166-1 alpha-2 country code.
20+
*
21+
* @see https://en.wikipedia.org/wiki/ISO_3166-1#Current_codes
22+
*
1923
* @Annotation
24+
*
2025
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
2126
*
2227
* @author Bernhard Schussek <bschussek@gmail.com>
@@ -38,6 +43,15 @@ class Country extends Constraint
3843
public $message = 'This value is not a valid country.';
3944
public $alpha3 = false;
4045

46+
/**
47+
* @param array<string,mixed>|null $options The options as associative array
48+
* @param string|null $message The message if the validation fails
49+
* @param bool|null $alpha3 Whether to check for alpha-3 codes instead of alpha-2
50+
* @param string[]|null $groups An array of validation groups
51+
* @param mixed|null $payload Domain-specific data attached to a constraint
52+
*
53+
* @see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3#Current_codes
54+
*/
4155
public function __construct(
4256
array $options = null,
4357
string $message = null,

‎src/Symfony/Component/Validator/Constraints/CssColor.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/CssColor.php
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
use Symfony\Component\Validator\Exception\InvalidArgumentException;
1616

1717
/**
18+
* Validates that a value is a valid CSS color.
19+
*
1820
* @Annotation
21+
*
1922
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
2023
*
2124
* @author Mathieu Santostefano <msantostefano@protonmail.com>
@@ -68,9 +71,13 @@ class CssColor extends Constraint
6871
public $formats;
6972

7073
/**
71-
* @param array|string $formats The types of CSS colors allowed (e.g. hexadecimal only, RGB and HSL only, etc.).
74+
* @param string[]|string|array<string,mixed> $formats The types of CSS colors allowed (e.g. hexadecimal only, RGB, HSL only, etc.), or this constraint's options as an associative array
75+
* @param string|null $message The message if the validation fails
76+
* @param string[]|null $groups An array of validation groups
77+
* @param mixed|null $payload Domain-specific data attached to a constraint
78+
* @param array<string,mixed>|null $options The options as an associative array
7279
*/
73-
public function __construct($formats = [], string $message = null, array $groups = null, $payload = null, array $options = null)
80+
public function __construct(array|string $formats = [], string $message = null, array $groups = null, mixed $payload = null, array $options = null)
7481
{
7582
$validationModesAsString = implode(', ', self::$validationModes);
7683

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.