<commit_before><?php

namespace Ddeboer\DataImport\Writer;

/**
 * Writes to a CSV file
 */
class CsvWriter extends AbstractStreamWriter
{
    private $delimiter = ';';
    private $enclosure = '"';

    /**
     * Constructor
     *
     * @param string   $delimiter The delimiter
     * @param string   $enclosure The enclosure
     * @param resource $stream
     */
    public function __construct($delimiter = ';', $enclosure = '"', $stream = null)
    {
        parent::__construct($stream);

        $this->delimiter = $delimiter;
        $this->enclosure = $enclosure;
    }

    /**
     * {@inheritdoc}
     */
    public function writeItem(array $item)
    {
        fputcsv($this->getStream(), $item, $this->delimiter, $this->enclosure);

        return $this;
    }
}<commit_msg>Add UTF-8 encoding to CsvWriter<commit_after><?php

namespace Ddeboer\DataImport\Writer;

/**
 * Writes to a CSV file
 */
class CsvWriter extends AbstractStreamWriter
{
    private $delimiter = ';';
    private $enclosure = '"';
    private $utf8Encoding = false;

    /**
     * Constructor
     *
     * @param string   $delimiter The delimiter
     * @param string   $enclosure The enclosure
     * @param resource $stream
     * @param bool     $utf8Encoding
     */
    public function __construct($delimiter = ';', $enclosure = '"', $stream = null, $utf8Encoding = false)
    {
        parent::__construct($stream);

        $this->delimiter = $delimiter;
        $this->enclosure = $enclosure;
        $this->utf8Encoding = $utf8Encoding;
    }

    /**
     * @inheritdoc
     */
    public function prepare()
    {
        if ($this->utf8Encoding) {
            fprintf($this->getStream(), chr(0xEF) . chr(0xBB) . chr(0xBF));
        }

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function writeItem(array $item)
    {
        fputcsv($this->getStream(), $item, $this->delimiter, $this->enclosure);

        return $this;
    }
}
{'fraction_non_alphanumeric': 0.14322120285423037, 'fraction_numerical': 0.0050968399592252805, 'mean_word_length': 2.3555555555555556, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, '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': '7381167', 'n_tokens_mistral': 617, 'n_tokens_neox': 603, 'n_words': 130}