@@ -157,35 +157,42 @@ public function doImport(File|null $importHandle = null): array
157157 /**
158158 * Move down the XML tree to the actual data
159159 */
160- $ databaseXml = $ xml ->database ;
161160
162161 $ analyses = null ;
163162 /** @var ImportTable[] $tables */
164163 $ tables = [];
165164
166- $ databaseName = (string ) $ databaseXml ['name ' ];
167-
168- /** @var SimpleXMLElement $tableRowXml */
169- foreach ($ databaseXml ->table ?? [] as $ tableRowXml ) {
170- $ tableName = (string ) $ tableRowXml ['name ' ];
171-
172- $ table = $ tables [$ tableName ] ?? new ImportTable ($ tableName );
165+ $ databaseName = '' ;
166+ // SimpleXMLElement does not obey typical PHP rules.
167+ // Children can be fetched through the magical __get() method,but if the child does not exist,
168+ // it will return an empty SimpleXMLElement instead of null.
169+ // This means that we need to check for the existence of the child before trying to access it.
170+ if (isset ($ xml ->database )) {
171+ $ databaseXml = $ xml ->database ;
172+ $ databaseName = (string ) $ databaseXml ['name ' ];
173+
174+ /** @var SimpleXMLElement $tableRowXml */
175+ foreach ($ databaseXml ->table as $ tableRowXml ) {
176+ $ tableName = (string ) $ tableRowXml ['name ' ];
177+
178+ $ table = $ tables [$ tableName ] ?? new ImportTable ($ tableName );
179+
180+ $ tableRow = [];
181+ /** @var SimpleXMLElement $tableCellXml */
182+ foreach ($ tableRowXml ->column as $ tableCellXml ) {
183+ /** @psalm-suppress PossiblyNullArrayAccess */
184+ $ columnName = (string ) $ tableCellXml ['name ' ];
185+ if (! in_array ($ columnName , $ table ->columns , true )) {
186+ $ table ->columns [] = $ columnName ;
187+ }
173188
174- $ tableRow = [];
175- /** @var SimpleXMLElement $tableCellXml */
176- foreach ($ tableRowXml ->column as $ tableCellXml ) {
177- /** @psalm-suppress PossiblyNullArrayAccess */
178- $ columnName = (string ) $ tableCellXml ['name ' ];
179- if (! in_array ($ columnName , $ table ->columns , true )) {
180- $ table ->columns [] = $ columnName ;
189+ $ tableRow [] = (string ) $ tableCellXml ;
181190 }
182191
183- $ tableRow [] = (string ) $ tableCellXml ;
184- }
185-
186- $ table ->rows [] = $ tableRow ;
192+ $ table ->rows [] = $ tableRow ;
187193
188- $ tables [$ tableName ] = $ table ;
194+ $ tables [$ tableName ] = $ table ;
195+ }
189196 }
190197
191198 unset($ xml );
0 commit comments