getSourceFp(); $destinationFp = $this->getDestinationFp(); $index = $this->getIndex(); // Extract duplicates in a separate file. $duplicateCount = 0; foreach ($index as $identifier => $positions) { if (count($positions) > 1) { // We have a duplicate. foreach ($positions as $pos) { rewind($sourceFp); fseek($sourceFp, $pos); $sourceData = fgetcsv($sourceFp); fputcsv($destinationFp, $sourceData); $duplicateCount++; } } } return new Report( Report::TYPE_INFO, "${duplicateCount} duplicate records extracted in file '" . realpath($this->getDestination()) . "'." ); } }