You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Files/FileList: adding the same file twice should not increment FileList::$numFiles
This commit fixes the `FileList::__construct()` and
`FileList::addFile()` methods to ensure that, when there is an attempt
to add the same file twice, the `FileList::$numFiles` variable is not
incremented.
The code was already handling duplicates correctly in the sense that
duplicated files were not added to `FileList::$files`. However,
`FileList::$numFiles` was being incorrectly incremented.
There is some duplicated logic in `FileList::__construct()` and
`FileList::addFile()`. I considered refactoring the duplicated code to a
private method before adding the check that is added in this commit. I
decided not to do it as there are some subtle differences between the
logic in the two methods.
`FileList::__construct()` always sets the value of an entry in the
`FileList::$files` to `null` and the key to whatever is returned by
`SplFileInfo::getPathname()`. While `FileList::addFile()` sets the value
of an entry in the `FileList::$files` to `null` or an object passed to
the method and the key to the path passed to the method.
I decided to leave this refactor to remove the duplication to the future
and focus this commit on fixing the issue with handling duplicated
files.
0 commit comments