Skip to content

Commit c8f6442

Browse files
author
Augustin Pasquini
committed
SF7: All constraint message properties have been moved to constructors
1 parent 1d77d6f commit c8f6442

13 files changed

Lines changed: 186 additions & 67 deletions

src/Validator/Constraints/Email.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,22 @@ class Email extends _Email
1717

1818
public string $tldMessage = 'The value {{ domain }} is not a valid domain name.';
1919
public string $dnsMessage = 'The domain {{ domain }} is not setup to received emails.';
20+
public mixed $mode = 'strict';
21+
public bool $checkDNS = false;
2022

21-
/** @var mixed */
22-
public $mode = 'strict';
23+
public function __construct(
24+
?string $tldMessage = null,
25+
?string $dnsMessage = null,
26+
mixed $mode = null,
27+
?bool $checkDNS = null,
28+
?array $groups = null,
29+
mixed $payload = null,
30+
) {
31+
parent::__construct([], $groups, $payload);
2332

24-
public bool $checkDNS = false;
33+
$this->tldMessage = $tldMessage ?? $this->tldMessage;
34+
$this->dnsMessage = $dnsMessage ?? $this->dnsMessage;
35+
$this->mode = $mode ?? $this->mode;
36+
$this->checkDNS = $checkDNS ?? $this->checkDNS;
37+
}
2538
}

src/Validator/Constraints/EmployerIdentificationNumber.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,16 @@
1010
class EmployerIdentificationNumber extends Constraint
1111
{
1212
public const WRONG_FORMAT_ERROR = '890163a8-f289-4c6b-aa2b-73890f93ca5c';
13+
1314
public string $message = 'The value {{ value }} is not a valid employer identification number.';
15+
16+
public function __construct(
17+
?string $message = null,
18+
?array $groups = null,
19+
mixed $payload = null,
20+
) {
21+
parent::__construct([], $groups, $payload);
22+
23+
$this->message = $message ?? $this->message;
24+
}
1425
}

src/Validator/Constraints/FloatScale.php

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,15 @@ class FloatScale extends Constraint
1818

1919
public int $scale;
2020

21-
/**
22-
* @param int|array<mixed> $scale
23-
* @param array<mixed> $options
24-
*/
2521
public function __construct(
26-
$scale,
22+
int $scale,
23+
?string $message = null,
2724
?array $groups = null,
2825
mixed $payload = null,
29-
array $options = []
3026
) {
31-
if (\is_array($scale)) {
32-
$options = array_merge($scale, $options);
33-
} elseif (null !== $scale) {
34-
$options['value'] = $scale;
35-
}
27+
parent::__construct([], $groups, $payload);
3628

37-
parent::__construct($options, $groups, $payload);
38-
}
39-
40-
public function getDefaultOption(): string
41-
{
42-
return 'scale';
43-
}
44-
45-
public function getRequiredOptions(): array
46-
{
47-
return ['scale'];
29+
$this->scale = $scale;
30+
$this->message = $message ?? $this->message;
4831
}
4932
}

src/Validator/Constraints/FrenchRna.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,14 @@ class FrenchRna extends Constraint
1515
public const INVALID_FORMAT_ERROR = 'd125c480-3efd-42dd-9a59-6058fddd4fe4';
1616

1717
public string $message = 'The value {{ value }} is not a valid RNA identifier.';
18+
19+
public function __construct(
20+
?string $message = null,
21+
?array $groups = null,
22+
mixed $payload = null,
23+
) {
24+
parent::__construct([], $groups, $payload);
25+
26+
$this->message = $message ?? $this->message;
27+
}
1828
}

src/Validator/Constraints/FrenchSiren.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ class FrenchSiren extends Luhn
1414
{
1515
public const INVALID_FORMAT_ERROR = '4d762774-3g50-4bd5-a6d5-b10a3299d8d3';
1616

17-
/** @var mixed */
18-
public $message = 'The value {{ value }} is not a valid SIREN number.';
17+
public string $message = 'The value {{ value }} is not a valid SIREN number.';
18+
19+
public function __construct(
20+
?string $message = null,
21+
?array $groups = null,
22+
mixed $payload = null,
23+
) {
24+
parent::__construct([], $groups, $payload);
25+
26+
$this->message = $message ?? $this->message;
27+
}
1928
}

src/Validator/Constraints/FrenchSiret.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ class FrenchSiret extends Luhn
1414
{
1515
public const INVALID_FORMAT_ERROR = 'cbe06561-776e-45c2-b33c-a73141746d43';
1616

17-
/** @var mixed */
18-
public $message = 'The value {{ value }} is not a valid SIRET number.';
17+
public string $message = 'The value {{ value }} is not a valid SIRET number.';
18+
19+
public function __construct(
20+
?string $message = null,
21+
?array $groups = null,
22+
mixed $payload = null,
23+
) {
24+
parent::__construct([], $groups, $payload);
25+
26+
$this->message = $message ?? $this->message;
27+
}
1928
}

src/Validator/Constraints/LastDigitsUsSocialSecurityNumber.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ class LastDigitsUsSocialSecurityNumber extends Constraint
1313
{
1414
public const INVALID_FORMAT_ERROR = 'a6e7e8b3-2e2c-4f7c-b321-0b3b8e3c87f1';
1515

16-
public string $message = 'The value {{ value }} is not a valid set of ' .
17-
'last four digits of a US Social Security Number.';
16+
public string $message = 'The value {{ value }} is not a valid set of last four digits of a US Social Security Number.';
17+
18+
public function __construct(
19+
?string $message = null,
20+
?array $groups = null,
21+
mixed $payload = null,
22+
) {
23+
parent::__construct([], $groups, $payload);
24+
25+
$this->message = $message ?? $this->message;
26+
}
1827
}

