@@ -171,6 +171,7 @@ private function setColumnsToHide(array &$headers, array $hideColumns): array
171
171
/**
172
172
* @param string $filename
173
173
* @param array<string>|false $hideColumns
174
+ * @param int|false $limit
174
175
* @return Generator
175
176
* @throws FileHandlerException
176
177
*/
@@ -180,18 +181,18 @@ private function getRows(string $filename, array|false $hideColumns = false, int
180
181
if (!$ csvFile ) {
181
182
throw new FileHandlerException ('file not found ' );
182
183
}
184
+
183
185
$ headers = $ this ->extractHeader ($ csvFile );
184
186
if (!is_array ($ headers )) {
187
+ fclose ($ csvFile );
185
188
throw new FileHandlerException ('could not extract header ' );
186
189
}
187
190
188
- if (is_array ($ hideColumns )) {
189
- $ indices = $ this ->setColumnsToHide ($ headers , $ hideColumns );
190
- }
191
-
191
+ $ indices = is_array ($ hideColumns ) ? $ this ->setColumnsToHide ($ headers , $ hideColumns ) : [];
192
192
193
193
$ isEmptyFile = true ;
194
194
$ count = 0 ;
195
+
195
196
try {
196
197
while (($ row = fgetcsv ($ csvFile )) !== false ) {
197
198
$ isEmptyFile = false ;
@@ -203,7 +204,6 @@ private function getRows(string $filename, array|false $hideColumns = false, int
203
204
$ this ->removeElementByIndex ($ row , $ indices );
204
205
}
205
206
206
-
207
207
$ item = array_combine ($ headers , $ row );
208
208
yield $ item ;
209
209
$ count ++;
@@ -216,12 +216,12 @@ private function getRows(string $filename, array|false $hideColumns = false, int
216
216
fclose ($ csvFile );
217
217
}
218
218
219
-
220
219
if ($ isEmptyFile ) {
221
220
throw new FileHandlerException ('invalid csv file format ' );
222
221
}
223
222
}
224
223
224
+
225
225
/**
226
226
* @param array<int,string> $row
227
227
* @param array<int<0, max>, int> $indices
0 commit comments