8000 minor #52012 [Validator] Add PHPDoc to validator constraints (squrious) · symfony/symfony@4086e81 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4086e81

Browse files
minor #52012 [Validator] Add PHPDoc to validator constraints (squrious)
This PR was squashed before being merged into the 7.1 branch. Discussion ---------- [Validator] Add PHPDoc to validator constraints | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Part of #51920 | License | MIT Add PHPDoc to Validator constraints attributes. Commits ------- 1a26ebe [Validator] Add PHPDoc to validator constraints
2 parents b92bdc0 + 1a26ebe commit 4086e81

Some content is hidden

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

69 files changed

+496
-10
lines changed

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

Lines 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+
* Hints 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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@
1414
use Symfony\Component\Validator\Constraint;
1515

1616
/**
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+
*
1720
* @author Bernhard Schussek <bschussek@gmail.com>
1821
*/
1922
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
2023
class All extends Composite
2124
{
2225
public array|Constraint $constraints = [];
2326

27+
/**
28+
* @param array<Constraint>|array<string,mixed>|null $constraints
29+
* @param string[]|null $groups
30+
*/
2431
public function __construct(mixed $constraints = null, array $groups = null, mixed $payload = null)
2532
{
2633
parent::__construct($constraints ?? [], $groups, $payload);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Symfony\Component\Validator\Constraint;
1515

1616
/**
17+
* Checks that at least one of the given constraint is satisfied.
18+
*
1719
* @author Przemysław Bogusz <przemyslaw.bogusz@tubotax.pl>
1820
*/
1921
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
@@ -30,6 +32,13 @@ class AtLeastOneOf extends Composite
3032
public string $messageCollection = 'Each element of this collection should satisfy its own set of constraints.';
3133
public bool $includeInternalMessages = true;
3234

35+
/**
36+
* @param array<Constraint>|array<string,mixed>|null $constraints An array of validation constraints
37+
* @param string[]|null $groups
38+
* @param string|null $message Intro of the failure message that will be followed by the failed constraint(s) message(s)
39+
* @param string|null $messageCollection Failure message for All and Collection inner constraints
40+
* @param bool|null $includeInternalMessages Whether to include inner constraint messages (defaults to true)
41+
*/
3342
public function __construct(mixed $constraints = null, array $groups = null, mixed $payload = null, string $message = null, string $messageCollection = null, bool $includeInternalMessages = null)
3443
{
3544
parent::__construct($constraints ?? [], $groups, $payload);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
use Symfony\Component\Validator\Exception\LogicException;
1919

2020
/**
21+
* Ensures that the value is valid against the BIC format.
22+
*
23+
* @see https://en.wikipedia.org/wiki/ISO_9362
24+
*
2125
* @author Michael Hirschler <michael.vhirsch@gmail.com>
2226
*/
2327
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
@@ -43,6 +47,12 @@ class Bic extends Constraint
4347
public ?string $iban = null;
4448
public ?string $ibanPropertyPath = null;
4549

50+
/**
51+
* @param array<string,mixed>|null $options
52+
* @param string|null $iban An IBAN value to validate that its country code is the same as the BIC's one
53+
* @param string|null $ibanPropertyPath Property path to the IBAN value when validating objects
54+
* @param string[]|null $groups
55+
*/
4656
public function __construct(array $options = null, string $message = null, string $iban = null, string $ibanPropertyPath = null, string $ibanMessage = null, array $groups = null, mixed $payload = null)
4757
{
4858
if (!class_exists(Countries::class)) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Symfony\Component\Validator\Constraint;
1515

1616
/**
17+
* Validates that a value is blank, i.e. an empty string or null.
18+
*
1719
* @author Bernhard Schussek <bschussek@gmail.com>
1820
*/
1921
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
@@ -27,6 +29,10 @@ class Blank extends Constraint
2729

2830
public string $message = 'This value should be blank.';
2931

32+
/**
33+
* @param array<string,mixed>|null $options
34+
* @param string[]|null $groups
35+
*/
3036
public function __construct(array $options = null, string $message = null, array $groups = null, mixed $payload = null)
3137
{
3238
parent::__construct($options ?? [], $groups, $payload);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Symfony\Component\Validator\Constraint;
1515

1616
/**
17+
* Defines custom validation rules through arbitrary callback methods.
18+
*
1719
* @author Bernhard Schussek <bschussek@gmail.com>
1820
*/
1921
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
@@ -24,6 +26,10 @@ class Callback extends Constraint
2426
*/
2527
public $callback;
2628

29+
/**
30+
* @param string|string[]|callable|array<string,mixed>|null $callback The callback definition
31+
* @param string[]|null $groups
32+
*/
2733
public function __construct(array|string|callable $callback = null, array $groups = null, mixed $payload = null, array $options = [])
2834
{
2935
// Invocation through attributes with an array parameter only

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
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
* @author Tim Nagel <t.nagel@infinite.net.au>
2020
* @author Bernhard Schussek <bschussek@gmail.com>
@@ -46,6 +46,11 @@ class CardScheme extends Constraint
4646
public string $message = 'Unsupported card type or invalid card number.';
4747
public array|string|null $schemes = null;
4848

49+
/**
50+
* @param string|string[]|array<string,mixed>|null $schemes Name(s) of the number scheme(s) used to validate the credit card number
51+
* @param string[]|null $groups
52+
* @param array<string,mixed> $options
53+
*/
4954
public function __construct(array|string|null $schemes, string $message = null, array $groups = null, mixed $payload = null, array $options = [])
5055
{
5156
if (\is_array($schemes) && \is_string(key($schemes))) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@
1515
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
1616

1717
/**
18+
* Validates a whole class, including nested objects in properties.
19+
*
1820
* @author Jules Pietri <jules@heahprod.com>
1921
*/
2022
#[\Attribute(\Attribute::TARGET_CLASS)]
2123
class Cascade extends Constraint
2224
{
2325
public array $exclude = [];
2426

27+
/**
28+
* @param string[]|string|array<string,mixed>|null $exclude Properties excluded from validation
29+
* @param array<string,mixed>|null $options
30+
*/
2531
public function __construct(array|string $exclude = null, array $options = null)
2632
{
2733
if (\is_array($exclude) && !array_is_list($exclude)) {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Symfony\Component\Validator\Constraint;
1515

1616
/**
17+
* Validates that a value is one of a given set of valid choices.
18+
*
1719
* @author Bernhard Schussek <bschussek@gmail.com>
1820
*/
1921
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
@@ -47,6 +49,16 @@ public function getDefaultOption(): ?string
4749
return 'choices';
4850
}
4951

52+
/**
53+
* @param array|null $choices An array of choices (required unless a callback is specified)
54+
* @param callable|string|null $callback Callback method to use instead of the choice option to get the choices
55+
* @param bool|null $multiple Whether to expect the value to be an array of valid choices (defaults to false)
56+
* @param bool|null $strict This option defaults to true and should not be used
57+
* @param int|null $min Minimum of valid choices if multiple values are expected
58+
* @param int|null $max Maximum of valid choices if multiple values are expected
59+
* @param string[]|null $groups
60+
* @param bool|null $match Whether to validate the values are part of the choices or not (defaults to true)
61+
*/
5062
public function __construct(
5163
string|array $options = [],
5264
array $choices = null,

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
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
* @author Sorin Pop <popsorin15@gmail.com>
2123
* @author Calin Bolea <calin.bolea@gmail.com>
2224
*/
@@ -43,6 +45,13 @@ class Cidr extends Constraint
4345
public int $netmaskMin = 0;
4446
public int $netmaskMax;
4547

48+
/**
49+
* @param array<string,mixed>|null $options
50+
* @param string|null $version The CIDR version to validate (4, 6 or all, defaults to all)
51+
* @param int|null $netmaskMin The lowest valid for a valid netmask (defaults to 0)
52+
* @param int|null $netmaskMax The biggest valid for a valid netmask (defaults to 32 for IPv4, 128 for IPv6)
53+
* @param string[]|null $groups
54+
*/
4655
public function __construct(
4756
array $options = null,
4857
string $version = null,

0 commit comments

Comments
 (0)
0