<commit_before><?php

namespace JK\Sam\Filter\Copy;

use Exception;
use JK\Sam\Filter\Filter;
use SplFileInfo;
use Symfony\Component\Filesystem\Filesystem;

class CopyFilter extends Filter
{
    /**
     * @param SplFileInfo[] $sources
     * @param SplFileInfo[] $destinations
     * @return SplFileInfo[]
     * @throws Exception
     */
    public function run(array $sources, array $destinations)
    {
        $fileSystem = new Filesystem();

        // must have the same sources and destinations number
        if (count($sources) !== count($destinations) && count($destinations) !== 1) {
            throw new Exception('Sources and destinations count mismatch');
        }

        if (count($destinations) === 1 && !is_dir($destinations[0]) && count($sources) > 1) {
            throw new Exception('If only one destination is set for multiple source, it should be a directory');
        }
        $copiedFiles = [];

        // copy generated files to its destination
        foreach ($sources as $index => $source) {

            if (array_key_exists($index, $destinations)) {
                $destination = $destinations[$index];
            } else {
                $destination = $destinations[0];
            }

            if (is_dir($destination)) {
                $destination = $destination.'/'.$source->getFilename();
            }
            $this->addNotification('copying "'.$source.'" to "'.$destination.'"');

            $fileSystem->copy($source, $destination);
            $copiedFiles[] = $destination;
        }

        return $copiedFiles;
    }

    /**
     * 
     */
    public function checkRequirements()
    {
    }

    /**
     * Return the file extensions supported by this filter.
     *
     * @return string[]<commit_msg>fix potential bug in copy filter<commit_after><?php

namespace JK\Sam\Filter\Copy;

use Exception;
use JK\Sam\Filter\Filter;
use SplFileInfo;
use Symfony\Component\Filesystem\Filesystem;

class CopyFilter extends Filter
{
    /**
     * @param SplFileInfo[] $sources
     * @param SplFileInfo[] $destinations
     * @return SplFileInfo[]
     * @throws Exception
     */
    public function run(array $sources, array $destinations)
    {
        $fileSystem = new Filesystem();

        // must have the same sources and destinations number
        if (count($sources) !== count($destinations) && count($destinations) !== 1) {
            throw new Exception('Sources and destinations count mismatch');
        }

        if (count($destinations) === 1 && !is_dir($destinations[0]) && count($sources) > 1) {
            throw new Exception('If only one destination is set for multiple source, it should be a directory');
        }
        $copiedFiles = [];

        // copy generated files to its destination
        foreach ($sources as $index => $source) {

            if (array_key_exists($index, $destinations)) {
                $destination = $destinations[$index];
            } else {
                $destination = $destinations[0];
            }

            if (is_dir($destination)) {
                $destination = $destination.'/'.$source->getFilename();
            }
            $this->addNotification('copying "'.$source.'" to "'.$destination.'"');

            $fileSystem->copy($source->getPath(), $destination->getPath());
            $copiedFiles[] = $destination;
        }

        return $copiedFiles;
    }

    /**
     * 
     */
    public function checkRequirements()
    {
    }

    /**
     * Return the file extensions supported by this filter.
     *
     * @return string[]
{'fraction_non_alphanumeric': 0.131321598211791, 'fraction_numerical': 0.002794076557697681, 'mean_word_length': 2.213644524236984, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '2729122', 'n_tokens_mistral': 968, 'n_tokens_neox': 929, 'n_words': 250}