Fix: avoid count() crash in ImportListView on non-array headerColumns #650
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a potential fatal error that occurs during the import process when $headerColumns is not an array.
In ImportListView.php, the following line:
$this->ss->assign('colCount', count($this->headerColumns));
can throw an error like:
Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given
This usually happens if something goes wrong earlier in the import process and $headerColumns ends up being false or unset.
Motivation and Context
This change ensures that the import view doesn't break if $headerColumns isn’t an array. It's a small defensive coding fix, but it improves stability for users importing large or complex datasets.
How To Test This
Go to the Import section for the Targets module.
Try importing a large or malformed CSV file.
Confirm that the page doesn’t crash with a count() error.
Verify that the number of columns is displayed correctly if $headerColumns is valid.
Types of changes
Bug fix (non-breaking change which fixes an issue)