Skip to content

Commit

Permalink
Merge pull request #585 from qkdreyer/master
Browse files Browse the repository at this point in the history
fix: prevent type error on choices array with optional keys
  • Loading branch information
goetas authored Mar 11, 2024
2 parents ad89a56 + 5aa1771 commit 97bb596
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Tests/Translation/Extractor/File/Fixture/MyFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'empty_value' => ['year' => 'form.dueDate.empty.year', 'month' => 'form.dueDate.empty.month', 'day' => 'form.dueDate.empty.day'],
]);
}

public const CHOICES = ['choices' => [null]];
}
4 changes: 4 additions & 0 deletions Tests/Translation/Extractor/File/FormExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ public function testExtract()
$message->addSource($fileSourceFactory->create($fixtureSplInfo, 67));
$expected->add($message);

$message = new Message(0);
$message->addSource($fileSourceFactory->create($fixtureSplInfo, -1));
$expected->add($message);

$this->assertEquals($expected, $this->extract('MyFormType.php'));
}

Expand Down
4 changes: 2 additions & 2 deletions Translation/Extractor/File/FormExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ protected function parseChoiceNode(Node $item, Node $node, $domain)
return true;
}

foreach ($item->value->items as $subItem) {
foreach ($item->value->items as $index => $subItem) {
$newItem = clone $subItem;
$newItem->key = $subItem->value;
$newItem->value = $subItem->key;
$newItem->value = $subItem->key ?? new Node\Scalar\LNumber($index);
$subItem = $newItem;
$this->parseItem($subItem, $domain);
}
Expand Down

0 comments on commit 97bb596

Please sign in to comment.