Skip to content

Commit

Permalink
use named-arguments to configure validation constraint options
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Jan 24, 2025
1 parent 171af72 commit de324eb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions reference/constraints/Email.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ Basic Usage
public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('email', new Assert\Email([
'message' => 'The email "{{ value }}" is not a valid email.',
]));
$metadata->addPropertyConstraint('email', new Assert\Email(
message: 'The email "{{ value }}" is not a valid email.',
));
}
}
Expand Down
6 changes: 3 additions & 3 deletions reference/constraints/EqualTo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ and that the ``age`` is ``20``, you could do the following:
{
$metadata->addPropertyConstraint('firstName', new Assert\EqualTo('Mary'));
$metadata->addPropertyConstraint('age', new Assert\EqualTo([
'value' => 20,
]));
$metadata->addPropertyConstraint('age', new Assert\EqualTo(
value: 20,
));
}
}
Expand Down
24 changes: 12 additions & 12 deletions reference/constraints/Expression.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ One way to accomplish this is with the Expression constraint:
{
public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addConstraint(new Assert\Expression([
'expression' => 'this.getCategory() in ["php", "symfony"] or !this.isTechnicalPost()',
'message' => 'If this is a tech post, the category should be either php or symfony!',
]));
$metadata->addConstraint(new Assert\Expression(
expression: 'this.getCategory() in ["php", "symfony"] or !this.isTechnicalPost()',
message: 'If this is a tech post, the category should be either php or symfony!',
));
}
// ...
Expand Down Expand Up @@ -200,10 +200,10 @@ assert that the expression must return ``true`` for validation to fail.
{
public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('isTechnicalPost', new Assert\Expression([
'expression' => 'this.getCategory() in ["php", "symfony"] or value == false',
'message' => 'If this is a tech post, the category should be either php or symfony!',
]));
$metadata->addPropertyConstraint('isTechnicalPost', new Assert\Expression(
expression: 'this.getCategory() in ["php", "symfony"] or value == false',
message: 'If this is a tech post, the category should be either php or symfony!',
));
}
// ...
Expand Down Expand Up @@ -343,10 +343,10 @@ type (numeric, boolean, strings, null, etc.)
{
public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('metric', new Assert\Expression([
'expression' => 'value + error_margin < threshold',
'values' => ['error_margin' => 0.25, 'threshold' => 1.5],
]));
$metadata->addPropertyConstraint('metric', new Assert\Expression(
expression: 'value + error_margin < threshold',
values: ['error_margin' => 0.25, 'threshold' => 1.5],
));
}
// ...
Expand Down
6 changes: 3 additions & 3 deletions reference/constraints/ExpressionSyntax.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ The following constraints ensure that:
{
$metadata->addPropertyConstraint('promotion', new Assert\ExpressionSyntax());
$metadata->addPropertyConstraint('shippingOptions', new Assert\ExpressionSyntax([
'allowedVariables' => ['user', 'shipping_centers'],
]));
$metadata->addPropertyConstraint('shippingOptions', new Assert\ExpressionSyntax(
allowedVariables: ['user', 'shipping_centers'],
));
}
}
Expand Down

0 comments on commit de324eb

Please sign in to comment.