Skip to content

Commit 97bb596

Browse files
authored
Merge pull request #585 from qkdreyer/master
fix: prevent type error on choices array with optional keys
2 parents ad89a56 + 5aa1771 commit 97bb596

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

Tests/Translation/Extractor/File/Fixture/MyFormType.php

+2
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,6 @@ public function buildForm(FormBuilderInterface $builder, array $options)
6767
'empty_value' => ['year' => 'form.dueDate.empty.year', 'month' => 'form.dueDate.empty.month', 'day' => 'form.dueDate.empty.day'],
6868
]);
6969
}
70+
71+
public const CHOICES = ['choices' => [null]];
7072
}

Tests/Translation/Extractor/File/FormExtractorTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ public function testExtract()
148148
$message->addSource($fileSourceFactory->create($fixtureSplInfo, 67));
149149
$expected->add($message);
150150

151+
$message = new Message(0);
152+
$message->addSource($fileSourceFactory->create($fixtureSplInfo, -1));
153+
$expected->add($message);
154+
151155
$this->assertEquals($expected, $this->extract('MyFormType.php'));
152156
}
153157

Translation/Extractor/File/FormExtractor.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ protected function parseChoiceNode(Node $item, Node $node, $domain)
241241
return true;
242242
}
243243

244-
foreach ($item->value->items as $subItem) {
244+
foreach ($item->value->items as $index => $subItem) {
245245
$newItem = clone $subItem;
246246
$newItem->key = $subItem->value;
247-
$newItem->value = $subItem->key;
247+
$newItem->value = $subItem->key ?? new Node\Scalar\LNumber($index);
248248
$subItem = $newItem;
249249
$this->parseItem($subItem, $domain);
250250
}

0 commit comments

Comments
 (0)