<commit_before><?php

namespace WouterJ\Fred;

/**
 * @author <NAME> <<EMAIL>>
 */
class StepStack
{
    /** @var \Traversable */
    private $files;

    public function __construct(\Traversable $files)
    {
        $this->files = $files;
    }

    public function then(Step $step)
    {
        $this->files = $step->constructIterator($this->files);

        return $this;
    }

    public function dest($glob)
    {
        var_dump('Iterator chain ended with dest to '.$glob);

        foreach ($this->files as $file) {
            echo PHP_EOL, $file->info()->getRelativePathname();
            echo ': ', $file->content();
        }
    }
}<commit_msg>First version of destination handling<commit_after><?php

namespace WouterJ\Fred;

/**
 * @author <NAME> <<EMAIL>>
 */
class StepStack
{
    /** @var \Traversable */
    private $files;

    public function __construct(\Traversable $files)
    {
        $this->files = $files;
    }

    public function then(Step $step)
    {
        $this->files = $step->constructIterator($this->files);

        return $this;
    }

    public function dest($glob)
    {
        if (STDOUT === $glob) {
            foreach ($this->files as $file) {
                fwrite(STDOUT, $file->content());
            }
        } elseif (is_dir($glob)) {
            /** @var File $file */
            foreach ($this->files as $file) {
                file_put_contents($glob.DIRECTORY_SEPARATOR.$file->info()->getFilename(), $file->content());
            }
        } elseif (1 === count($this->files)) {
            $file = current(iterator_to_array($this->files));

            file_put_contents(getcwd().DIRECTORY_SEPARATOR.$glob, $file->content());
        } else {
            throw new \InvalidArgumentException(sprintf('Unable to handle destination "%s".', $glob));
        }
    }
}
{'fraction_non_alphanumeric': 0.15938864628820962, 'fraction_numerical': 0.0005458515283842794, 'mean_word_length': 2.171280276816609, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 30, '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': '7345717', 'n_tokens_mistral': 552, 'n_tokens_neox': 537, 'n_words': 114}