File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -417,6 +417,10 @@ public function valueByName(
417
417
bool |string $ required = false ,
418
418
Bytes |Token |DisplayString |DateTimeImmutable |string |int |float |bool |null $ default = null
419
419
): Bytes |Token |DisplayString |DateTimeImmutable |string |int |float |bool |null {
420
+ if (null !== $ default && null === Type::tryFromVariable ($ default )) {
421
+ throw new SyntaxError ('The default parameter is invalid. ' );
422
+ }
423
+
420
424
try {
421
425
return $ this ->getByName ($ name , $ validate )->value ();
422
426
} catch (InvalidOffset $ exception ) {
Original file line number Diff line number Diff line change @@ -509,6 +509,16 @@ public function it_can_validate_the_item_parameter_value(): void
509
509
self ::assertFalse ($ item ->parameterByName (name: 'b ' , default: false ));
510
510
}
511
511
512
+ #[Test]
513
+ public function it_will_fail_if_the_default_value_is_invalid_for_the_parameter_name (): void
514
+ {
515
+ $ item = Item::fromAssociative (Token::fromString ('babayaga ' ), ['a ' => true ]);
516
+
517
+ $ this ->expectException (SyntaxError::class);
518
+
519
+ $ item ->parameterByName ('b ' , default:'bébé ' );
520
+ }
521
+
512
522
#[Test]
513
523
public function it_can_validate_and_trigger_a_custom_error_message (): void
514
524
{
You can’t perform that action at this time.
0 commit comments