src/Validator/Constraints/Phone.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ class Phone extends Constraint
2121
public const PHONE_NUMBER_NOT_EXIST = 'f32ef12d-cefa-42d9-97f0-520d90276bf0';
2222
public const INVALID_COUNTRY_CODE = '5530a448-f887-48c0-8ef8-77f206aa52b6';
2323

24+
public string $message = 'The value {{ value }} is not a valid phone number.';
25+
public string $notIntlFormatMessage = 'The value {{ value }} is not formatted as an international phone number.';
26+
public string $tooShortMessage = 'The phone number {{ value }} is too short.';
27+
public string $tooLongMessage = 'The phone number {{ value }} is too long.';
28+
public string $inexistantMessage = 'The phone number {{ value }} does not exist.';
29+
public string $wrongTypeMessage = 'The value {{ value }} is not an accepted phone number type.';
30+
public string $invalidCountryCodeMessage = 'The phone number {{ value }} does not have a valid country code.';
31+
2432
/**
2533
* @return array<int>
2634
*/
@@ -41,13 +49,27 @@ public function getValidTypes(): array
4149
];
4250
}
4351

44-
public string $message = 'The value {{ value }} is not a valid phone number.';
45-
public string $notIntlFormatMessage = 'The value {{ value }} is not formatted as an international phone number.';
46-
public string $tooShortMessage = 'The phone number {{ value }} is too short.';
47-
public string $tooLongMessage = 'The phone number {{ value }} is too long.';
48-
public string $inexistantMessage = 'The phone number {{ value }} does not exist.';
49-
public string $wrongTypeMessage = 'The value {{ value }} is not an accepted phone number type.';
50-
public string $invalidCountryCodeMessage = 'The phone number {{ value }} does not have a valid country code.';
52+
public function __construct(
53+
?string $message = null,
54+
?string $notIntlFormatMessage = null,
55+
?string $tooShortMessage = null,
56+
?string $tooLongMessage = null,
57+
?string $inexistantMessage = null,
58+
?string $wrongTypeMessage = null,
59+
?string $invalidCountryCodeMessage = null,
60+
?array $groups = null,
61+
mixed $payload = null,
62+
) {
63+
parent::__construct([], $groups, $payload);
64+
65+
$this->message = $message ?? $this->message;
66+
$this->notIntlFormatMessage = $notIntlFormatMessage ?? $this->notIntlFormatMessage;
67+
$this->tooShortMessage = $tooShortMessage ?? $this->tooShortMessage;
68+
$this->tooLongMessage = $tooLongMessage ?? $this->tooLongMessage;
69+
$this->inexistantMessage = $inexistantMessage ?? $this->inexistantMessage;
70+
$this->wrongTypeMessage = $wrongTypeMessage ?? $this->wrongTypeMessage;
71+
$this->invalidCountryCodeMessage = $invalidCountryCodeMessage ?? $this->invalidCountryCodeMessage;
72+
}
5173

5274
/**
5375
* {@inheritDoc}

src/Validator/Constraints/PhoneLandline.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,27 @@ public function getValidTypes(): array
2727
];
2828
}
2929

30-
public string $wrongTypeMessage = 'The value {{ value }} is not a valid landline phone number.';
30+
public function __construct(
31+
?string $message = null,
32+
?string $notIntlFormatMessage = null,
33+
?string $tooShortMessage = null,
34+
?string $tooLongMessage = null,
35+
?string $inexistantMessage = null,
36+
?string $wrongTypeMessage = null,
37+
?string $invalidCountryCodeMessage = null,
38+
?array $groups = null,
39+
mixed $payload = null,
40+
) {
41+
parent::__construct(
42+
$message,
43+
$notIntlFormatMessage,
44+
$tooShortMessage,
45+
$tooLongMessage,
46+
$inexistantMessage,
47+
$wrongTypeMessage ?? 'The value {{ value }} is not a valid landline phone number.',
48+
$invalidCountryCodeMessage,
49+
$groups,
50+
$payload
51+
);
52+
}
3153
}

src/Validator/Constraints/PhoneMobile.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,27 @@ public function getValidTypes(): array
2222
];
2323
}
2424

25-
public string $wrongTypeMessage = 'The value {{ value }} is not a valid mobile phone number.';
25+
public function __construct(
26+
?string $message = null,
27+
?string $notIntlFormatMessage = null,
28+
?string $tooShortMessage = null,
29+
?string $tooLongMessage = null,
30+
?string $inexistantMessage = null,
31+
?string $wrongTypeMessage = null,
32+
?string $invalidCountryCodeMessage = null,
33+
?array $groups = null,
34+
mixed $payload = null,
35+
) {
36+
parent::__construct(
37+
$message,
38+
$notIntlFormatMessage,
39+
$tooShortMessage,
40+
$tooLongMessage,
41+
$inexistantMessage,
42+
$wrongTypeMessage ?? 'The value {{ value }} is not a valid mobile phone number.',
43+
$invalidCountryCodeMessage,
44+
$groups,
45+
$payload
46+
);
47+
}
2648
}

0 commit comments

Comments
 (0)