29
29
*/
30
30
class BicValidator extends ConstraintValidator
31
31
{
32
+ // Reference: https://www.iban.com/structure
32
33
private const BIC_COUNTRY_TO_IBAN_COUNTRY_MAP = [
33
- // Reference: https://www.ecbs.org/iban/france-bank-account-number.html
34
+ // FR includes:
34
35
'GF ' => 'FR ' , // French Guiana
35
36
'PF ' => 'FR ' , // French Polynesia
36
37
'TF ' => 'FR ' , // French Southern Territories
@@ -39,13 +40,20 @@ class BicValidator extends ConstraintValidator
39
40
'YT ' => 'FR ' , // Mayotte
40
41
'NC ' => 'FR ' , // New Caledonia
41
42
'RE ' => 'FR ' , // Reunion
43
+ 'BL ' => 'FR ' , // Saint Barthelemy
44
+ 'MF ' => 'FR ' , // Saint Martin (French part)
42
45
'PM ' => 'FR ' , // Saint Pierre and Miquelon
43
46
'WF ' => 'FR ' , // Wallis and Futuna Islands
44
- // Reference: https://www.ecbs.org/iban/united-kingdom-uk-bank-account-number.html
47
+ // GB includes:
45
48
'JE ' => 'GB ' , // Jersey
46
49
'IM ' => 'GB ' , // Isle of Man
47
50
'GG ' => 'GB ' , // Guernsey
48
51
'VG ' => 'GB ' , // British Virgin Islands
52
+ // FI includes:
53
+ 'AX ' => 'FI ' , // Aland Islands
54
+ // ES includes:
55
+ 'IC ' => 'ES ' , // Canary Islands
56
+ 'EA ' => 'ES ' , // Ceuta and Melilla
49
57
];
50
58
51
59
private $ propertyAccessor ;
@@ -104,7 +112,8 @@ public function validate($value, Constraint $constraint)
104
112
return ;
105
113
}
106
114
107
- if (!Countries::exists (substr ($ canonicalize , 4 , 2 ))) {
115
+ $ bicCountryCode = substr ($ canonicalize , 4 , 2 );
116
+ if (!isset (self ::BIC_COUNTRY_TO_IBAN_COUNTRY_MAP [$ bicCountryCode ]) && !Countries::exists ($ bicCountryCode )) {
108
117
$ this ->context ->buildViolation ($ constraint ->message )
109
118
->setParameter ('{{ value }} ' , $ this ->formatValue ($ value ))
110
119
->setCode (Bic::INVALID_COUNTRY_CODE_ERROR )
@@ -137,7 +146,7 @@ public function validate($value, Constraint $constraint)
137
146
return ;
138
147
}
139
148
$ ibanCountryCode = substr ($ iban , 0 , 2 );
140
- if (ctype_alpha ($ ibanCountryCode ) && !$ this ->bicAndIbanCountriesMatch (substr ( $ canonicalize , 4 , 2 ) , $ ibanCountryCode )) {
149
+ if (ctype_alpha ($ ibanCountryCode ) && !$ this ->bicAndIbanCountriesMatch ($ bicCountryCode , $ ibanCountryCode )) {
141
150
$ this ->context ->buildViolation ($ constraint ->ibanMessage )
142
151
->setParameter ('{{ value }} ' , $ this ->formatValue ($ value ))
143
152
->setParameter ('{{ iban }} ' , $ iban )
0 commit comments