Skip to content

Commit de324eb

Browse files
committed
use named-arguments to configure validation constraint options
1 parent 171af72 commit de324eb

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

reference/constraints/Email.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ Basic Usage
7070
7171
public static function loadValidatorMetadata(ClassMetadata $metadata): void
7272
{
73-
$metadata->addPropertyConstraint('email', new Assert\Email([
74-
'message' => 'The email "{{ value }}" is not a valid email.',
75-
]));
73+
$metadata->addPropertyConstraint('email', new Assert\Email(
74+
message: 'The email "{{ value }}" is not a valid email.',
75+
));
7676
}
7777
}
7878

reference/constraints/EqualTo.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ and that the ``age`` is ``20``, you could do the following:
9191
{
9292
$metadata->addPropertyConstraint('firstName', new Assert\EqualTo('Mary'));
9393
94-
$metadata->addPropertyConstraint('age', new Assert\EqualTo([
95-
'value' => 20,
96-
]));
94+
$metadata->addPropertyConstraint('age', new Assert\EqualTo(
95+
value: 20,
96+
));
9797
}
9898
}
9999

reference/constraints/Expression.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ One way to accomplish this is with the Expression constraint:
111111
{
112112
public static function loadValidatorMetadata(ClassMetadata $metadata): void
113113
{
114-
$metadata->addConstraint(new Assert\Expression([
115-
'expression' => 'this.getCategory() in ["php", "symfony"] or !this.isTechnicalPost()',
116-
'message' => 'If this is a tech post, the category should be either php or symfony!',
117-
]));
114+
$metadata->addConstraint(new Assert\Expression(
115+
expression: 'this.getCategory() in ["php", "symfony"] or !this.isTechnicalPost()',
116+
message: 'If this is a tech post, the category should be either php or symfony!',
117+
));
118118
}
119119
120120
// ...
@@ -200,10 +200,10 @@ assert that the expression must return ``true`` for validation to fail.
200200
{
201201
public static function loadValidatorMetadata(ClassMetadata $metadata): void
202202
{
203-
$metadata->addPropertyConstraint('isTechnicalPost', new Assert\Expression([
204-
'expression' => 'this.getCategory() in ["php", "symfony"] or value == false',
205-
'message' => 'If this is a tech post, the category should be either php or symfony!',
206-
]));
203+
$metadata->addPropertyConstraint('isTechnicalPost', new Assert\Expression(
204+
expression: 'this.getCategory() in ["php", "symfony"] or value == false',
205+
message: 'If this is a tech post, the category should be either php or symfony!',
206+
));
207207
}
208208
209209
// ...
@@ -343,10 +343,10 @@ type (numeric, boolean, strings, null, etc.)
343343
{
344344
public static function loadValidatorMetadata(ClassMetadata $metadata): void
345345
{
346-
$metadata->addPropertyConstraint('metric', new Assert\Expression([
347-
'expression' => 'value + error_margin < threshold',
348-
'values' => ['error_margin' => 0.25, 'threshold' => 1.5],
349-
]));
346+
$metadata->addPropertyConstraint('metric', new Assert\Expression(
347+
expression: 'value + error_margin < threshold',
348+
values: ['error_margin' => 0.25, 'threshold' => 1.5],
349+
));
350350
}
351351
352352
// ...

reference/constraints/ExpressionSyntax.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ The following constraints ensure that:
9090
{
9191
$metadata->addPropertyConstraint('promotion', new Assert\ExpressionSyntax());
9292
93-
$metadata->addPropertyConstraint('shippingOptions', new Assert\ExpressionSyntax([
94-
'allowedVariables' => ['user', 'shipping_centers'],
95-
]));
93+
$metadata->addPropertyConstraint('shippingOptions', new Assert\ExpressionSyntax(
94+
allowedVariables: ['user', 'shipping_centers'],
95+
));
9696
}
9797
}
9898

0 commit comments

Comments
 (0)