<commit_before><?php

namespace Palmtree\Csv;

use Palmtree\Csv\Formatter\FormatterInterface;
use Palmtree\Csv\Formatter\StringFormatter;
use Palmtree\Csv\Row\Row;

/**
 * Reads a CSV file by loading each line into memory
 * one at a time.
 */
class Reader extends AbstractCsv implements \Iterator, \Countable
{
    protected $fopenMode = 'r';
    /** @var FormatterInterface[] */
    protected $formatters = [];
    /** @var int */
    protected $index = 0;
    /** @var array */
    protected $headers;
    /** @var Row */
    protected $row;
    /** @var string */
    protected $escapeCharacter = "\0";

    /**
     * @param $file
     *
     * @return array
     */
    public static function read($file)
    {
        $csv = new static($file);

        return iterator_to_array($csv);
    }

    /**
     * @return array
     */
    public function getHeaders()
    {
        return $this->headers;
    }

    /**
     * @param mixed              $key
     * @param FormatterInterface $formatter
     *
     * @return $this
     */
    public function addFormatter($key, FormatterInterface $formatter)
    {
        $this->formatters[$key] = $formatter;

        return $this;
    }

    /**
     * @param array|\Traversable $formatters
     *
     * @return $this
     */
    public function addFormatters($formatters)
    {
        foreach ($formatters as $key => $formatter) {
            $this->addFormatter($key, $formatter);
        }

        return $this;
    }

    /**
     * @param mixed $key
     *
     * @return null|FormatterInterface
     */
    public function getFormatter($key)
    {
        if (!isset($this->formatters[$key])) {
            $this->formatters[$key] = new StringFormatter();
        }

        return $this->formatters[$key];
    }

    /**
     * @return string
     */
    public function getEscapeCharacter()
    {
        return $this->escapeCharacter;
    }

    /**
     * @param string $escapeCharacter
     *
     * @return AbstractCsv
     */
    public function setEscapeCharacter($escapeCharacter)
    {
        $this->escapeCharacter = $escapeCharacter;

        return $this;
    }

    /**
     * Returns an array of cells for the next row.
     *
     * @return Row
     */
    protected function getNextRow()
    {
        if (!$this->getFileHandle()) {
            $this->createFileHandle();
        }

        $row = fgetcsv(
            $this->getFileHandle(),
            null,
            $this->getDelimiter(),
            $this->getEnclosure(),
            $this->getEscapeCharacter()
        );

        if (!$row) {
            return null;
        }
<commit_msg>Update return types<commit_after><?php

namespace Palmtree\Csv;

use Palmtree\Csv\Formatter\FormatterInterface;
use Palmtree\Csv\Formatter\StringFormatter;
use Palmtree\Csv\Row\Row;

/**
 * Reads a CSV file by loading each line into memory
 * one at a time.
 */
class Reader extends AbstractCsv implements \Iterator, \Countable
{
    protected $fopenMode = 'r';
    /** @var FormatterInterface[] */
    protected $formatters = [];
    /** @var int */
    protected $index = 0;
    /** @var Row */
    protected $headers;
    /** @var Row */
    protected $row;
    /** @var string */
    protected $escapeCharacter = "\0";

    /**
     * @param $file
     *
     * @return array
     */
    public static function read($file)
    {
        $csv = new static($file);

        return iterator_to_array($csv);
    }

    /**
     * @return Row
     */
    public function getHeaders()
    {
        return $this->headers;
    }

    /**
     * @param mixed              $key
     * @param FormatterInterface $formatter
     *
     * @return $this
     */
    public function addFormatter($key, FormatterInterface $formatter)
    {
        $this->formatters[$key] = $formatter;

        return $this;
    }

    /**
     * @param array|\Traversable $formatters
     *
     * @return $this
     */
    public function addFormatters($formatters)
    {
        foreach ($formatters as $key => $formatter) {
            $this->addFormatter($key, $formatter);
        }

        return $this;
    }

    /**
     * @param mixed $key
     *
     * @return null|FormatterInterface
     */
    public function getFormatter($key)
    {
        if (!isset($this->formatters[$key])) {
            $this->formatters[$key] = new StringFormatter();
        }

        return $this->formatters[$key];
    }

    /**
     * @return string
     */
    public function getEscapeCharacter()
    {
        return $this->escapeCharacter;
    }

    /**
     * @param string $escapeCharacter
     *
     * @return AbstractCsv
     */
    public function setEscapeCharacter($escapeCharacter)
    {
        $this->escapeCharacter = $escapeCharacter;

        return $this;
    }

    /**
     * Returns an array of cells for the next row.
     *
     * @return Row
     */
    protected function getNextRow()
    {
        if (!$this->getFileHandle()) {
            $this->createFileHandle();
        }

        $row = fgetcsv(
            $this->getFileHandle(),
            null,
            $this->getDelimiter(),
            $this->getEnclosure(),
            $this->getEscapeCharacter()
        );

        if ($row === null || $row === false) {
            return null;
        }

{'fraction_non_alphanumeric': 0.13383742911153118, 'fraction_numerical': 0.0007561436672967864, 'mean_word_length': 1.8278995189738108, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '7269834', 'n_tokens_mistral': 1558, 'n_tokens_neox': 1518, 'n_words': 347}