<commit_before><?php namespace Mabasic\Kalista\Movies;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class OrganizeCommand extends Command {

    /**
     * @param $source
     * @return array
     */
    public function scanDirectory($source)
    {
        return array_diff(scandir($source), array('..', '.'));
    }

    /**
     * @param $item
     * @return mixed
     */
    public function getDirectoryNameFromFile($item)
    {
        // If filename is already formatted
        // return file name
        $output = explode('[', $item)[0];

        // If filename is not formatted
        if($item == $output)
        {
            // Return file name without extension
            $output = explode('.', $item)[0];
        }

        return $output;
    }

    /**
     * Configure the command options.
     *
     * @return void
     */
    protected function configure()
    {
        $this->setName('organize:movies')
            ->addArgument(
                'source',
                InputArgument::REQUIRED,
                'Source folder that needs to be organized.'
            )
            ->addArgument(
                'destination',
                InputArgument::REQUIRED,
                'Destination folder where organized files are stored.'
            )
            ->setDescription('Movies movies from one folder in another folder in separate folders.');
    }

    /**
     * Execute the command.
     *
     * @param  \Symfony\Component\Console\Input\InputInterface $input
     * @param  \Symfony\Component\Console\Output\OutputInterface $output
     * @return void
     */
    public function execute(InputInterface $input, OutputInterface $output)
    {
        $source = $input->getArgument('source');
        $destination = $input->getArgument('destination');

        $this->organizeMovies($source, $destination, $output);



    }

    private function organizeMovies($source, $destination, OutputInterface $output)
    {
        $items = $this->scanDirectory($source);

        foreach ($items as $item)
        {
            if (is_dir($source . '/' . $item))
            {
                // TODO: Do recursive

                //continue;
                $this->organizeMovies($source . '/' . $item, $destination, $output);

                continue;
            }

            $directoryName = $this->getDirectoryNameFromFile($item);

            $directoryPath = $destination . '/' . $directoryName;

            if ( ! is_dir($directoryPath))
            {
                mkdir($directoryPath);
            }

            copy($source . '/' . $item, $directoryPath . '/' . $item);

            $output->writeln($item);
        }
    }
}<commit_msg>Some refactoring. Still not satisfied.<commit_after><?php namespace Mabasic\Kalista\Movies;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class OrganizeCommand extends Command {

    /**
     * Configure the command options.
     *
     * @return void
     */
    protected function configure()
    {
        $this->setName('organize:movies')
            ->addArgument(
                'source',
                InputArgument::REQUIRED,
                'Source folder that needs to be organized.'
            )
            ->addArgument(
                'destination',
                InputArgument::REQUIRED,
                'Destination folder where organized files are stored.'
            )
            ->setDescription('Movies movies from one folder in another folder in separate folders.');
    }

    /**
     * Execute the command.
     *
     * @param  \Symfony\Component\Console\Input\InputInterface $input
     * @param  \Symfony\Component\Console\Output\OutputInterface $output
     * @return void
     */
    public function execute(InputInterface $input, OutputInterface $output)
    {
        $source = $input->getArgument('source');
        $destination = $input->getArgument('destination');

        $this->organizeMovies($source, $destination, $output);
    }

    private function organizeMovies($source, $destination, OutputInterface $output)
    {
        $items = $this->scanDirectory($source);

        foreach ($items as $item)
        {
            if (is_dir($source . '/' . $item))
            {
                $this->organizeMovies($source . '/' . $item, $destination, $output);

                continue;
            }

            $target = $this->generateDirectoryPath($destination, $item);

            $this->createDirectory($target);

            $this->copyFileToDestination($source, $item, $target);

            $output->writeln($item);
        }
    }

    /**
     * @param $destination
     * @param $item
     * @return mixed
     */
    public function generateDirectoryPath($destination, $item)
    {
        // If filename is already formatted
        // return file name
        $output = explode('[', $item)[0];

        // If filename is not formatted
        if($item == $output)
        {
            // Return file name without extension
            $output = explode('.', $item)[0];
        }

        return $destination . '/' . $output;
    }

    /**
     * @param $source
     * @return array
     */
    public function scanDirectory($source)
    {
        return array_diff(scandir($source), array('..', '.'));
    }

    /**
     * @param $source
     * @param $item
     * @param $destination
     */
    private function copyFileToDestination($source, $item, $destination)
    {
        copy($source . '/' . $item, $destination . '/' . $item);
    }

    /**
     * @param $directoryPath
     */
    private function createDirectory($directoryPath)
    {
        if ( ! is_dir($directoryPath))
        {
            mkdir($directoryPath);
        }
    }
}
{'fraction_non_alphanumeric': 0.12684463604709004, 'fraction_numerical': 0.000663239927043608, 'mean_word_length': 1.8916586768935761, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '5084605', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1561, 'n_words': 346}