Skip to content

Commit 0cb71d6

Browse files
committed
Further improve parentArray handling when set on an unnamed object, it will attempt to typehint the inherited object if there's only 1, or falls back to the intrinsic type
1 parent 56d42ee commit 0cb71d6

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/XmlFileParser.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,14 @@ private function writeClassAndFieldHints(Frame $frame): string
292292
$allParentKeys = [];
293293
$allParentArrays = [];
294294
foreach ($frame->getChildren() as $child) {
295-
$typehint = $this->childHasInterestingData($child) ? $child->getClassName() : $child->getType();
295+
$typehint = $this->childHasInterestingData($child) ? $child->getClassName() : null;
296+
if (empty($typehint) && 1 === count($child->getInherits())) {
297+
$typehint = $child->getInherits()[0];
298+
}
299+
$typehint = $typehint ?: $child->getType();
296300
$parentKeys = [];
297301
if ($child->getParentKey()) {
298-
$parentKeys[$child->getParentKey()] = $typehint;
302+
$parentKeys[$child->getParentKey()] = $typehint ?: 'table';
299303
}
300304
foreach ($this->iterateInherits($child) as $inherit) {
301305
if ($inherit->getParentKey()) {
@@ -307,7 +311,7 @@ private function writeClassAndFieldHints(Frame $frame): string
307311

308312
$parentArrays = [];
309313
if ($child->getParentArray()) {
310-
$parentArrays[$child->getParentArray()] = $typehint;
314+
$parentArrays[$child->getParentArray()] = $typehint ?: 'table';
311315
}
312316
foreach ($this->iterateInherits($child) as $inherit) {
313317
if ($inherit->getParentArray()) {

0 commit comments

Comments
 (0)