<commit_before><?php

namespace Ddeboer\DataImport\Reader;

/**
 * Reads a CSV file, using as little memory as possible
 *
 * @author <NAME> <<EMAIL>>
 */
class CsvReader implements ReaderInterface, \SeekableIterator
{
    /**
     * Number of the row that contains the column names
     *
     * @var int
     */
    protected $headerRowNumber;

    /**
     * CSV file
     *
     * @var \SplFileObject
     */
    protected $file;

    /**
     * Column headers as read from the CSV file
     *
     * @var array
     */
    protected $columnHeaders;

    /**
     * Total number of rows in the CSV file
     *
     * @var int
     */
    protected $count;

    /**
     * Construct CSV reader
     *
     * @param \SplFileObject $file      CSV file
     * @param string         $delimiter Delimiter
     * @param string         $enclosure Enclosure
     * @param string         $escape    Escape characters
     */
    public function __construct(\SplFileObject $file, $delimiter = ';', $enclosure = '"', $escape = '\\')
    {
        $this->file = $file;
        $this->file->setFlags(\SplFileObject::READ_CSV |
            \SplFileObject::SKIP_EMPTY |
            \SplFileObject::READ_AHEAD |
            \SplFileObject::DROP_NEW_LINE);
        $this->file->setCsvControl(
            $delimiter,
            $enclosure,
            $escape
        );
    }

    /**
     * Return the current row as an array
     *
     * If a header row has been set, an associative array will be returned
     *
     * @return array
     */
    public function current()
    {
        $line = $this->file->current();

        // If the CSV has column headers, use them to construct an associative
        // array for the columns in this line<commit_msg>Fix CS<commit_after><?php

namespace Ddeboer\DataImport\Reader;

/**
 * Reads a CSV file, using as little memory as possible
 *
 * @author <NAME> <<EMAIL>>
 */
class CsvReader implements ReaderInterface, \SeekableIterator
{
    /**
     * Number of the row that contains the column names
     *
     * @var int
     */
    protected $headerRowNumber;

    /**
     * CSV file
     *
     * @var \SplFileObject
     */
    protected $file;

    /**
     * Column headers as read from the CSV file
     *
     * @var array
     */
    protected $columnHeaders;

    /**
     * Total number of rows in the CSV file
     *
     * @var int
     */
    protected $count;

    /**
     * Construct CSV reader
     *
     * @param \SplFileObject $file      CSV file
     * @param string         $delimiter Delimiter
     * @param string         $enclosure Enclosure
     * @param string         $escape    Escape characters
     */
    public function __construct(\SplFileObject $file, $delimiter = ';', $enclosure = '"', $escape = '\\')
    {
        $this->file = $file;
        $this->file->setFlags(
            \SplFileObject::READ_CSV |
            \SplFileObject::SKIP_EMPTY |
            \SplFileObject::READ_AHEAD |
            \SplFileObject::DROP_NEW_LINE
        );
        $this->file->setCsvControl(
            $delimiter,
            $enclosure,
            $escape
        );
    }

    /**
     * Return the current row as an array
     *
     * If a header row has been set, an associative array will be returned
     *
     * @return array
     */
    public function current()
    {
        $line = $this->file->current();

        // If the CSV has column headers, use them to construct an associative
        // array for the columns in this line
{'fraction_non_alphanumeric': 0.10778443113772455, 'fraction_numerical': 0.0, 'mean_word_length': 1.7797147385103012, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '517493', 'n_tokens_mistral': 1039, 'n_tokens_neox': 1000, 'n_words': 297}