Skip to content

[Validator] Add more precise PHPDoc on constraints #58049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Symfony/Component/Validator/Constraints/CardScheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class CardScheme extends Constraint
public array|string|null $schemes = null;

/**
* @param string|string[]|array<string,mixed>|null $schemes Name(s) of the number scheme(s) used to validate the credit card number
* @param string[]|null $groups
* @param array<string,mixed> $options
* @param non-empty-string|non-empty-string[]|array<string,mixed>|null $schemes Name(s) of the number scheme(s) used to validate the credit card number
* @param string[]|null $groups
* @param array<string,mixed> $options
*/
public function __construct(array|string|null $schemes, ?string $message = null, ?array $groups = null, mixed $payload = null, array $options = [])
{
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Validator/Constraints/Cascade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class Cascade extends Constraint
public array $exclude = [];

/**
* @param string[]|string|array<string,mixed>|null $exclude Properties excluded from validation
* @param array<string,mixed>|null $options
* @param non-empty-string[]|non-empty-string|array<string,mixed>|null $exclude Properties excluded from validation
* @param array<string,mixed>|null $options
*/
public function __construct(array|string|null $exclude = null, ?array $options = null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Validator/Constraints/Choice.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public function getDefaultOption(): ?string
* @param callable|string|null $callback Callback method to use instead of the choice option to get the choices
* @param bool|null $multiple Whether to expect the value to be an array of valid choices (defaults to false)
* @param bool|null $strict This option defaults to true and should not be used
* @param int|null $min Minimum of valid choices if multiple values are expected
* @param int|null $max Maximum of valid choices if multiple values are expected
* @param int<0, max>|null $min Minimum of valid choices if multiple values are expected
* @param positive-int|null $max Maximum of valid choices if multiple values are expected
* @param string[]|null $groups
* @param bool|null $match Whether to validate the values are part of the choices or not (defaults to true)
*/
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/Validator/Constraints/Count.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ class Count extends Constraint
public ?int $divisibleBy = null;

/**
* @param int|array<string,mixed>|null $exactly The exact expected number of elements
* @param int|null $min Minimum expected number of elements
* @param int|null $max Maximum expected number of elements
* @param int|null $divisibleBy The number the collection count should be divisible by
* @param string[]|null $groups
* @param array<mixed,string> $options
* @param int<0, max>|array<string,mixed>|null $exactly The exact expected number of elements
* @param int<0, max>|null $min Minimum expected number of elements
* @param positive-int|null $max Maximum expected number of elements
* @param positive-int|null $divisibleBy The number the collection count should be divisible by
* @param string[]|null $groups
* @param array<mixed,string> $options
*/
public function __construct(
int|array|null $exactly = null,
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Validator/Constraints/CssColor.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class CssColor extends Constraint
public array|string $formats;

/**
* @param string[]|string|array<string,mixed> $formats The types of CSS colors allowed ({@see https://symfony.com/doc/current/reference/constraints/CssColor.html#formats})
* @param string[]|null $groups
* @param array<string,mixed>|null $options
* @param non-empty-string[]|non-empty-string|array<string,mixed> $formats The types of CSS colors allowed ({@see https://symfony.com/doc/current/reference/constraints/CssColor.html#formats})
* @param string[]|null $groups
* @param array<string,mixed>|null $options
*/
public function __construct(array|string $formats = [], ?string $message = null, ?array $groups = null, $payload = null, ?array $options = null)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Validator/Constraints/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class DateTime extends Constraint
public string $message = 'This value is not a valid datetime.';

/**
* @param string|array<string,mixed>|null $format The datetime format to match (defaults to 'Y-m-d H:i:s')
* @param string[]|null $groups
* @param array<string,mixed> $options
* @param non-empty-string|array<string,mixed>|null $format The datetime format to match (defaults to 'Y-m-d H:i:s')
* @param string[]|null $groups
* @param array<string,mixed> $options
*/
public function __construct(string|array|null $format = null, ?string $message = null, ?array $groups = null, mixed $payload = null, array $options = [])
{
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Expression extends Constraint
* @param array<string,mixed>|null $values The values of the custom variables used in the expression (defaults to an empty array)
* @param string[]|null $groups
* @param array<string,mixed> $options
* @param bool|null $negate Whether to fail is the expression evaluates to true (defaults to false)
* @param bool|null $negate Whether to fail if the expression evaluates to true (defaults to false)
*/
public function __construct(
string|ExpressionObject|array|null $expression,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ExpressionSyntax extends Constraint

/**
* @param array<string,mixed>|null $options
* @param string|null $service The service used to validate the constraint instead of the default one
* @param non-empty-string|null $service The service used to validate the constraint instead of the default one
* @param string[]|null $allowedVariables Restrict the available variables in the expression to these values (defaults to null that allows any variable)
* @param string[]|null $groups
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Validator/Constraints/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ class File extends Constraint

/**
* @param array<string,mixed>|null $options
* @param int|string|null $maxSize The max size of the underlying file
* @param positive-int|string|null $maxSize The max size of the underlying file
* @param bool|null $binaryFormat Pass true to use binary-prefixed units (KiB, MiB, etc.) or false to use SI-prefixed units (kB, MB) in displayed messages. Pass null to guess the format from the maxSize option. (defaults to null)
* @param string[]|string|null $mimeTypes Acceptable media type(s). Prefer the extensions option that also enforce the file's extension consistency.
* @param int|null $filenameMaxLength Maximum length of the file name
* @param positive-int|null $filenameMaxLength Maximum length of the file name
* @param string|null $disallowEmptyMessage Enable empty upload validation with this message in case of error
* @param string|null $uploadIniSizeErrorMessage Message if the file size exceeds the max size configured in php.ini
* @param string|null $uploadFormSizeErrorMessage Message if the file size exceeds the max size configured in the HTML input field
Expand Down
22 changes: 11 additions & 11 deletions src/Symfony/Component/Validator/Constraints/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ class Image extends File

/**
* @param array<string,mixed>|null $options
* @param int|string|null $maxSize The max size of the underlying file
* @param positive-int|string|null $maxSize The max size of the underlying file
* @param bool|null $binaryFormat Pass true to use binary-prefixed units (KiB, MiB, etc.) or false to use SI-prefixed units (kB, MB) in displayed messages. Pass null to guess the format from the maxSize option. (defaults to null)
* @param string[]|null $mimeTypes Acceptable media types
* @param int|null $filenameMaxLength Maximum length of the file name
* @param non-empty-string[]|null $mimeTypes Acceptable media types
* @param positive-int|null $filenameMaxLength Maximum length of the file name
* @param string|null $disallowEmptyMessage Enable empty upload validation with this message in case of error
* @param string|null $uploadIniSizeErrorMessage Message if the file size exceeds the max size configured in php.ini
* @param string|null $uploadFormSizeErrorMessage Message if the file size exceeds the max size configured in the HTML input field
Expand All @@ -102,14 +102,14 @@ class Image extends File
* @param string|null $uploadCantWriteErrorMessage Message if the uploaded file can not be stored in the temporary directory
* @param string|null $uploadErrorMessage Message if an unknown error occurred on upload
* @param string[]|null $groups
* @param int|null $minWidth Minimum image width
* @param int|null $maxWidth Maximum image width
* @param int|null $maxHeight Maximum image height
* @param int|null $minHeight Minimum image weight
* @param int|float|null $maxRatio Maximum image ratio
* @param int|float|null $minRatio Minimum image ration
* @param int|float|null $minPixels Minimum amount of pixels
* @param int|float|null $maxPixels Maximum amount of pixels
* @param int<0, int>|null $minWidth Minimum image width
* @param positive-int|null $maxWidth Maximum image width
* @param positive-int|null $maxHeight Maximum image height
* @param int<0, int>|null $minHeight Minimum image weight
* @param positive-int|float|null $maxRatio Maximum image ratio
* @param int<0, max>|float|null $minRatio Minimum image ration
* @param int<0, max>|float|null $minPixels Minimum amount of pixels
* @param positive-int|float|null $maxPixels Maximum amount of pixels
* @param bool|null $allowSquare Whether to allow a square image (defaults to true)
* @param bool|null $allowLandscape Whether to allow a landscape image (defaults to true)
* @param bool|null $allowPortrait Whether to allow a portrait image (defaults to true)
Expand Down
16 changes: 8 additions & 8 deletions src/Symfony/Component/Validator/Constraints/Length.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ class Length extends Constraint
public string $countUnit = self::COUNT_CODEPOINTS;

/**
* @param int|array<string,mixed>|null $exactly The exact expected length
* @param int|null $min The minimum expected length
* @param int|null $max The maximum expected length
* @param string|null $charset The charset to be used when computing value's length (defaults to UTF-8)
* @param callable|null $normalizer A callable to normalize value before it is validated
* @param self::COUNT_*|null $countUnit The character count unit for the length check (defaults to {@see Length::COUNT_CODEPOINTS})
* @param string[]|null $groups
* @param array<string,mixed> $options
* @param positive-int|array<string,mixed>|null $exactly The exact expected length
* @param int<0, max>|null $min The minimum expected length
* @param positive-int|null $max The maximum expected length
* @param string|null $charset The charset to be used when computing value's length (defaults to UTF-8)
* @param callable|null $normalizer A callable to normalize value before it is validated
* @param self::COUNT_*|null $countUnit The character count unit for the length check (defaults to {@see Length::COUNT_CODEPOINTS})
* @param string[]|null $groups
* @param array<string,mixed> $options
*/
public function __construct(
int|array|null $exactly = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class NotCompromisedPassword extends Constraint

/**
* @param array<string,mixed>|null $options
* @param int|null $threshold The number of times the password should have been leaked to consider it is compromised (defaults to 1)
* @param positive-int|null $threshold The number of times the password should have been leaked to consider it is compromised (defaults to 1)
* @param bool|null $skipOnError Whether to ignore HTTP errors while requesting the API and thus consider the password valid (defaults to false)
* @param string[]|null $groups
*/
Expand Down
16 changes: 8 additions & 8 deletions src/Symfony/Component/Validator/Constraints/Range.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ class Range extends Constraint
public ?string $maxPropertyPath = null;

/**
* @param array<string,mixed>|null $options
* @param string|null $invalidMessage The message if min and max values are numeric but the given value is not
* @param string|null $invalidDateTimeMessage The message if min and max values are PHP datetimes but the given value is not
* @param int|float|string|null $min The minimum value, either numeric or a datetime string representation
* @param string|null $minPropertyPath Property path to the min value
* @param int|float|string|null $max The maximum value, either numeric or a datetime string representation
* @param string|null $maxPropertyPath Property path to the max value
* @param string[]|null $groups
* @param array<string,mixed>|null $options
* @param string|null $invalidMessage The message if min and max values are numeric but the given value is not
* @param string|null $invalidDateTimeMessage The message if min and max values are PHP datetimes but the given value is not
* @param int|float|non-empty-string|null $min The minimum value, either numeric or a datetime string representation
* @param non-empty-string|null $minPropertyPath Property path to the min value
* @param int|float|non-empty-string|null $max The maximum value, either numeric or a datetime string representation
* @param non-empty-string|null $maxPropertyPath Property path to the max value
* @param string[]|null $groups
*/
public function __construct(
?array $options = null,
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Week.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ final class Week extends Constraint
self::TOO_HIGH_ERROR => 'TOO_HIGH_ERROR',
];

/**
* @param non-empty-string|null $min
* @param non-empty-string|null $max
*/
#[HasNamedArguments]
public function __construct(
public ?string $min = null,
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Validator/Constraints/WordCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ final class WordCount extends Constraint
self::TOO_LONG_ERROR => 'TOO_LONG_ERROR',
];

/**
* @param int<0, max>|null $min
* @param positive-int|null $max
*/
#[HasNamedArguments]
public function __construct(
public ?int $min = null,
Expand Down
Loading