Skip to content

Commit f4ba9a3

Browse files
committed
Prevent iso from being set by both legacy string and positional argument
1 parent e642f8c commit f4ba9a3

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/ZipCodeValidator/Constraints/ZipCode.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ public function __construct(
3333
)
3434
{
3535
if (is_string($options)) {
36+
if (null !== $iso) {
37+
throw new InvalidOptionsException(
38+
'Cannot pass both positional string $options and named "iso". Use one style.',
39+
['options', 'iso']
40+
);
41+
}
42+
3643
$options = ['iso' => $options];
3744
} elseif (null === $options) {
3845
$options = [];

tests/Constraints/ZipCodeTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,10 @@ public function testUnknownLegacyOptionThrowsException(): void
7676
$this->expectException(InvalidOptionsException::class);
7777
new ZipCode(['foo' => 'bar', 'iso' => 'FR']);
7878
}
79+
80+
public function testLegacyStringOptionCannotBeCombinedWithNamedIso(): void
81+
{
82+
$this->expectException(InvalidOptionsException::class);
83+
new ZipCode('DE', iso: 'FR');
84+
}
7985
}

0 commit comments

Comments
 (0)