Skip to content

Commit 07ff8d7

Browse files
authored
fix complexity
Signed-off-by: rahul <[email protected]>
1 parent 5fc328e commit 07ff8d7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/CsvFileHandler.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ private function setColumnsToHide(array &$headers, array $hideColumns): array
171171
/**
172172
* @param string $filename
173173
* @param array<string>|false $hideColumns
174+
* @param int|false $limit
174175
* @return Generator
175176
* @throws FileHandlerException
176177
*/
@@ -180,18 +181,18 @@ private function getRows(string $filename, array|false $hideColumns = false, int
180181
if (!$csvFile) {
181182
throw new FileHandlerException('file not found');
182183
}
184+
183185
$headers = $this->extractHeader($csvFile);
184186
if (!is_array($headers)) {
187+
fclose($csvFile);
185188
throw new FileHandlerException('could not extract header');
186189
}
187190

188-
if (is_array($hideColumns)) {
189-
$indices = $this->setColumnsToHide($headers, $hideColumns);
190-
}
191-
191+
$indices = is_array($hideColumns) ? $this->setColumnsToHide($headers, $hideColumns) : [];
192192

193193
$isEmptyFile = true;
194194
$count = 0;
195+
195196
try {
196197
while (($row = fgetcsv($csvFile)) !== false) {
197198
$isEmptyFile = false;
@@ -203,7 +204,6 @@ private function getRows(string $filename, array|false $hideColumns = false, int
203204
$this->removeElementByIndex($row, $indices);
204205
}
205206

206-
207207
$item = array_combine($headers, $row);
208208
yield $item;
209209
$count++;
@@ -216,12 +216,12 @@ private function getRows(string $filename, array|false $hideColumns = false, int
216216
fclose($csvFile);
217217
}
218218

219-
220219
if ($isEmptyFile) {
221220
throw new FileHandlerException('invalid csv file format');
222221
}
223222
}
224223

224+
225225
/**
226226
* @param array<int,string> $row
227227
* @param array<int<0, max>, int> $indices

0 commit comments

Comments
 (0)